summaryrefslogtreecommitdiffstats
path: root/lib/redmine/menu_manager.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/redmine/menu_manager.rb')
-rw-r--r--lib/redmine/menu_manager.rb39
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb
index 8dfd95abe..7cff20e46 100644
--- a/lib/redmine/menu_manager.rb
+++ b/lib/redmine/menu_manager.rb
@@ -61,7 +61,7 @@ module Redmine
# Returns false if user is not authorized
def redirect_to_project_menu_item(project, name)
item = Redmine::MenuManager.items(:project_menu).detect {|i| i.name.to_s == name.to_s}
- if item && User.current.allowed_to?(item.url, project) && (item.condition.nil? || item.condition.call(project))
+ if item && item.allowed?(User.current, project)
redirect_to({item.param => project}.merge(item.url))
return true
end
@@ -153,17 +153,15 @@ module Redmine
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 User.current.allowed_to?(menu_item.url, project)
- link_to(h(menu_item.caption),
- menu_item.url,
- menu_item.html_options)
+ if menu_item.allowed?(User.current, project)
+ link_to(menu_item.caption, menu_item.url, menu_item.html_options)
end
end
def menu_items_for(menu, project=nil)
items = []
Redmine::MenuManager.items(menu).root.children.each do |node|
- if allowed_node?(node, User.current, project)
+ if node.allowed?(User.current, project)
if block_given?
yield node
else
@@ -188,19 +186,9 @@ module Redmine
return [caption, url, (current_menu_item == item.name)]
end
- # Checks if a user is allowed to access the menu item by:
- #
- # * Checking the url target (project only)
- # * Checking the conditions of the item
+ # See MenuItem#allowed?
def allowed_node?(node, user, project)
- if node.url.is_a?(Hash) && project && user && !user.allowed_to?(node.url, project)
- return false
- end
- if node.condition && !node.condition.call(project)
- # Condition that doesn't pass
- return false
- end
- return true
+ node.allowed?(user, project)
end
end
@@ -432,6 +420,21 @@ module Redmine
@html_options
end
end
+
+ # Checks if a user is allowed to access the menu item by:
+ #
+ # * Checking the url target (project only)
+ # * Checking the conditions of the item
+ def allowed?(user, project)
+ if url.is_a?(Hash) && project && user && !user.allowed_to?(url, project)
+ return false
+ end
+ if condition && !condition.call(project)
+ # Condition that doesn't pass
+ return false
+ end
+ return true
+ end
end
end
end