1
0
mirror of https://github.com/meineerde/redmine.git synced 2025-12-20 15:31:12 +00:00

Code cleanup.

git-svn-id: http://svn.redmine.org/redmine/trunk@13764 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2014-12-14 21:01:51 +00:00
parent 8ac68457f5
commit cb3676a553

View File

@ -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