summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-06-11 06:21:52 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-06-11 06:21:52 +0000
commit53710d80fc886297d901ac913b4b7570ff5acdb4 (patch)
tree9d090578ecb7bc8b5d32780a432006784550ead7 /lib
parent431a73c968e1222a60983039f695b2da7904ddc9 (diff)
downloadredmine-53710d80fc886297d901ac913b4b7570ff5acdb4.tar.gz
redmine-53710d80fc886297d901ac913b4b7570ff5acdb4.zip
Introduce virtual MenuNodes (#15880).
They are characterized by having a blank url. they will only be rendered if the user is authorized to see at least one of its children. they render as links which do nothing when clicked. Patch by Jan Schulz-Hofen. git-svn-id: http://svn.redmine.org/redmine/trunk@15501 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r--lib/redmine/menu_manager.rb19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb
index fa7777065..0d2d19a43 100644
--- a/lib/redmine/menu_manager.rb
+++ b/lib/redmine/menu_manager.rb
@@ -147,7 +147,15 @@ module Redmine
end
def render_single_menu_node(item, caption, url, selected)
- link_to(h(caption), url, item.html_options(:selected => selected))
+ options = item.html_options(:selected => selected)
+
+ # virtual nodes are only there for their children to be displayed in the menu
+ # and should not do anything on click, except if otherwise defined elsewhere
+ if url.blank?
+ url = '#'
+ options.reverse_merge!(:onclick => 'return false;')
+ end
+ link_to(h(caption), url, options)
end
def render_unattached_menu_item(menu_item, project)
@@ -433,7 +441,14 @@ module Redmine
# * Checking the permission or the url target (project only)
# * Checking the conditions of the item
def allowed?(user, project)
- if user && project
+ if url.blank?
+ # this is a virtual node that is only there for its children to be diplayed in the menu
+ # it is considered an allowed node if at least one of the children is allowed
+ all_children = children
+ all_children += child_menus.call(project) if child_menus
+ return true if all_children.detect{|child| child.allowed?(user, project) }
+ return false
+ elsif user && project
if permission
unless user.allowed_to?(permission, project)
return false