app/helpers/admin/adminsite_menu_helper.rb in adminsite-3.2.1 vs app/helpers/admin/adminsite_menu_helper.rb in adminsite-3.2.2
- old
+ new
@@ -29,33 +29,52 @@
end
end
child_menus = child_menus.compact
if child_controller_names_authorized.count > 0
+ begin
+ url_controller_class = "#{recognize_path(url)[:controller]}_controller".classify.constantize
+ if !can?(:read, url_controller_class.new.authorize_resource_class)
+ url = content_index_path(child_controller_names_authorized.first)
+ end
+ rescue
+ end
+
html_options = {method: method}
html_options[:title] = current_adminsite_admin_user.email if klasses == 'log_out'
link = link_to(label, "#{url}?admin_menu=#{admin_menu}", html_options)
result = raw "<li class='#{html_classes(url, nil, klasses, admin_menu, label )}'>#{link}</li>"
content_for(:content_menu, child_menus.join("\n").html_safe )
end
result
end
+ def content_index_path(controller_name)
+ begin
+ if controller_name != controller_name.pluralize
+ eval("admin_#{controller_name}_index_path")
+ else
+ eval("admin_#{controller_name}_path")
+ end
+ rescue
+ end
+ end
+
+ def content_index_link(controller_name, admin_menu, method = nil)
+ path = content_index_path(controller_name)
+ link_to(content_menu_label(path, controller_name), "#{path}?admin_menu=#{admin_menu}", method: method, )
+ end
+
def content_menu_label(url, controller_name)
menu_controller = recognize_path(url)[:controller]
return controller_name.titlecase if menu_controller.blank?
eval("#{menu_controller}_controller".classify).content_menu_label
end
def content_menu_item(controller_name, admin_menu, klasses, method )
- if controller_name != controller_name.pluralize
- url = eval("admin_#{controller_name}_index_path")
- else
- url = eval("admin_#{controller_name}_path")
- end
- link = link_to(content_menu_label(url, controller_name), "#{url}?admin_menu=#{admin_menu}", method: method, )
- raw "<li class='#{html_classes(url, controller_name, klasses, admin_menu )}'>#{link}</li>"
+ link = content_index_link(controller_name, admin_menu, method )
+ raw "<li class='#{html_classes(content_index_path(controller_name), controller_name, klasses, admin_menu )}'>#{link}</li>"
end
def current_url?(url, label = '')
if label.present?
return request.fullpath == "#{url}?admin_menu=#{label}"
\ No newline at end of file