From 295df5e8d92e85b3c5a7fc6c761c32b691b81b75 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 30 Sep 2020 19:13:58 +0200 Subject: [PATCH] Show the admin/settings menu for any of its elements It's possible to create permission sets the only give access to a subset of the settings menu items, without this the settings menu was kept hidden. --- backend/lib/spree/backend_configuration.rb | 15 ++++++++++++- backend/spec/features/admin/homepage_spec.rb | 2 ++ .../lib/spree/backend_configuration_spec.rb | 21 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/backend/lib/spree/backend_configuration.rb b/backend/lib/spree/backend_configuration.rb index d1a10c9980b..ef57d259c3d 100644 --- a/backend/lib/spree/backend_configuration.rb +++ b/backend/lib/spree/backend_configuration.rb @@ -131,7 +131,20 @@ def menu_items MenuItem.new( CONFIGURATION_TABS, 'wrench', - condition: -> { can?(:admin, Spree::Store) }, + condition: -> { + can?(:admin, Spree::Store) || + can?(:show, Spree::AdjustmentReason) || + can?(:show, Spree::PaymentMethod) || + can?(:show, Spree::RefundReason) || + can?(:show, Spree::ReimbursementType) || + can?(:show, Spree::ShippingCategory) || + can?(:show, Spree::ShippingMethod) || + can?(:show, Spree::StockLocation) || + can?(:show, Spree::TaxCategory) || + can?(:show, Spree::TaxRate) || + can?(:show, Spree::ReturnReason) || + can?(:show, Spree::Zone) + }, label: :settings, partial: 'spree/admin/shared/settings_sub_menu', url: :admin_stores_path, diff --git a/backend/spec/features/admin/homepage_spec.rb b/backend/spec/features/admin/homepage_spec.rb index d69f8325102..372390aa6dc 100644 --- a/backend/spec/features/admin/homepage_spec.rb +++ b/backend/spec/features/admin/homepage_spec.rb @@ -73,6 +73,8 @@ custom_authorization! do |_user| can [:admin, :home], :dashboards can [:admin, :edit, :index, :show], Spree::Order + cannot [:show], Spree::StockLocation + cannot [:show], Spree::Zone end it 'should only display tabs fakedispatch has access to' do diff --git a/backend/spec/lib/spree/backend_configuration_spec.rb b/backend/spec/lib/spree/backend_configuration_spec.rb index 1e9ea5d5d7d..a745843ff8d 100644 --- a/backend/spec/lib/spree/backend_configuration_spec.rb +++ b/backend/spec/lib/spree/backend_configuration_spec.rb @@ -18,5 +18,26 @@ expect(stock_menu_item.match_path).to eq('/stock_items') end end + + describe 'menu tab for settings' do + let(:menu_item) { subject.find { |item| item.label == :settings } } + let(:view) { double("view") } + + it 'is shown if any of its submenus are present' do + allow(view).to receive(:can?).and_return(true, false) + + result = view.instance_exec(&menu_item.condition) + + expect(result).to eq(true) + end + + it 'is not shown if none of its submenus are present' do + expect(view).to receive(:can?).exactly(12).times.and_return(false) + + result = view.instance_exec(&menu_item.condition) + + expect(result).to eq(false) + end + end end end