diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-12-14 21:01:51 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-12-14 21:01:51 +0000 |
commit | cb3676a553fbce76f5e5ff351f9f7974c674a0d6 (patch) | |
tree | 622c0bbeb69cc303d0d5e301f6ad7101329470e7 /lib/redmine/menu_manager.rb | |
parent | 8ac68457f5eba4869acb4fde465e40a798e01c02 (diff) | |
download | redmine-cb3676a553fbce76f5e5ff351f9f7974c674a0d6.tar.gz redmine-cb3676a553fbce76f5e5ff351f9f7974c674a0d6.zip |
Code cleanup.
git-svn-id: http://svn.redmine.org/redmine/trunk@13764 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/menu_manager.rb')
-rw-r--r-- | lib/redmine/menu_manager.rb | 39 |
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 |