mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-03 22:06:07 +00:00
Hide super admin menu items for enterprise users
Imported temporarily missing Spree functionality. This patch becomes obsolete with another Spree upgrade.
This commit is contained in:
committed by
Rohan Mitchell
parent
14ee7a06ae
commit
3a69c958ef
@@ -1,6 +1,15 @@
|
||||
module Spree
|
||||
module Admin
|
||||
module NavigationHelper
|
||||
# TEMP: import method until it is re-introduced into Spree.
|
||||
def klass_for(name)
|
||||
model_name = name.to_s
|
||||
|
||||
["Spree::#{model_name.classify}", model_name.classify, model_name.gsub('_', '/').classify].find do |t|
|
||||
t.safe_constantize
|
||||
end.try(:safe_constantize)
|
||||
end
|
||||
|
||||
# Make it so that the Reports admin tab can be enabled/disabled through the cancan
|
||||
# :report resource, since it does not have a corresponding resource class (unlike
|
||||
# eg. Spree::Product).
|
||||
@@ -12,6 +21,17 @@ module Spree
|
||||
# klass
|
||||
# end
|
||||
# alias_method_chain :klass_for, :sym_fallback
|
||||
|
||||
# TEMP: override method until it is fixed in Spree.
|
||||
def tab_with_cancan_check(*args)
|
||||
options = {:label => args.first.to_s}
|
||||
if args.last.is_a?(Hash)
|
||||
options = options.merge(args.last)
|
||||
end
|
||||
return '' if klass = klass_for(options[:label]) and cannot?(:admin, klass)
|
||||
tab_without_cancan_check(*args)
|
||||
end
|
||||
alias_method_chain :tab, :cancan_check
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,6 +18,7 @@ feature "Authentication", js: true do
|
||||
click_login_button
|
||||
expect(page).to have_content "DASHBOARD"
|
||||
expect(page).to have_current_path spree.admin_path
|
||||
expect(page).to have_no_content "CONFIGURATION"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user