Spliting order management abilities out of product management abilities

This commit is contained in:
Rob Harrington
2014-09-26 17:11:11 +10:00
parent 299b0fe5be
commit 4b2f1cefa0
3 changed files with 47 additions and 42 deletions

View File

@@ -5,6 +5,7 @@ class AbilityDecorator
add_base_abilities user if is_new_user? user
add_enterprise_management_abilities user if can_manage_enterprises? user
add_product_management_abilities user if can_manage_products? user
add_order_management_abilities user if can_manage_orders? user
add_relationship_management_abilities user if can_manage_relationships? user
end
@@ -17,12 +18,13 @@ class AbilityDecorator
user.enterprises.present?
end
def can_manage_products?(user)
# ( user.enterprises.map(&:type) & %w(single full) ).any?
can_manage_enterprises? user
end
def can_manage_orders?(user)
( user.enterprises.map(&:type) & %w(single full) ).any?
end
def can_manage_relationships?(user)
can_manage_enterprises? user
@@ -47,7 +49,6 @@ class AbilityDecorator
end
end
def add_product_management_abilities(user)
# Enterprise User can only access products that they are a supplier for
can [:create], Spree::Product
@@ -65,7 +66,9 @@ class AbilityDecorator
can [:admin, :index, :read, :search], Spree::Taxon
can [:admin, :index, :read, :create, :edit], Spree::Classification
end
def add_order_management_abilities(user)
# Enterprise User can only access orders that they are a distributor for
can [:index, :create], Spree::Order
can [:read, :update, :fire, :resend], Spree::Order do |order|

View File

@@ -64,7 +64,7 @@ feature %q{
page.should have_admin_menu_item 'Dashboard'
page.should have_admin_menu_item 'Enterprises'
['Orders', 'Products', 'Reports', 'Configuration', 'Promotions', 'Users', 'Order Cycles'].each do |menu_item_name|
['Orders', 'Reports', 'Configuration', 'Promotions', 'Users', 'Order Cycles'].each do |menu_item_name|
page.should_not have_admin_menu_item menu_item_name
end
end
@@ -79,15 +79,15 @@ feature %q{
end
end
it "does not show me product management controls" do
page.should_not have_selector '#products'
it "shows me product management controls, but not order_cycle controls" do
page.should have_selector '#products'
page.should_not have_selector '#order_cycles'
end
it "does not show me enterprise product info, payment methods, shipping methods or enterprise fees" do
it "shows me enterprise product info but not payment methods, shipping methods or enterprise fees" do
# Producer product info
page.should_not have_selector '.producers_tab span', text: 'Total Products'
page.should_not have_selector '.producers_tab span', text: 'Active Products'
page.should have_selector '.producers_tab span', text: 'Total Products'
page.should have_selector '.producers_tab span', text: 'Active Products'
page.should_not have_selector '.producers_tab span', text: 'Products in OCs'
# Payment methods, shipping methods, enterprise fees

View File

@@ -13,44 +13,46 @@ module Spree
let(:enterprise_single) { create(:enterprise, type: 'single') }
let(:enterprise_profile) { create(:enterprise, type: 'profile') }
describe "creating enterprises" do
context "as manager of a 'full' type enterprise" do
before do
user.enterprise_roles.create! enterprise: enterprise_full
end
it { subject.can_manage_products?(user).should be_true }
it { subject.can_manage_enterprises?(user).should be_true }
it { subject.can_manage_orders?(user).should be_true }
end
context "as manager of a 'single' type enterprise" do
before do
user.enterprise_roles.create! enterprise: enterprise_single
end
it { subject.can_manage_products?(user).should be_true }
it { subject.can_manage_enterprises?(user).should be_true }
it { subject.can_manage_orders?(user).should be_true }
end
context "as manager of a 'profile' type enterprise" do
before do
user.enterprise_roles.create! enterprise: enterprise_profile
end
it { subject.can_manage_products?(user).should be_true }
it { subject.can_manage_enterprises?(user).should be_true }
it { subject.can_manage_orders?(user).should be_false }
end
context "as a new user with no enterprises" do
it { subject.can_manage_products?(user).should be_false }
it { subject.can_manage_enterprises?(user).should be_false }
it { subject.can_manage_orders?(user).should be_false }
it "can create enterprises straight off the bat" do
subject.is_new_user?(user).should be_true
expect(user).to have_ability :create, for: Enterprise
end
end
describe "managing enterprises" do
it "can manage enterprises when the user has at least one enterprise assigned" do
user.enterprise_roles.create! enterprise: enterprise_full
subject.can_manage_enterprises?(user).should be_true
end
it "can't otherwise" do
subject.can_manage_enterprises?(user).should be_false
end
end
describe "managing products" do
it "can when a user manages a 'full' type enterprise" do
user.enterprise_roles.create! enterprise: enterprise_full
subject.can_manage_products?(user).should be_true
end
it "can when a user manages a 'single' type enterprise" do
user.enterprise_roles.create! enterprise: enterprise_single
subject.can_manage_products?(user).should be_true
end
it "can't when a user manages a 'profile' type enterprise" do
user.enterprise_roles.create! enterprise: enterprise_profile
subject.can_manage_products?(user).should be_true
end
it "can't when the user manages no enterprises" do
subject.can_manage_products?(user).should be_false
end
end
end
describe 'Roles' do