From f6e9c9494c0213bb627f84718ab2ed06306b7da5 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 14 Jan 2015 11:03:32 +1100 Subject: [PATCH] Enterprise user can edit profiles it has permission to --- .../admin/enterprises_controller.rb | 6 ++++-- spec/features/admin/enterprises_spec.rb | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 0ee0541145..cf97b5a283 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -76,8 +76,10 @@ module Admin end def collection - # TODO was ordered with is_distributor DESC as well, not sure why or how we want ot sort this now - Enterprise.managed_by(spree_current_user).order('is_primary_producer ASC, name') + # TODO was ordered with is_distributor DESC as well, not sure why or how we want to sort this now + OpenFoodNetwork::Permissions.new(spree_current_user). + editable_enterprises. + order('is_primary_producer ASC, name') end def collection_actions diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index e7f7ea14cf..e19249fef1 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -324,7 +324,9 @@ feature %q{ let(:supplier2) { create(:supplier_enterprise, name: 'Another Supplier') } let(:distributor1) { create(:distributor_enterprise, name: 'First Distributor') } let(:distributor2) { create(:distributor_enterprise, name: 'Another Distributor') } + let(:distributor3) { create(:distributor_enterprise, name: 'Yet Another Distributor') } let(:enterprise_user) { create_enterprise_user } + let!(:er) { create(:enterprise_relationship, parent: distributor3, child: distributor1, permissions_list: [:edit_profile]) } before(:each) do enterprise_user.enterprise_roles.build(enterprise: supplier1).save @@ -410,15 +412,26 @@ feature %q{ end end - scenario "editing enterprises I have permission to" do + scenario "editing enterprises I manage" do click_link 'Enterprises' - within('#listing_enterprises tbody tr:first') { click_link 'Edit Profile' } + within("#listing_enterprises tr.enterprise-#{distributor1.id}") { click_link 'Edit Profile' } fill_in 'enterprise_name', :with => 'Eaterprises' click_button 'Update' flash_message.should == 'Enterprise "Eaterprises" has been successfully updated!' - page.should have_field 'enterprise_name', :with => 'Eaterprises' + distributor1.reload.name.should == 'Eaterprises' + end + + scenario "editing enterprises I have permission to" do + click_link 'Enterprises' + within("#listing_enterprises tr.enterprise-#{distributor3.id}") { click_link 'Edit Profile' } + + fill_in 'enterprise_name', :with => 'Eaterprises' + click_button 'Update' + + flash_message.should == 'Enterprise "Eaterprises" has been successfully updated!' + distributor3.reload.name.should == 'Eaterprises' end scenario "editing images for an enterprise" do