Skip to content

Commit

Permalink
Show the admin/settings menu for any of its elements
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
elia committed Oct 1, 2020
1 parent be7c78e commit e7bc874
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
15 changes: 14 additions & 1 deletion backend/lib/spree/backend_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions backend/spec/lib/spree/backend_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,17 @@
expect(stock_menu_item.match_path).to eq('/stock_items')
end
end

describe 'menu tab for settings' do
let(:menu_item) do
subject.find { |item| item.label == :settings }
end

it 'is shown if any of its submenus are present' do
view = double("view", can?: false)
expect(view).to receive(:can?).at_least(12).times
view.instance_exec(&menu_item.condition)
end
end
end
end

0 comments on commit e7bc874

Please sign in to comment.