mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-22 16:31:12 +00:00
shorten long line of lib/redmine/menu_manager.rb
git-svn-id: http://svn.redmine.org/redmine/trunk@20416 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
f7fc041078
commit
1286ee29d9
@ -226,7 +226,10 @@ module Redmine
|
|||||||
|
|
||||||
# See MenuItem#allowed?
|
# See MenuItem#allowed?
|
||||||
def allowed_node?(node, user, project)
|
def allowed_node?(node, user, project)
|
||||||
raise MenuError, ":child_menus must be an array of MenuItems" unless node.is_a? MenuItem
|
unless node.is_a? MenuItem
|
||||||
|
raise MenuError, ":child_menus must be an array of MenuItems"
|
||||||
|
end
|
||||||
|
|
||||||
node.allowed?(user, project)
|
node.allowed?(user, project)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -415,13 +418,23 @@ module Redmine
|
|||||||
|
|
||||||
class MenuItem < MenuNode
|
class MenuItem < MenuNode
|
||||||
include Redmine::I18n
|
include Redmine::I18n
|
||||||
attr_reader :name, :url, :param, :condition, :parent, :child_menus, :last, :permission
|
attr_reader :name, :url, :param, :condition, :parent,
|
||||||
|
:child_menus, :last, :permission
|
||||||
|
|
||||||
def initialize(name, url, options={})
|
def initialize(name, url, options={})
|
||||||
raise ArgumentError, "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
|
if options[:if] && !options[:if].respond_to?(:call)
|
||||||
raise ArgumentError, "Invalid option :html for menu item '#{name}'" if options[:html] && !options[:html].is_a?(Hash)
|
raise ArgumentError, "Invalid option :if for menu item '#{name}'"
|
||||||
raise ArgumentError, "Cannot set the :parent to be the same as this item" if options[:parent] == name.to_sym
|
end
|
||||||
raise ArgumentError, "Invalid option :children for menu item '#{name}'" if options[:children] && !options[:children].respond_to?(:call)
|
if options[:html] && !options[:html].is_a?(Hash)
|
||||||
|
raise ArgumentError, "Invalid option :html for menu item '#{name}'"
|
||||||
|
end
|
||||||
|
if options[:parent] == name.to_sym
|
||||||
|
raise ArgumentError, "Cannot set the :parent to be the same as this item"
|
||||||
|
end
|
||||||
|
if options[:children] && !options[:children].respond_to?(:call)
|
||||||
|
raise ArgumentError, "Invalid option :children for menu item '#{name}'"
|
||||||
|
end
|
||||||
|
|
||||||
@name = name
|
@name = name
|
||||||
@url = url
|
@url = url
|
||||||
@condition = options[:if]
|
@condition = options[:if]
|
||||||
@ -472,7 +485,9 @@ module Redmine
|
|||||||
# it is considered an allowed node if at least one of the children is allowed
|
# it is considered an allowed node if at least one of the children is allowed
|
||||||
all_children = children
|
all_children = children
|
||||||
all_children += child_menus.call(project) if child_menus
|
all_children += child_menus.call(project) if child_menus
|
||||||
return false unless all_children.detect{|child| child.allowed?(user, project) }
|
unless all_children.detect{|child| child.allowed?(user, project)}
|
||||||
|
return false
|
||||||
|
end
|
||||||
elsif user && project
|
elsif user && project
|
||||||
if permission
|
if permission
|
||||||
unless user.allowed_to?(permission, project)
|
unless user.allowed_to?(permission, project)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user