mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-02 02:11:33 +00:00
Enterprise manager can access enterprise fees for enterprises they manage - fixes fees on order cycles interface
This commit is contained in:
@@ -49,7 +49,7 @@ module Admin
|
||||
end
|
||||
|
||||
def collection
|
||||
super.order('enterprise_id', 'fee_type', 'name')
|
||||
EnterpriseFee.managed_by(spree_current_user).order('enterprise_id', 'fee_type', 'name')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,6 +13,13 @@ class EnterpriseFee < ActiveRecord::Base
|
||||
|
||||
scope :for_enterprise, lambda { |enterprise| where(enterprise_id: enterprise) }
|
||||
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
else
|
||||
where('enterprise_id IN (?)', user.enterprises)
|
||||
end
|
||||
}
|
||||
|
||||
def self.clear_all_adjustments_for(line_item)
|
||||
line_item.order.adjustments.where(originator_type: 'EnterpriseFee', source_id: line_item, source_type: 'Spree::LineItem').destroy_all
|
||||
|
||||
@@ -40,7 +40,10 @@ class AbilityDecorator
|
||||
|
||||
can [:create], OrderCycle
|
||||
|
||||
can [:index, :read], EnterpriseFee
|
||||
can [:admin, :index, :read], EnterpriseFee do |enterprise_fee|
|
||||
user.enterprises.include? enterprise_fee.enterprise
|
||||
end
|
||||
|
||||
can [:admin, :index, :read, :create, :edit, :update], ExchangeVariant
|
||||
can [:admin, :index, :read, :create, :edit, :update], Exchange
|
||||
can [:admin, :index, :read, :create, :edit, :update], ExchangeFee
|
||||
|
||||
@@ -349,7 +349,7 @@ 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!(:distributor1_fee) { create(:enterprise_fee, enterprise: distributor1, name: 'First Distributor Fee') }
|
||||
before(:each) do
|
||||
product = create(:product, supplier: supplier1)
|
||||
product.distributors << distributor1
|
||||
@@ -384,6 +384,8 @@ feature %q{
|
||||
click_button 'Add supplier'
|
||||
|
||||
select 'First Distributor', from: 'order_cycle_coordinator_id'
|
||||
click_button 'Add coordinator fee'
|
||||
select 'First Distributor Fee', from: 'order_cycle_coordinator_fee_0_id'
|
||||
|
||||
select 'First Distributor', from: 'new_distributor_id'
|
||||
click_button 'Add distributor'
|
||||
|
||||
@@ -136,6 +136,10 @@ module Spree
|
||||
it "should be able to create OrderCycles" do
|
||||
should have_ability([:create], for: OrderCycle)
|
||||
end
|
||||
|
||||
it "should be able to read EnterpriseFees" do
|
||||
should have_ability([:admin, :index, :read], for: EnterpriseFee)
|
||||
end
|
||||
end
|
||||
|
||||
context 'Enterprise manager' do
|
||||
@@ -160,4 +164,4 @@ module Spree
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user