Enterprise manager can edit and bulk edit enterprises they have access to

This commit is contained in:
Rohan Mitchell
2013-08-22 11:40:33 +10:00
parent aab7176f2c
commit f870e70560
4 changed files with 36 additions and 5 deletions

View File

@@ -24,7 +24,11 @@ module Admin
end
def collection
super.managed_by(spree_current_user).order('is_primary_producer DESC, is_distributor ASC, name')
Enterprise.managed_by(spree_current_user).order('is_primary_producer DESC, is_distributor ASC, name')
end
def collection_actions
[:index, :bulk_update]
end
end
end

View File

@@ -47,8 +47,9 @@ class AbilityDecorator
can [:admin, :index, :read, :create, :edit, :update], ExchangeVariant
can [:admin, :index, :read, :create, :edit, :update], Exchange
can [:admin, :index, :read, :create, :edit, :update], ExchangeFee
can [:admin, :index], Enterprise
can [:read, :edit, :update], Enterprise do |enterprise|
can [:read, :edit, :update, :bulk_update], Enterprise do |enterprise|
user.enterprises.include? enterprise
end

View File

@@ -105,6 +105,7 @@ feature %q{
click_button 'Update'
flash_message.should == 'Enterprise "Eaterprises" has been successfully updated!'
page.should have_selector '#listing_enterprises a', text: 'Eaterprises'
end
@@ -128,7 +129,6 @@ feature %q{
end
context 'as an Enterprise user' do
let(:supplier1) { create(:supplier_enterprise, name: 'First Supplier') }
let(:supplier2) { create(:supplier_enterprise, name: 'Another Supplier') }
let(:distributor1) { create(:distributor_enterprise, name: 'First Distributor') }
@@ -153,5 +153,31 @@ feature %q{
page.should_not have_content supplier2.name
page.should_not have_content distributor2.name
end
scenario "can edit enterprises I have permission to" do
click_link 'Enterprises'
within('#listing_enterprises tbody tr:first') { click_link 'Edit' }
fill_in 'enterprise_name', :with => 'Eaterprises'
click_button 'Update'
flash_message.should == 'Enterprise "Eaterprises" has been successfully updated!'
page.should have_selector '#listing_enterprises a', text: 'Eaterprises'
end
scenario "can bulk edit enterprise collection dates/times for enterprises I have permission to" do
click_link 'Enterprises'
fill_in 'enterprise_set_collection_attributes_0_next_collection_at', :with => 'One'
fill_in 'enterprise_set_collection_attributes_1_next_collection_at', :with => 'Two'
click_button 'Update'
flash_message.should == 'Distributor collection times updated.'
supplier1.reload.next_collection_at.should == 'One'
distributor1.reload.next_collection_at.should == 'Two'
supplier2.reload.next_collection_at.should be_nil
distributor2.reload.next_collection_at.should be_nil
end
end
end

View File

@@ -151,11 +151,11 @@ module Spree
end
it 'should have the ability to read and edit enterprises that I manage' do
should have_ability([:read, :edit, :update], for: s1)
should have_ability([:read, :edit, :update, :bulk_update], for: s1)
end
it 'should not have the ability to read and edit enterprises that I do not manage' do
should_not have_ability([:read, :edit, :update], for: s2)
should_not have_ability([:read, :edit, :update, :bulk_update], for: s2)
end
it 'should have the ability administrate enterpises' do