Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the admin/settings menu for any of its elements #3783

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions backend/spec/features/admin/homepage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 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,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