##// END OF EJS Templates
Introduce virtual MenuNodes (#15880)....
Jean-Philippe Lang -
r15119:53710d80fc88
parent child
Show More
@@ -147,7 +147,15 module Redmine
147 147 end
148 148
149 149 def render_single_menu_node(item, caption, url, selected)
150 link_to(h(caption), url, item.html_options(:selected => selected))
150 options = item.html_options(:selected => selected)
151
152 # virtual nodes are only there for their children to be displayed in the menu
153 # and should not do anything on click, except if otherwise defined elsewhere
154 if url.blank?
155 url = '#'
156 options.reverse_merge!(:onclick => 'return false;')
157 end
158 link_to(h(caption), url, options)
151 159 end
152 160
153 161 def render_unattached_menu_item(menu_item, project)
@@ -433,7 +441,14 module Redmine
433 441 # * Checking the permission or the url target (project only)
434 442 # * Checking the conditions of the item
435 443 def allowed?(user, project)
436 if user && project
444 if url.blank?
445 # this is a virtual node that is only there for its children to be diplayed in the menu
446 # it is considered an allowed node if at least one of the children is allowed
447 all_children = children
448 all_children += child_menus.call(project) if child_menus
449 return true if all_children.detect{|child| child.allowed?(user, project) }
450 return false
451 elsif user && project
437 452 if permission
438 453 unless user.allowed_to?(permission, project)
439 454 return false
@@ -208,6 +208,41 class Redmine::MenuManager::MenuHelperTest < ActionView::TestCase
208 208 end
209 209 end
210 210 end
211
212 def test_render_empty_virtual_menu_node_with_children
213
214 # only empty item with no click target
215 Redmine::MenuManager.map :menu1 do |menu|
216 menu.push(:parent_node, nil, { })
217 end
218
219 # parent with unallowed unattached child
220 Redmine::MenuManager.map :menu2 do |menu|
221 menu.push(:parent_node, nil, {:children => Proc.new {|p|
222 [Redmine::MenuManager::MenuItem.new("test_child_unallowed", {:controller => 'issues', :action => 'new'}, {})]
223 } })
224 end
225
226 # parent with unallowed standard child
227 Redmine::MenuManager.map :menu3 do |menu|
228 menu.push(:parent_node, nil, {})
229 menu.push(:test_child_unallowed, {:controller =>'issues', :action => 'new'}, {:parent => :parent_node})
230 end
231
232 # should not be displayed to anonymous
233 User.current = User.find(6)
234 assert_nil render_menu(:menu1, Project.find(1))
235 assert_nil render_menu(:menu2, Project.find(1))
236 assert_nil render_menu(:menu3, Project.find(1))
237
238 # should be displayed to an admin
239 User.current = User.find(1)
240 @output_buffer = render_menu(:menu2, Project.find(1))
241 assert_select("ul li a.parent-node", "Parent node")
242 @output_buffer = render_menu(:menu3, Project.find(1))
243 assert_select("ul li a.parent-node", "Parent node")
244
245 end
211 246
212 247 def test_render_menu_node_with_children_without_an_array
213 248 parent_node = Redmine::MenuManager::MenuItem.new(:parent_node,
General Comments 0
You need to be logged in to leave comments. Login now