From 208e05bee7a83f05f5d397b76bb1c9c7fe1f9b64 Mon Sep 17 00:00:00 2001 From: Jan Schulz-Hofen Date: Sun, 8 Jan 2017 11:42:48 +0100 Subject: [PATCH 2/6] Prevent hash type URLs from being namespaced in MenuManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is necessary for Doorkeeper and possibly other plugins/engines which would like to use Redmine’s base layout (and therefore menus) in a namespaced controller. --- lib/redmine/menu_manager.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb index f1a9b1b..24cba7e 100644 --- a/lib/redmine/menu_manager.rb +++ b/lib/redmine/menu_manager.rb @@ -177,14 +177,14 @@ module Redmine url = '#' options.reverse_merge!(:onclick => 'return false;') end - link_to(h(caption), url, options) + link_to(h(caption), use_absolute_controller(url), options) end def render_unattached_menu_item(menu_item, project) raise MenuError, ":child_menus must be an array of MenuItems" unless menu_item.is_a? MenuItem if menu_item.allowed?(User.current, project) - link_to(menu_item.caption, menu_item.url, menu_item.html_options) + link_to(menu_item.caption, use_absolute_controller(menu_item.url), menu_item.html_options) end end @@ -225,6 +225,15 @@ module Redmine raise MenuError, ":child_menus must be an array of MenuItems" unless node.is_a? MenuItem node.allowed?(user, project) end + + # Prevent hash type URLs (e.g. {controller: 'foo', action: 'bar}) from being namespaced + # when menus are rendered from views in namespaced controllers in plugins or engines + def use_absolute_controller(url) + if url.is_a?(Hash) && url[:controller].present? && !url[:controller].start_with?('/') + url[:controller] = "/#{url[:controller]}" + end + url + end end class << self -- 2.7.2