mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge navigator_helper with decorator
This commit is contained in:
@@ -42,6 +42,17 @@ module Spree
|
||||
content_tag('li', link, :class => css_classes.join(' '))
|
||||
end
|
||||
|
||||
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])) && cannot?(:admin, klass)
|
||||
|
||||
tab_without_cancan_check(*args)
|
||||
end
|
||||
alias_method_chain :tab, :cancan_check
|
||||
|
||||
# finds class for a given symbol / string
|
||||
#
|
||||
# Example :
|
||||
@@ -53,11 +64,25 @@ module 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)
|
||||
["Spree::#{model_name.classify}", model_name.classify, model_name.tr('_', '/').classify].find(&:safe_constantize).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).
|
||||
def klass_for_with_sym_fallback(name)
|
||||
klass = klass_for_without_sym_fallback(name)
|
||||
klass ||= name.singularize.to_sym
|
||||
klass = :overview if klass == :dashboard
|
||||
klass = Spree::Order if klass == :bulk_order_management
|
||||
klass = EnterpriseGroup if klass == :group
|
||||
klass = VariantOverride if klass == :Inventory
|
||||
klass = ProductImport::ProductImporter if klass == :import
|
||||
klass = Spree::Admin::ReportsController if klass == :report
|
||||
klass
|
||||
end
|
||||
alias_method_chain :klass_for, :sym_fallback
|
||||
|
||||
def link_to_clone(resource, options={})
|
||||
options[:data] = {:action => 'clone'}
|
||||
link_to_with_icon('icon-copy', Spree.t(:clone), clone_admin_product_url(resource), options)
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
require 'spree/admin/navigation_helper'
|
||||
|
||||
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.tr('_', '/').classify].find(&:safe_constantize).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).
|
||||
def klass_for_with_sym_fallback(name)
|
||||
klass = klass_for_without_sym_fallback(name)
|
||||
klass ||= name.singularize.to_sym
|
||||
klass = :overview if klass == :dashboard
|
||||
klass = Spree::Order if klass == :bulk_order_management
|
||||
klass = EnterpriseGroup if klass == :group
|
||||
klass = VariantOverride if klass == :Inventory
|
||||
klass = ProductImport::ProductImporter if klass == :import
|
||||
klass = Spree::Admin::ReportsController if klass == :report
|
||||
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])) && cannot?(:admin, klass)
|
||||
|
||||
tab_without_cancan_check(*args)
|
||||
end
|
||||
alias_method_chain :tab, :cancan_check
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user