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:
Maikel Linke
2016-11-30 16:49:06 +11:00
committed by Rohan Mitchell
parent 14ee7a06ae
commit 3a69c958ef
2 changed files with 21 additions and 0 deletions

View File

@@ -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

View File

@@ -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