]> source.dussan.org Git - redmine.git/commitdiff
Child nodes should only be rendered if the user is actually authorized to see them...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 8 May 2016 06:48:36 +0000 (06:48 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 8 May 2016 06:48:36 +0000 (06:48 +0000)
Patch by Jan Schulz-Hofen.

git-svn-id: http://svn.redmine.org/redmine/trunk@15393 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/menu_manager.rb
test/unit/lib/redmine/menu_manager/menu_helper_test.rb

index 619f8f30caae90398bd02daa4facd41a300e8fa7..fa7777065355374d614b4f7d458527f10df69f73 100644 (file)
@@ -114,7 +114,7 @@ module Redmine
           # Standard children
           standard_children_list = "".html_safe.tap do |child_html|
             node.children.each do |child|
-              child_html << render_menu_node(child, project)
+              child_html << render_menu_node(child, project) if allowed_node?(child, User.current, project)
             end
           end
 
@@ -138,7 +138,7 @@ module Redmine
           # Tree nodes support #each so we need to do object detection
           if unattached_children.is_a? Array
             unattached_children.each do |child|
-              child_html << content_tag(:li, render_unattached_menu_item(child, project))
+              child_html << content_tag(:li, render_unattached_menu_item(child, project)) if allowed_node?(child, User.current, project)
             end
           else
             raise MenuError, ":child_menus must be an array of MenuItems"
@@ -192,6 +192,7 @@ 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
         node.allowed?(user, project)
       end
     end
index 975991eb521465a268817bcdf3fb3e5e61217030..404ec64065d79c7620da4682d0564a526d50ff28 100644 (file)
@@ -119,7 +119,7 @@ class Redmine::MenuManager::MenuHelperTest < ActionView::TestCase
     User.current = User.find(2)
 
     parent_node = Redmine::MenuManager::MenuItem.new(:parent_node,
-                                                     '/test',
+                                                     {:controller => 'issues', :action => 'index'},
                                                      {
                                                        :children => Proc.new {|p|
                                                          children = []
@@ -131,7 +131,7 @@ class Redmine::MenuManager::MenuHelperTest < ActionView::TestCase
                                                      })
 
     parent_node << Redmine::MenuManager::MenuItem.new(:child_node,
-                                                     '/test',
+                                                     {:controller => 'issues', :action => 'index'},
                                                      {
                                                        :children => Proc.new {|p|
                                                          children = []
@@ -163,6 +163,52 @@ class Redmine::MenuManager::MenuHelperTest < ActionView::TestCase
     end
   end
 
+  def test_render_menu_node_with_allowed_and_unallowed_unattached_children
+    User.current = User.find(2)
+
+    parent_node = Redmine::MenuManager::MenuItem.new(:parent_node,
+                                                     {:controller => 'issues', :action => 'index'},
+                                                     {
+                                                       :children => Proc.new {|p|
+                                                         [
+                                                           Redmine::MenuManager::MenuItem.new("test_child_allowed", {:controller => 'issues', :action => 'index'}, {}),
+                                                           Redmine::MenuManager::MenuItem.new("test_child_unallowed", {:controller => 'issues', :action => 'unallowed'}, {}),
+                                                         ]
+                                                       }
+                                                     })
+
+    @output_buffer = render_menu_node(parent_node, Project.find(1))
+
+    assert_select("li") do
+      assert_select("a.parent-node", "Parent node")
+      assert_select("ul.menu-children.unattached") do
+        assert_select("li a.test-child-allowed", "Test child allowed")
+        assert_select("li a.test-child-unallowed", false)
+      end
+    end
+  end
+
+  def test_render_menu_node_with_allowed_and_unallowed_standard_children
+    User.current = User.find(6)
+
+    Redmine::MenuManager.map :some_menu do |menu|
+      menu.push(:parent_node, {:controller => 'issues', :action => 'index'}, { })
+      menu.push(:test_child_allowed, {:controller => 'issues', :action => 'index'}, {:parent => :parent_node})
+      menu.push(:test_child_unallowed, {:controller => 'issues', :action => 'new'}, {:parent => :parent_node})
+    end
+
+    @output_buffer = render_menu(:some_menu, Project.find(1))
+
+    assert_select("li") do
+      assert_select("a.parent-node", "Parent node")
+      assert_select("ul.menu-children.unattached", false)
+      assert_select("ul.menu-children") do
+        assert_select("li a.test-child-allowed", "Test child allowed")
+        assert_select("li a.test-child-unallowed", false)
+      end
+    end
+  end
+
   def test_render_menu_node_with_children_without_an_array
     parent_node = Redmine::MenuManager::MenuItem.new(:parent_node,
                                                      '/test',