diff --git a/app/views/boards/show.html.erb b/app/views/boards/show.html.erb
index 2fd6c60..caaa483 100644
--- a/app/views/boards/show.html.erb
+++ b/app/views/boards/show.html.erb
@@ -10,6 +10,7 @@
{:controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'},
:class => 'icon icon-settings' if User.current.allowed_to?(:manage_boards, @project) %>
+<%= call_hook(:view_boards_show_contextual, {:board => @board, :project => @project}) %>
diff --git a/app/views/context_menus/issues.html.erb b/app/views/context_menus/issues.html.erb
index 20f72fa..599e0eb 100644
--- a/app/views/context_menus/issues.html.erb
+++ b/app/views/context_menus/issues.html.erb
@@ -178,5 +178,6 @@
:method => :delete, :data => {:confirm => issues_destroy_confirmation_message(@issues)}, :class => 'icon icon-del', :disabled => !@can[:delete] %>
<% end %>
+ <%= render_object_menu_items(:issue_context_menu, @issues, @project, list: true) %>
<%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %>
diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb
index 2fba22f..b034a88 100644
--- a/app/views/documents/index.html.erb
+++ b/app/views/documents/index.html.erb
@@ -1,6 +1,7 @@
<%= link_to sprite_icon('add', l(:label_document_new)), new_project_document_path(@project), :class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-document", "document_title"); return false;' if User.current.allowed_to?(:add_documents, @project) %>
+<%= call_hook(:view_documents_index_contextual, {:project => @project}) %>
diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb
index 47333e7..322db6d 100644
--- a/app/views/documents/show.html.erb
+++ b/app/views/documents/show.html.erb
@@ -5,6 +5,7 @@
<% if User.current.allowed_to?(:delete_documents, @project) %>
<%= delete_link document_path(@document) %>
<% end %>
+<%= call_hook(:view_documents_show_contextual, {:document => @document, :project => @project}) %>
<%= @document.title %>
diff --git a/app/views/groups/show.html.erb b/app/views/groups/show.html.erb
index 4620b27..f0e25b6 100644
--- a/app/views/groups/show.html.erb
+++ b/app/views/groups/show.html.erb
@@ -1,5 +1,6 @@
<%= link_to(sprite_icon('edit', l(:button_edit)), edit_group_path(@group), :class => 'icon icon-edit') if User.current.admin? %>
+<%= call_hook(:view_groups_show_contextual, {:group => @group}) %>
<%= @group.name %>
diff --git a/app/views/issues/_action_menu.html.erb b/app/views/issues/_action_menu.html.erb
index 8b5d302..0843d08 100644
--- a/app/views/issues/_action_menu.html.erb
+++ b/app/views/issues/_action_menu.html.erb
@@ -7,10 +7,13 @@
<%= watcher_link(@issue, User.current) %>
<%= link_to sprite_icon('copy', l(:button_copy)), project_copy_issue_path(@project, @issue),
:class => 'icon icon-copy ' if User.current.allowed_to?(:copy_issues, @project) && Issue.allowed_target_projects.any? %>
+<%= call_hook(:view_issues_show_contextual, {:issue => @issue, :project => @project}) %>
<%= actions_dropdown do %>
<%= copy_object_url_link(issue_url(@issue, only_path: false)) %>
+ <%= render_object_menu_items(:issue_actions, @issue, @project) %>
<%= link_to sprite_icon('del', l(:button_delete_object, object_name: l(:label_issue)).capitalize), issue_path(@issue),
:data => {:confirm => issues_destroy_confirmation_message(@issue)},
:method => :delete, :class => 'icon icon-del ' if @issue.deletable? %>
+ <%= call_hook(:view_issues_show_actions_menu, {:issue => @issue, :project => @project}) %>
<% end %>
diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb
index aa88291..2e93b4a 100644
--- a/app/views/issues/index.html.erb
+++ b/app/views/issues/index.html.erb
@@ -2,6 +2,7 @@
<% if User.current.allowed_to?(:add_issues, @project, :global => true) && (@project.nil? || Issue.allowed_target_trackers(@project).any?) %>
<%= link_to sprite_icon('add', l(:label_issue_new)), _new_project_issue_path(@project), :class => 'icon icon-add new-issue' %>
<% end %>
+ <%= call_hook(:view_issues_index_contextual, {:project => @project, :query => @query}) %>
<%= actions_dropdown do %>
<% if @project %>
<%= link_to sprite_icon('summary', l(:field_summary)), project_issues_report_path(@project), :class => 'icon icon-stats' %>
@@ -14,6 +15,7 @@
<%= link_to_if_authorized sprite_icon('settings', l(:label_settings)),
{:controller => 'projects', :action => 'settings', :id => @project, :tab => 'issues'},
:class => 'icon icon-settings' if User.current.allowed_to?(:edit_project, @project) %>
+ <%= call_hook(:view_issues_index_actions_menu, {:project => @project, :query => @query}) %>
<% end %>
diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb
index e60c803..3bc45ba 100644
--- a/app/views/messages/show.html.erb
+++ b/app/views/messages/show.html.erb
@@ -18,6 +18,7 @@
:data => { :confirm => l(:text_are_you_sure) },
:class => 'icon icon-del'
) if @message.destroyable_by?(User.current) %>
+ <%= call_hook(:view_messages_show_contextual, {:topic => @topic, :message => @message, :project => @project}) %>
<%= avatar(@topic.author) %><%= @topic.subject %>
diff --git a/app/views/news/index.html.erb b/app/views/news/index.html.erb
index addb5d8..04fe812 100644
--- a/app/views/news/index.html.erb
+++ b/app/views/news/index.html.erb
@@ -4,6 +4,7 @@
:class => 'icon icon-add add-news-link',
:onclick => 'showAndScrollTo("add-news", "news_title"); return false;') if User.current.allowed_to?(:manage_news, @project, global: true) %>
<%= watcher_link(@project.enabled_module('news'), User.current) if @project && User.current.logged? %>
+<%= call_hook(:view_news_index_contextual, {:project => @project}) %>
diff --git a/app/views/news/show.html.erb b/app/views/news/show.html.erb
index 008460f..8bfe416 100644
--- a/app/views/news/show.html.erb
+++ b/app/views/news/show.html.erb
@@ -7,6 +7,7 @@
:accesskey => accesskey(:edit),
:onclick => '$("#edit-news").show(); return false;') if User.current.allowed_to?(:manage_news, @project) %>
<%= delete_link news_path(@news) if User.current.allowed_to?(:manage_news, @project) %>
+<%= call_hook(:view_news_show_contextual, {:news => @news, :project => @project}) %>
<%= avatar(@news.author) %> <%=h @news.title %>
diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb
index 875e736..7a80596 100644
--- a/app/views/projects/index.html.erb
+++ b/app/views/projects/index.html.erb
@@ -2,6 +2,7 @@
<%= form_tag({}, :method => :get) do %>
<% end %>
<%= render_project_action_links %>
+ <%= call_hook(:view_projects_index_contextual, {:query => @query}) %>
<%= @query.new_record? ? l(:label_project_plural) : @query.name %>
diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb
index ffbfcce..d6a530d 100644
--- a/app/views/projects/show.html.erb
+++ b/app/views/projects/show.html.erb
@@ -1,6 +1,7 @@
<%= bookmark_link @project %>
+ <%= call_hook(:view_projects_show_contextual, {:project => @project}) %>
<%= actions_dropdown do %>
<% if User.current.allowed_to?(:add_subprojects, @project) %>
<%= link_to sprite_icon('add', l(:label_subproject_new)), new_project_path(:parent_id => @project), :class => 'icon icon-add' %>
@@ -18,6 +19,8 @@
<%= link_to_if_authorized sprite_icon('settings', l(:label_settings)),
{:controller => 'projects', :action => 'settings', :id => @project},
:class => 'icon icon-settings' if User.current.allowed_to?(:edit_project, @project) %>
+ <%= render_object_menu_items(:project_actions, @project, @project) %>
+ <%= call_hook(:view_projects_show_actions_menu, {:project => @project}) %>
<% end %>
diff --git a/app/views/repositories/_navigation.html.erb b/app/views/repositories/_navigation.html.erb
index dfdac39..1214112 100644
--- a/app/views/repositories/_navigation.html.erb
+++ b/app/views/repositories/_navigation.html.erb
@@ -22,6 +22,7 @@
<%= link_to sprite_icon('reload', l(:button_fetch_changesets)),
{:action => :fetch_changesets, :id => @project, :repository_id => @repository.identifier_param},
:class => 'icon icon-reload', :method => :post if User.current.allowed_to?(:manage_repository, @project) && !Setting.autofetch_changesets? %>
+ <%= call_hook(:view_repositories_navigation_actions_menu, {:repository => @repository, :project => @project}) %>
<% end %>
<%= form_tag({:action => controller.action_name,
diff --git a/app/views/timelog/index.html.erb b/app/views/timelog/index.html.erb
index 5e61dd2..033b077 100644
--- a/app/views/timelog/index.html.erb
+++ b/app/views/timelog/index.html.erb
@@ -2,6 +2,7 @@
<%= link_to sprite_icon('time-add', l(:button_log_time)),
_new_time_entry_path(@project, @query.filtered_issue_id),
:class => 'icon icon-time-add' if User.current.allowed_to?(:log_time, @project, :global => true) %>
+<%= call_hook(:view_timelog_index_contextual, {:project => @project, :query => @query}) %>
<%= actions_dropdown do %>
<% if User.current.allowed_to?(:import_time_entries, @project, :global => true) && User.current.allowed_to?(:log_time, @project, :global => true) %>
<%= link_to sprite_icon('import', l(:button_import)), new_time_entries_import_path(:project_id => @project), :class => 'icon icon-import' %>
@@ -10,6 +11,7 @@
<%= link_to_if_authorized sprite_icon('settings', l(:label_settings)),
{:controller => 'projects', :action => 'settings', :id => @project, :tab => 'activities'},
:class => 'icon icon-settings' if User.current.allowed_to?(:manage_project_activities, @project) %>
+ <%= call_hook(:view_timelog_index_actions_menu, {:project => @project, :query => @query}) %>
<% end %>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb
index eb975a5..bd4e28f 100644
--- a/app/views/users/index.html.erb
+++ b/app/views/users/index.html.erb
@@ -1,9 +1,11 @@
<%= link_to sprite_icon('add', l(:label_user_new)), new_user_path, :class => 'icon icon-add' %>
+ <%= call_hook(:view_users_index_contextual, {:query => @query}) %>
<%= actions_dropdown do %>
<% if User.current.allowed_to?(:import_users, nil, :global => true) %>
<%= link_to sprite_icon('import', l(:button_import)), new_users_import_path, :class => 'icon icon-import' %>
<% end %>
+ <%= call_hook(:view_users_index_actions_menu, {:query => @query}) %>
<% end %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index a221927..9229732 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -1,5 +1,7 @@
<%= link_to(sprite_icon('edit', l(:button_edit)), edit_user_path(@user), :class => 'icon icon-edit') if User.current.admin? && @user.logged? %>
+<%= render_object_menu_items(:user_actions, @user) %>
+<%= call_hook(:view_users_show_contextual, {:user => @user}) %>
<%= avatar_edit_link(@user, :size => "50") %> <%= @user.name %>
diff --git a/app/views/versions/index.html.erb b/app/views/versions/index.html.erb
index 79339e7..c5ee0df 100644
--- a/app/views/versions/index.html.erb
+++ b/app/views/versions/index.html.erb
@@ -1,10 +1,12 @@
<%= link_to(sprite_icon('add', l(:label_version_new)), new_project_version_path(@project),
:class => 'icon icon-add') if User.current.allowed_to?(:manage_versions, @project) %>
+ <%= call_hook(:view_versions_index_contextual, {:project => @project}) %>
<%= actions_dropdown do %>
<%= link_to_if_authorized sprite_icon('settings', l(:label_settings)),
{:controller => 'projects', :action => 'settings', :id => @project, :tab => 'versions'},
:class => 'icon icon-settings' if User.current.allowed_to?(:manage_versions, @project) %>
+ <%= call_hook(:view_versions_index_actions_menu, {:project => @project}) %>
<% end %>
diff --git a/app/views/versions/show.html.erb b/app/views/versions/show.html.erb
index cdd2b30..22430cf 100644
--- a/app/views/versions/show.html.erb
+++ b/app/views/versions/show.html.erb
@@ -3,6 +3,7 @@
<%= link_to_if_authorized(sprite_icon('edit', l(:button_edit_associated_wikipage, :page_title => @version.wiki_page_title)), { :controller => 'wiki', :action => 'edit', :project_id => @version.project, :id => Wiki.titleize(@version.wiki_page_title)}, :class => 'icon icon-edit') unless @version.wiki_page_title.blank? || @version.project.wiki.nil? %>
<%= delete_link version_path(@version, :back_url => url_for(:controller => 'versions', :action => 'index', :project_id => @version.project)) if User.current.allowed_to?(:manage_versions, @version.project) %>
<%= link_to_new_issue(@version, @project) %>
+<%= render_object_menu_items(:version_actions, @version, @version.project) %>
<%= call_hook(:view_versions_show_contextual, { :version => @version, :project => @project }) %>
diff --git a/app/views/wiki/show.html.erb b/app/views/wiki/show.html.erb
index 4b222ef..5ed4e6b 100644
--- a/app/views/wiki/show.html.erb
+++ b/app/views/wiki/show.html.erb
@@ -7,6 +7,7 @@
<% end %>
<% end %>
+ <%= call_hook(:view_wiki_show_contextual, {:page => @page, :project => @project}) %>
<%= actions_dropdown do %>
<%= link_to_if_authorized(sprite_icon('history', l(:label_history)), { :action => 'history', :id => @page.title}, :class => 'icon icon-history') %>
@@ -24,6 +25,7 @@
<% if User.current.allowed_to?(:edit_wiki_pages, @project) %>
<%= link_to sprite_icon('add', l(:label_wiki_page_new)), new_project_wiki_page_path(@project, :parent => @page.title), :remote => true, :class => 'icon icon-add' %>
<% end %>
+ <%= call_hook(:view_wiki_show_actions_menu, {:page => @page, :project => @project}) %>
<% end %>
diff --git a/doc/HOOKS b/doc/HOOKS
index b176cdb..9cedec8 100644
--- a/doc/HOOKS
+++ b/doc/HOOKS
@@ -156,6 +156,11 @@ view_admin_projects_sidebar_queries_bottom
Context: -
Called in: app/views/admin/projects.html.erb
+view_boards_show_contextual
+ Since: 7.1.0
+ Context: :board, :project
+ Called in: app/views/boards/show.html.erb
+
view_calendars_show_bottom
Since: -
Context: :year, :month, :project, :query
@@ -166,6 +171,16 @@ view_custom_fields_form_upper_box
Context: :custom_field, :form
Called in: app/views/custom_fields/_form.html.erb
+view_documents_index_contextual
+ Since: 7.1.0
+ Context: :project
+ Called in: app/views/documents/index.html.erb
+
+view_documents_show_contextual
+ Since: 7.1.0
+ Context: :document, :project
+ Called in: app/views/documents/show.html.erb
+
view_groups_memberships_table_header
Since: -
Context: :group
@@ -176,6 +191,11 @@ view_groups_memberships_table_row
Context: :group, :membership
Called in: app/helpers/principal_memberships_helper.rb
+view_groups_show_contextual
+ Since: 7.1.0
+ Context: :group
+ Called in: app/views/groups/show.html.erb
+
view_issue_statuses_form
Since: -
Context: :issue_status
@@ -231,21 +251,41 @@ view_issues_history_time_entry_bottom
Context: :time_entry
Called in: app/views/issues/tabs/_time_entries.html.erb
+view_issues_index_actions_menu
+ Since: 7.1.0
+ Context: :project, :query
+ Called in: app/views/issues/index.html.erb
+
view_issues_index_bottom
Since: -
Context: :issues, :project, :query
Called in: app/views/issues/index.html.erb
+view_issues_index_contextual
+ Since: 7.1.0
+ Context: :project, :query
+ Called in: app/views/issues/index.html.erb
+
view_issues_new_top
Since: -
Context: :issue
Called in: app/views/issues/new.html.erb
+view_issues_show_actions_menu
+ Since: 7.1.0
+ Context: :issue, :project
+ Called in: app/views/issues/_action_menu.html.erb
+
view_issues_show_bottom
Since: 7.1.0
Context: :issue
Called in: app/views/issues/show.html.erb
+view_issues_show_contextual
+ Since: 7.1.0
+ Context: :issue, :project
+ Called in: app/views/issues/_action_menu.html.erb
+
view_issues_show_description_bottom
Since: -
Context: :issue
@@ -351,6 +391,11 @@ view_layouts_base_title_after
Context: :title
Called in: app/helpers/application_helper.rb
+view_messages_show_contextual
+ Since: 7.1.0
+ Context: :topic, :message, :project
+ Called in: app/views/messages/show.html.erb
+
view_my_account
Since: -
Context: :user, :form
@@ -376,6 +421,16 @@ view_my_page_splitcontent
Context: :user
Called in: app/views/my/page.html.erb
+view_news_index_contextual
+ Since: 7.1.0
+ Context: :project
+ Called in: app/views/news/index.html.erb
+
+view_news_show_contextual
+ Since: 7.1.0
+ Context: :news, :project
+ Called in: app/views/news/show.html.erb
+
view_projects_copy_only_items
Since: -
Context: :project, :f
@@ -386,6 +441,11 @@ view_projects_form
Context: :project, :form
Called in: app/views/projects/_form.html.erb
+view_projects_index_contextual
+ Since: 7.1.0
+ Context: :query
+ Called in: app/views/projects/index.html.erb
+
view_projects_roadmap_version_bottom
Since: -
Context: :version
@@ -401,6 +461,16 @@ view_projects_settings_members_table_row
Context: :project, :member
Called in: app/views/members/_members.html.erb
+view_projects_show_actions_menu
+ Since: 7.1.0
+ Context: :project
+ Called in: app/views/projects/show.html.erb
+
+view_projects_show_contextual
+ Since: 7.1.0
+ Context: :project
+ Called in: app/views/projects/show.html.erb
+
view_projects_show_left
Since: -
Context: :project
@@ -431,6 +501,11 @@ view_reports_issue_report_split_content_right
Context: :project
Called in: app/views/reports/issue_report.html.erb
+view_repositories_navigation_actions_menu
+ Since: 7.1.0
+ Context: :repository, :project
+ Called in: app/views/repositories/_navigation.html.erb
+
view_repositories_show_contextual
Since: -
Context: :repository, :project
@@ -469,6 +544,16 @@ view_timelog_edit_form_bottom
Context: :time_entry, :form
Called in: app/views/timelog/_form.html.erb
+view_timelog_index_actions_menu
+ Since: 7.1.0
+ Context: :project, :query
+ Called in: app/views/timelog/index.html.erb
+
+view_timelog_index_contextual
+ Since: 7.1.0
+ Context: :project, :query
+ Called in: app/views/timelog/index.html.erb
+
view_users_form
Since: -
Context: :user, :form
@@ -479,6 +564,16 @@ view_users_form_preferences
Context: :user, :form
Called in: app/views/users/_form.html.erb
+view_users_index_actions_menu
+ Since: 7.1.0
+ Context: :query
+ Called in: app/views/users/index.html.erb
+
+view_users_index_contextual
+ Since: 7.1.0
+ Context: :query
+ Called in: app/views/users/index.html.erb
+
view_users_memberships_table_header
Since: -
Context: :user
@@ -489,11 +584,26 @@ view_users_memberships_table_row
Context: :user, :membership
Called in: app/helpers/principal_memberships_helper.rb
+view_users_show_contextual
+ Since: 7.1.0
+ Context: :user
+ Called in: app/views/users/show.html.erb
+
view_users_sidebar_queries_bottom
Since: -
Context: -
Called in: app/views/users/index.html.erb
+view_versions_index_actions_menu
+ Since: 7.1.0
+ Context: :project
+ Called in: app/views/versions/index.html.erb
+
+view_versions_index_contextual
+ Since: 7.1.0
+ Context: :project
+ Called in: app/views/versions/index.html.erb
+
view_versions_show_bottom
Since: -
Context: :version
@@ -514,6 +624,16 @@ view_welcome_index_right
Context: -
Called in: app/views/welcome/index.html.erb
+view_wiki_show_actions_menu
+ Since: 7.1.0
+ Context: :page, :project
+ Called in: app/views/wiki/show.html.erb
+
+view_wiki_show_contextual
+ Since: 7.1.0
+ Context: :page, :project
+ Called in: app/views/wiki/show.html.erb
+
view_wiki_show_sidebar_bottom
Since: -
Context: :wiki, :page
diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb
index 5d14fc1..a9d36fa 100644
--- a/lib/redmine/menu_manager.rb
+++ b/lib/redmine/menu_manager.rb
@@ -118,6 +118,52 @@ module Redmine
links.empty? ? nil : content_tag('ul', links.join.html_safe)
end
+ # Renders the items that plugins added to the menu of an object:
+ # * :issue_actions - the actions menu of an issue (object: the issue)
+ # * :issue_context_menu - the context menu of the issue list (object: the selected issues)
+ # * :project_actions - the actions menu of a project overview (object: the project)
+ # * :user_actions - the actions of a user page (object: the user)
+ # * :version_actions - the actions of a version page (object: the version)
+ #
+ # For these menus, the :if and :caption Procs and a Proc url receive the object; a
+ # Hash url gets the object as its :param (or :ids for a list of objects), and the
+ # :permission is checked in +project+.
+ # menu :issue_actions, :a_action, {:controller => 'a_plugin', :action => 'do'},
+ # :caption => :label_a_action, :icon => 'add', :if => Proc.new {|issue| issue.closed?}
+ #
+ # +list+ renders each link in a +li+ (context menu).
+ def render_object_menu_items(menu, object, project=nil, list: false)
+ links = []
+ Redmine::MenuManager.items(menu).root.children.each do |item|
+ next unless object_menu_item_allowed?(item, object, project)
+
+ url =
+ case item.url
+ when Proc then item.url.call(object)
+ when Hash
+ # a list of objects is an Array or a relation (the selected issues)
+ many = object.respond_to?(:to_ary)
+ key = many ? :ids : item.param
+ value = many ? object.to_ary.map(&:id).sort : object
+ {key => value}.merge(item.url)
+ when Symbol then send(item.url, object)
+ else item.url
+ end
+ caption = item.caption(object)
+ label = item.icon.present? ? sprite_icon(item.icon, h(caption), plugin: item.plugin) : h(caption)
+ link = link_to(label, use_absolute_controller(url), item.html_options)
+ links << (list ? content_tag('li', link) : link)
+ end
+ safe_join(links)
+ end
+
+ def object_menu_item_allowed?(item, object, project)
+ return false if project && item.permission && !User.current.allowed_to?(item.permission, project)
+ return false if item.condition && !item.condition.call(object)
+
+ true
+ end
+
def render_menu_node(node, project=nil)
if node.children.present? || !node.child_menus.nil?
return render_menu_node_with_children(node, project)
diff --git a/test/integration/lib/redmine/view_hooks_test.rb b/test/integration/lib/redmine/view_hooks_test.rb
index c2b0b9f..a599a9f 100644
--- a/test/integration/lib/redmine/view_hooks_test.rb
+++ b/test/integration/lib/redmine/view_hooks_test.rb
@@ -19,17 +19,34 @@
require_relative '../../../test_helper'
-# The hooks and registries that let plugins add to pages without overriding
-# core views or helpers: each one is called on its page, and what a plugin adds
-# through them leaves the page's HTML as valid as it was.
+# The hooks, registries and menus that let plugins add to pages without
+# overriding core views or helpers: each one is called on its page, and what a
+# plugin adds through them leaves the page's HTML as valid as it was.
class ViewHooksTest < Redmine::IntegrationTest
# The pages and the hooks each one must call
PAGES = {
'/projects/ecookbook' => %w(
view_layouts_base_header_top view_layouts_base_header_bottom view_layouts_base_sidebar_top
- view_layouts_base_content_top view_layouts_base_footer_top view_layouts_base_footer_bottom),
- '/issues/1' => %w(view_issues_show_top view_issues_show_details_end view_issues_show_bottom),
+ view_layouts_base_content_top view_layouts_base_footer_top view_layouts_base_footer_bottom
+ view_projects_show_contextual view_projects_show_actions_menu),
+ '/projects/ecookbook/issues' => %w(view_issues_index_contextual view_issues_index_actions_menu),
+ '/issues/1' => %w(
+ view_issues_show_contextual view_issues_show_actions_menu view_issues_show_top view_issues_show_details_end
+ view_issues_show_bottom),
+ '/projects?display_type=list' => %w(view_projects_index_contextual),
+ '/users' => %w(view_users_index_contextual view_users_index_actions_menu),
+ '/users/2' => %w(view_users_show_contextual),
'/users/2/edit' => %w(view_layouts_base_title_after),
+ '/groups/10' => %w(view_groups_show_contextual),
+ '/projects/ecookbook/roadmap' => %w(view_versions_index_contextual view_versions_index_actions_menu),
+ '/projects/ecookbook/wiki' => %w(view_wiki_show_contextual view_wiki_show_actions_menu),
+ '/projects/ecookbook/news' => %w(view_news_index_contextual),
+ '/news/1' => %w(view_news_show_contextual),
+ '/projects/ecookbook/documents' => %w(view_documents_index_contextual),
+ '/documents/1' => %w(view_documents_show_contextual),
+ '/projects/ecookbook/boards/1' => %w(view_boards_show_contextual),
+ '/boards/1/topics/1' => %w(view_messages_show_contextual),
+ '/projects/ecookbook/time_entries' => %w(view_timelog_index_contextual view_timelog_index_actions_menu),
'/admin/plugins' => %w(view_layouts_base_title_after)
}
@@ -58,6 +75,9 @@ class ViewHooksTest < Redmine::IntegrationTest
Redmine::Hook.clear_listeners
Redmine::Tabs.clear
Redmine::JournalDetails.clear
+ %w(issue_actions issue_context_menu project_actions user_actions version_actions).each do |menu|
+ Redmine::MenuManager.map(menu).delete(:sample)
+ end
end
def html_errors
@@ -75,6 +95,19 @@ class ViewHooksTest < Redmine::IntegrationTest
end
end
+ def test_contextual_hook_should_be_before_the_actions_menu_and_the_menu_hook_inside_it
+ Redmine::Hook.add_listener(MarkerListener)
+ PAGES.each do |path, hooks|
+ menu = hooks.detect {|hook| hook.end_with?('_actions_menu')}
+ next unless menu
+
+ contextual = hooks.detect {|hook| hook.end_with?('_contextual')}
+ get path
+ assert_select "div.contextual .hook-#{contextual} ~ span.dropdown", {:minimum => 1}, "#{contextual} not before the menu on #{path}"
+ assert_select "span.dropdown .dropdown-items .hook-#{menu}", {:minimum => 1}, "#{menu} not in the menu on #{path}"
+ end
+ end
+
def test_hook_output_should_not_make_the_html_invalid
PAGES.each_key do |path|
Redmine::Hook.clear_listeners
@@ -121,4 +154,28 @@ class ViewHooksTest < Redmine::IntegrationTest
get '/issues/1'
assert_select 'span.sample-detail', :text => 'Sample changed to high'
end
+
+ def test_object_menus_should_show_the_items_of_plugins
+ options = {:caption => 'Sample action', :html => {:class => 'icon sample-action'}}
+ Redmine::MenuManager.map(:issue_actions).push :sample, {:controller => 'issues', :action => 'show'}, options
+ Redmine::MenuManager.map(:project_actions).push :sample, Proc.new {|project| "/projects/#{project.identifier}"}, options
+ Redmine::MenuManager.map(:user_actions).push :sample, Proc.new {|user| "/users/#{user.id}"}, options
+ Redmine::MenuManager.map(:version_actions).push :sample, '/versions', options.merge(:if => Proc.new {|version| version.id == 2})
+ Redmine::MenuManager.map(:issue_context_menu).push :sample, {:controller => 'issues', :action => 'index'}, options
+
+ get '/issues/1'
+ assert_select 'a.sample-action[href="/issues/1"]', :text => 'Sample action'
+ get '/projects/ecookbook'
+ assert_select 'a.sample-action[href="/projects/ecookbook"]'
+ get '/users/2'
+ assert_select 'a.sample-action[href="/users/2"]'
+ get '/versions/2'
+ assert_select 'a.sample-action'
+ get '/versions/3'
+ assert_select 'a.sample-action', 0
+ get '/issues/context_menu', :params => {:ids => [1, 2]}, :xhr => true
+ # the context menu links are full URLs
+ assert_select 'li a.sample-action[href$=?]', '/issues?ids%5B%5D=1&ids%5B%5D=2', {},
+ "Links found: #{css_select('a.sample-action').pluck('href').inspect}"
+ end
end