diff --git a/lib/open_food_network/permissions.rb b/lib/open_food_network/permissions.rb index ca87f92b4e..f6d6757d67 100644 --- a/lib/open_food_network/permissions.rb +++ b/lib/open_food_network/permissions.rb @@ -15,6 +15,11 @@ module OpenFoodNetwork managed_and_related_enterprises_with :add_to_order_cycle end + # Find enterprises for which an admin is allowed to edit their profile + def editable_enterprises + managed_and_related_enterprises_with :edit_profile + end + # For every hub that an admin manages, show all the producers that that hub may add # to the order cycle # {hub1_id => [producer1_id, producer2_id, ...], ...} diff --git a/spec/lib/open_food_network/permissions_spec.rb b/spec/lib/open_food_network/permissions_spec.rb index 6ce369fbb5..184494153b 100644 --- a/spec/lib/open_food_network/permissions_spec.rb +++ b/spec/lib/open_food_network/permissions_spec.rb @@ -21,6 +21,19 @@ module OpenFoodNetwork end end + describe "finding enterprises whose profiles can be edited" do + let(:e) { double(:enterprise) } + + it "returns managed and related enterprises with edit_profile permission" do + permissions. + should_receive(:managed_and_related_enterprises_with). + with(:edit_profile). + and_return([e]) + + permissions.editable_enterprises.should == [e] + end + end + describe "finding enterprises that can be added to an order cycle, for each hub" do let!(:hub) { create(:distributor_enterprise) } let!(:producer) { create(:supplier_enterprise) }