From 11acb3ba59e647cd0457564af0bd701a787db582 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 1 May 2015 15:59:46 +1000 Subject: [PATCH] Allow to remove adjustments Managers of an order cycle and the distributor of an order are allowed to remove an adjustment from the order. --- app/models/spree/ability_decorator.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index c6126d7171..b8539979c2 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -152,6 +152,19 @@ class AbilityDecorator can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Shipment can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Adjustment can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::ReturnAuthorization + can [:destroy], Spree::Adjustment do |adjustment| + # Sharing code with destroying a line item. This should be unified and probably applied for other actions as well. + binding.pry + if user.admin? + true + elsif adjustment.adjustable.instance_of? Spree::Order + order = adjustment.adjustable + user.enterprises.include?(order.distributor) || user == order.order_cycle.manager + elsif adjustment.adjustable.instance_of? Spree::LineItem + order = adjustment.adjustable.order + user.enterprises.include?(order.distributor) || user == order.order_cycle.manager + end + end can [:create], OrderCycle