mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Adding permissions for outgoing hubs to see producers whose variants they are distributing, despite P-OC not existing
This commit is contained in:
@@ -62,6 +62,7 @@ module OpenFoodNetwork
|
||||
|
||||
managed_active = []
|
||||
hubs_active = []
|
||||
producers_active = []
|
||||
if order_cycle
|
||||
# TODO: remove this when permissions are all sorted out
|
||||
# Any enterprises that I manage that are already in the order_cycle
|
||||
@@ -72,9 +73,15 @@ module OpenFoodNetwork
|
||||
variants = Spree::Variant.joins(:product).where('spree_products.supplier_id IN (?)', managed_enterprises.is_primary_producer)
|
||||
active_exchanges = order_cycle.exchanges.outgoing.with_any_variant(variants)
|
||||
hubs_active = active_exchanges.map(&:receiver_id)
|
||||
|
||||
# TODO: Remove this when all P-OC are sorted out
|
||||
# Any producers of variants that hubs I manage are currently distributing in this OC
|
||||
variants = Spree::Variant.joins(:exchanges).where("exchanges.receiver_id IN (?) AND exchanges.order_cycle_id = (?) AND exchanges.incoming = 'f'", managed_hubs_in(order_cycle), order_cycle).pluck(:id).uniq
|
||||
products = Spree::Product.joins(:variants_including_master).where("spree_variants.id IN (?)", variants).pluck(:id).uniq
|
||||
producers_active = Enterprise.joins(:supplied_products).where("spree_products.id IN (?)", products).pluck(:id).uniq
|
||||
end
|
||||
|
||||
Enterprise.where(id: coordinator_permitted | managed_permitted | managed_active | hubs_permitted | producers_permitted | hubs_active)
|
||||
Enterprise.where(id: coordinator_permitted | managed_permitted | hubs_permitted | producers_permitted | managed_active | hubs_active | producers_active )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -105,6 +105,18 @@ module OpenFoodNetwork
|
||||
expect(enterprises).to_not include producer, coordinator
|
||||
end
|
||||
end
|
||||
|
||||
context "and distributes variants distributed by an unmanaged and unpermitted producer" do
|
||||
let!(:ex_outgoing) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
|
||||
before { ex_outgoing.variants << create(:variant, product: create(:product, supplier: producer)) }
|
||||
|
||||
# TODO: update this when we are confident about P-OCs
|
||||
it "returns that producer as well" do
|
||||
enterprises = permissions.order_cycle_enterprises_for(order_cycle: oc)
|
||||
expect(enterprises).to include producer, hub
|
||||
expect(enterprises).to_not include coordinator
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user