diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2020-11-18 16:15:19 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2020-11-18 16:15:19 +0000 |
commit | 1286ee29d97d2050cecc87fd1d44c295d9f66979 (patch) | |
tree | bae2c2f7a117922120b7f80d8883ccb70355456b /lib | |
parent | f7fc0410789f71047ee1f60b1fe456b5bc3f4a5c (diff) | |
download | redmine-1286ee29d97d2050cecc87fd1d44c295d9f66979.tar.gz redmine-1286ee29d97d2050cecc87fd1d44c295d9f66979.zip |
shorten long line of lib/redmine/menu_manager.rb
git-svn-id: http://svn.redmine.org/redmine/trunk@20416 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/menu_manager.rb | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb index db8e3e79c..4c6ad0d55 100644 --- a/lib/redmine/menu_manager.rb +++ b/lib/redmine/menu_manager.rb @@ -226,7 +226,10 @@ module Redmine # See MenuItem#allowed? 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) end end @@ -415,13 +418,23 @@ module Redmine class MenuItem < MenuNode 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={}) - raise ArgumentError, "Invalid option :if for menu item '#{name}'" 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, "Cannot set the :parent to be the same as this item" if options[:parent] == name.to_sym - raise ArgumentError, "Invalid option :children for menu item '#{name}'" if options[:children] && !options[:children].respond_to?(:call) + if options[:if] && !options[:if].respond_to?(:call) + raise ArgumentError, "Invalid option :if for menu item '#{name}'" + end + 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 @url = url @condition = options[:if] @@ -472,7 +485,9 @@ module Redmine # it is considered an allowed node if at least one of the children is allowed all_children = children 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 if permission unless user.allowed_to?(permission, project) |