From 1286ee29d97d2050cecc87fd1d44c295d9f66979 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Wed, 18 Nov 2020 16:15:19 +0000 Subject: shorten long line of lib/redmine/menu_manager.rb git-svn-id: http://svn.redmine.org/redmine/trunk@20416 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/menu_manager.rb | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'lib') 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) -- cgit v1.2.3