From b7bac326bd792932349042398c817f6defccfb1b Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 1 May 2015 12:05:43 +1000 Subject: [PATCH 1/4] admin order edit: re-label update button to "update and recalculate fees" --- .../admin/orders/_form/relabel_update_button.html.haml.deface | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/overrides/spree/admin/orders/_form/relabel_update_button.html.haml.deface diff --git a/app/overrides/spree/admin/orders/_form/relabel_update_button.html.haml.deface b/app/overrides/spree/admin/orders/_form/relabel_update_button.html.haml.deface new file mode 100644 index 0000000000..d4d3aefc8d --- /dev/null +++ b/app/overrides/spree/admin/orders/_form/relabel_update_button.html.haml.deface @@ -0,0 +1,3 @@ +/ replace "code[erb-loud]:contains('button t(:update)')" + += button t(:update_and_recalculate_fees), 'icon-refresh' From e6e063670cd90522a0bd57bb3af2167e1007c06a Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 1 May 2015 14:49:34 +1000 Subject: [PATCH 2/4] Allow managers to remove line items from order Managers of an order cycle and the distributor of an order are allowed to remove a line item from the order. --- .../spree/admin/line_items_controller_decorator.rb | 8 ++++++++ app/models/spree/ability_decorator.rb | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 app/controllers/spree/admin/line_items_controller_decorator.rb diff --git a/app/controllers/spree/admin/line_items_controller_decorator.rb b/app/controllers/spree/admin/line_items_controller_decorator.rb new file mode 100644 index 0000000000..ca83baa00b --- /dev/null +++ b/app/controllers/spree/admin/line_items_controller_decorator.rb @@ -0,0 +1,8 @@ +Spree::Admin::LineItemsController.class_eval do + private + + def load_order + @order = Spree::Order.find_by_number!(params[:order_id]) + authorize! :update, @order + end +end diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index e66c03aa72..c6126d7171 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -144,6 +144,9 @@ class AbilityDecorator end can [:admin, :bulk_management], Spree::Order if user.admin? || user.enterprises.any?(&:is_distributor) can [:admin, :create], Spree::LineItem + can [:destroy], Spree::LineItem do |item| + user.admin? || user.enterprises.include?(order.distributor) || user == order.order_cycle.manager + end can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Payment can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Shipment From 11acb3ba59e647cd0457564af0bd701a787db582 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 1 May 2015 15:59:46 +1000 Subject: [PATCH 3/4] 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 From 7b4130972b576890e845bfd4e4246c7f09632264 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 6 May 2015 18:12:17 +1000 Subject: [PATCH 4/4] Fix first feature spec sometimes timing out --- spec/features/admin/authentication_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/features/admin/authentication_spec.rb b/spec/features/admin/authentication_spec.rb index 059963fd70..8473551c99 100644 --- a/spec/features/admin/authentication_spec.rb +++ b/spec/features/admin/authentication_spec.rb @@ -10,15 +10,15 @@ feature "Authentication", js: true do scenario "logging into admin redirects home, then back to admin" do # This is the first admin spec, so give a little extra load time for slow systems - Capybara.using_wait_time(60) do + Capybara.using_wait_time(120) do visit spree.admin_path - end - fill_in "Email", with: user.email - fill_in "Password", with: user.password - click_login_button - page.should have_content "DASHBOARD" - current_path.should == spree.admin_path + fill_in "Email", with: user.email + fill_in "Password", with: user.password + click_login_button + page.should have_content "DASHBOARD" + current_path.should == spree.admin_path + end end scenario "viewing my account" do