mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Coordinator can see any enterprises that are already in the order cycle
This commit is contained in:
@@ -24,20 +24,21 @@ module OpenFoodNetwork
|
||||
coordinator = order_cycle.coordinator
|
||||
|
||||
if managed_enterprises.include? coordinator
|
||||
coordinator_permitted = []
|
||||
coordinator_permitted = [coordinator]
|
||||
all_active = []
|
||||
|
||||
if coordinator.sells == "own"
|
||||
# Coordinators that sell own can only see themselves in the OC interface
|
||||
coordinator_permitted = [coordinator]
|
||||
elsif coordinator.sells == "any"
|
||||
if coordinator.sells == "any"
|
||||
# If I manage the coordinator (or possibly in the future, if coordinator has made order cycle a friends of friend OC)
|
||||
# Any hubs that have granted the coordinator P-OC (or any enterprises that have granted mine P-OC if we do friends of friends)
|
||||
# If the coordinator sells any, relationships come into play
|
||||
coordinator_permitted = granting(:add_to_order_cycle, to: [coordinator]).pluck(:id)
|
||||
coordinator_permitted = coordinator_permitted | [coordinator]
|
||||
granting(:add_to_order_cycle, to: [coordinator]).pluck(:id).each do |enterprise_id|
|
||||
coordinator_permitted << enterprise_id
|
||||
end
|
||||
|
||||
all_active = order_cycle.suppliers.pluck(:id) | order_cycle.distributors.pluck(:id)
|
||||
end
|
||||
|
||||
Enterprise.where(id: coordinator_permitted)
|
||||
Enterprise.where(id: coordinator_permitted | all_active)
|
||||
else
|
||||
# Any enterprises that I manage directly, which have granted P-OC to the coordinator
|
||||
managed_permitted = granting(:add_to_order_cycle, to: [coordinator], scope: managed_enterprises_in(order_cycle) ).pluck(:id)
|
||||
|
||||
@@ -38,15 +38,17 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
context "as a manager of the coordinator" do
|
||||
it "returns the coordinator itself" do
|
||||
before do
|
||||
permissions.stub(:managed_enterprises) { Enterprise.where(id: [coordinator]) }
|
||||
end
|
||||
|
||||
it "returns the coordinator itself" do
|
||||
expect(permissions.order_cycle_enterprises_for(oc)).to include coordinator
|
||||
end
|
||||
|
||||
context "where P-OC has been granted to the coordinator by other enterprises" do
|
||||
before do
|
||||
create(:enterprise_relationship, parent: hub, child: coordinator, permissions_list: [:add_to_order_cycle])
|
||||
permissions.stub(:managed_enterprises) { Enterprise.where(id: [coordinator]) }
|
||||
end
|
||||
|
||||
context "where the coordinator sells any" do
|
||||
@@ -65,6 +67,35 @@ module OpenFoodNetwork
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "where P-OC has not been granted to the coordinator by other enterprises" do
|
||||
context "where the other enterprise are already in the order cycle" do
|
||||
let!(:ex_incoming) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) }
|
||||
let!(:ex_outgoing) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
|
||||
|
||||
context "where the coordinator sells any" do
|
||||
it "returns enterprises which have granted P-OC to the coordinator" do
|
||||
enterprises = permissions.order_cycle_enterprises_for(oc)
|
||||
expect(enterprises).to include hub, producer
|
||||
end
|
||||
end
|
||||
|
||||
context "where the coordinator sells 'own'" do
|
||||
before { coordinator.stub(:sells) { 'own' } }
|
||||
it "returns just the coordinator" do
|
||||
enterprises = permissions.order_cycle_enterprises_for(oc)
|
||||
expect(enterprises).to_not include hub, producer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "where the other enterprises are not in the order cycle" do
|
||||
it "returns just the coordinator" do
|
||||
enterprises = permissions.order_cycle_enterprises_for(oc)
|
||||
expect(enterprises).to_not include hub, producer
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "as a manager of a hub" do
|
||||
|
||||
Reference in New Issue
Block a user