edit_profile permission no longer shows links to manage shipping methods, payment methods and enterprise fees for an enterprise

This commit is contained in:
Rohan Mitchell
2015-01-14 14:46:59 +11:00
parent f0bd9c1065
commit d5437e1508
4 changed files with 32 additions and 10 deletions

View File

@@ -54,6 +54,9 @@ class AbilityDecorator
can [:read, :edit, :update, :bulk_update, :set_sells, :resend_confirmation], Enterprise do |enterprise|
OpenFoodNetwork::Permissions.new(user).editable_enterprises.include? enterprise
end
can [:manage_payment_methods, :manage_shipping_methods, :manage_enterprise_fees], Enterprise do |enterprise|
user.enterprises.include? enterprise
end
# All enterprises can have fees, though possibly suppliers don't need them?
can [:index, :create], EnterpriseFee

View File

@@ -11,21 +11,21 @@
%br/
- if enterprise.is_distributor
- if can? :admin, Spree::PaymentMethod
- if can?(:admin, Spree::PaymentMethod) && can?(:manage_payment_methods, enterprise)
= link_to_with_icon 'icon-chevron-right', 'Payment Methods', spree.admin_payment_methods_path(enterprise_id: enterprise.id)
(#{enterprise.payment_methods.count})
- if enterprise.payment_methods.count == 0
%span.icon-exclamation-sign.with-tip{"data-powertip" => "This enterprise has no payment methods", style: "font-size: 16px;color: #DA5354"}
%br/
- if can? :admin, Spree::ShippingMethod
- if can?(:admin, Spree::ShippingMethod) && can?(:manage_shipping_methods, enterprise)
= link_to_with_icon 'icon-plane', 'Shipping Methods', spree.admin_shipping_methods_path(enterprise_id: enterprise.id)
(#{enterprise.shipping_methods.count})
- if enterprise.shipping_methods.count == 0
%span.icon-exclamation-sign.with-tip{"data-powertip" => "This enterprise has shipping methods", style: "font-size: 16px;color: #DA5354"}
%br/
- if can? :admin, EnterpriseFee
- if can?(:admin, EnterpriseFee) && can?(:manage_enterprise_fees, enterprise)
= link_to_with_icon 'icon-money', 'Enterprise Fees', main_app.admin_enterprise_fees_path(enterprise_id: enterprise.id)
(#{enterprise.enterprise_fees.count})
- if enterprise.enterprise_fees.count == 0

View File

@@ -430,15 +430,26 @@ feature %q{
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' }
describe "enterprises I have edit permission for, but do not manage" do
it "allows me to edit them" do
click_link 'Enterprises'
within("#listing_enterprises tr.enterprise-#{distributor3.id}") { click_link 'Edit Profile' }
fill_in 'enterprise_name', :with => 'Eaterprises'
click_button 'Update'
fill_in 'enterprise_name', :with => 'Eaterprises'
click_button 'Update'
flash_message.should == 'Enterprise "Eaterprises" has been successfully updated!'
distributor3.reload.name.should == 'Eaterprises'
flash_message.should == 'Enterprise "Eaterprises" has been successfully updated!'
distributor3.reload.name.should == 'Eaterprises'
end
it "does not show links to manage payment methods, shipping methods or enterprise fees" do
click_link 'Enterprises'
within("#listing_enterprises tr.enterprise-#{distributor3.id}") do
page.should_not have_link 'Payment Methods'
page.should_not have_link 'Shipping Methods'
page.should_not have_link 'Enterprise Fees'
end
end
end
scenario "editing images for an enterprise" do

View File

@@ -253,6 +253,14 @@ module Spree
it "should be able to edit enterprises it has permission to" do
should have_ability([:read, :edit, :update, :bulk_update, :set_sells, :resend_confirmation], for: d_related)
end
it "should be able to manage shipping methods, payment methods and enterprise fees for enterprises it manages" do
should have_ability([:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d1)
end
it "should not be able to manage shipping methods, payment methods and enterprise fees for enterprises it has edit profile permission to" do
should_not have_ability([:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d_related)
end
end
describe "variant overrides" do