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:
parent
8ac68457f5
commit
cb3676a553
@ -61,7 +61,7 @@ module Redmine
|
|||||||
# Returns false if user is not authorized
|
# Returns false if user is not authorized
|
||||||
def redirect_to_project_menu_item(project, name)
|
def redirect_to_project_menu_item(project, name)
|
||||||
item = Redmine::MenuManager.items(:project_menu).detect {|i| i.name.to_s == name.to_s}
|
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))
|
redirect_to({item.param => project}.merge(item.url))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -153,17 +153,15 @@ module Redmine
|
|||||||
def render_unattached_menu_item(menu_item, project)
|
def render_unattached_menu_item(menu_item, project)
|
||||||
raise MenuError, ":child_menus must be an array of MenuItems" unless menu_item.is_a? MenuItem
|
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)
|
if menu_item.allowed?(User.current, project)
|
||||||
link_to(h(menu_item.caption),
|
link_to(menu_item.caption, menu_item.url, menu_item.html_options)
|
||||||
menu_item.url,
|
|
||||||
menu_item.html_options)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def menu_items_for(menu, project=nil)
|
def menu_items_for(menu, project=nil)
|
||||||
items = []
|
items = []
|
||||||
Redmine::MenuManager.items(menu).root.children.each do |node|
|
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?
|
if block_given?
|
||||||
yield node
|
yield node
|
||||||
else
|
else
|
||||||
@ -188,19 +186,9 @@ module Redmine
|
|||||||
return [caption, url, (current_menu_item == item.name)]
|
return [caption, url, (current_menu_item == item.name)]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if a user is allowed to access the menu item by:
|
# See MenuItem#allowed?
|
||||||
#
|
|
||||||
# * Checking the url target (project only)
|
|
||||||
# * Checking the conditions of the item
|
|
||||||
def allowed_node?(node, user, project)
|
def allowed_node?(node, user, project)
|
||||||
if node.url.is_a?(Hash) && project && user && !user.allowed_to?(node.url, project)
|
node.allowed?(user, project)
|
||||||
return false
|
|
||||||
end
|
|
||||||
if node.condition && !node.condition.call(project)
|
|
||||||
# Condition that doesn't pass
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -432,6 +420,21 @@ module Redmine
|
|||||||
@html_options
|
@html_options
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user