diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 52cdd75..cb85539 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -893,7 +893,8 @@ module ApplicationHelper
end
end
html_title args.reverse.map {|s| (s.is_a?(Array) ? s.first : s).to_s}
- content_tag('h2', strings.join(' » ').html_safe)
+ content_tag('h2', strings.join(' » ').html_safe) +
+ call_hook(:view_layouts_base_title_after, :title => args)
end
# Sets the html title
@@ -1807,13 +1808,18 @@ module ApplicationHelper
end
def sidebar_content?
- content_for?(:sidebar) || view_layouts_base_sidebar_hook_response.present?
+ content_for?(:sidebar) || view_layouts_base_sidebar_hook_response.present? ||
+ view_layouts_base_sidebar_top_hook_response.present?
end
def view_layouts_base_sidebar_hook_response
@view_layouts_base_sidebar_hook_response ||= call_hook(:view_layouts_base_sidebar)
end
+ def view_layouts_base_sidebar_top_hook_response
+ @view_layouts_base_sidebar_top_hook_response ||= call_hook(:view_layouts_base_sidebar_top)
+ end
+
def email_delivery_enabled?
!!ActionMailer::Base.perform_deliveries
end
diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb
index 3b5a19d..c240fbe 100644
--- a/app/views/issues/show.html.erb
+++ b/app/views/issues/show.html.erb
@@ -4,6 +4,7 @@
<% if @issue.is_private? %>
<%= l(:field_is_private) %>
<% end %>
+<%= call_hook(:view_issues_show_top, :issue => @issue) %>
<% if @prev_issue_id || @next_issue_id %>
@@ -143,8 +144,9 @@ end %>
<%= render :partial => 'relations' %>
<% end %>
<% end %>
-
+<%= call_hook(:view_issues_show_details_end, :issue => @issue) %>
+<%= call_hook(:view_issues_show_bottom, :issue => @issue) %>
<%= render partial: 'action_menu_edit' if User.current.wants_comments_in_reverse_order? %>
diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index e4ffb42..a1302a7 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -88,6 +88,7 @@
<% end %>
+ <%= call_hook :view_layouts_base_header_bottom %>
@@ -136,6 +138,7 @@
<%= javascript_tag "$('#sidebar-switch-panel').css('visibility', 'visible');" %>
<% end %>
@@ -146,13 +149,16 @@
<% if @project && !@project.active? %>
<%= sprite_icon('lock', l(:text_project_closed)) %>
<% end %>
+ <%= call_hook :view_layouts_base_content_top %>
<%= yield %>
<%= call_hook :view_layouts_base_content %>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb
index 9790700..5be352b 100644
--- a/app/views/users/edit.html.erb
+++ b/app/views/users/edit.html.erb
@@ -8,7 +8,7 @@
<%=
page_title = title [l(:label_user_plural), users_path], @user.login
- page_title.insert(page_title.rindex(' ') + 1, avatar(@user).to_s)
+ page_title.insert(page_title.rindex(' ', page_title.index('')) + 1, avatar(@user).to_s)
%>
<%= render_tabs user_settings_tabs %>
diff --git a/doc/HOOKS b/doc/HOOKS
new file mode 100644
index 0000000..b176cdb
--- /dev/null
+++ b/doc/HOOKS
@@ -0,0 +1,520 @@
+= Redmine hooks
+
+Every hook that Redmine calls, with the file it is called in and the keys of its
+context (besides :project, :controller, :request and :hook_caller, which view hooks
+always get). A plugin implements a hook as a method of a Redmine::Hook::Listener
+(controller and model hooks) or Redmine::Hook::ViewListener (view hooks), or with
+render_on. A hook listed here is kept; it is removed only after a deprecation notice
+in this file and in the changelog. test/unit/lib/redmine/hook_list_test.rb checks
+that every hook called in app/ and lib/ is listed here, and the other way round.
+
+Since: the version the hook appeared in; - for hooks older than this list.
+Context: the keys given on the line of the call (see the file for the rest).
+
+after_plugins_loaded
+ Since: -
+ Context: -
+ Called in: lib/redmine/plugin_loader.rb
+
+another_hook
+ Since: -
+ Context: :foo
+ Called in: lib/redmine/hook.rb
+
+controller_account_success_authentication_after
+ Since: -
+ Context: :user
+ Called in: app/controllers/account_controller.rb
+
+controller_custom_fields_edit_after_save
+ Since: -
+ Context: :params, :custom_field
+ Called in: app/controllers/custom_fields_controller.rb
+
+controller_custom_fields_new_after_save
+ Since: -
+ Context: :params, :custom_field
+ Called in: app/controllers/custom_fields_controller.rb
+
+controller_issues_bulk_edit_after_save
+ Since: -
+ Context: :params, :issue, :journal
+ Called in: app/controllers/issues_controller.rb
+
+controller_issues_bulk_edit_before_save
+ Since: -
+ Context: :params, :issue
+ Called in: app/controllers/issues_controller.rb
+
+controller_issues_edit_after_save
+ Since: 7.1.0
+ Context: -
+ Called in: app/controllers/issues_controller.rb
+
+controller_issues_edit_before_save
+ Since: 7.1.0
+ Context: -
+ Called in: app/controllers/issues_controller.rb
+
+controller_issues_new_after_save
+ Since: -
+ Context: :params, :issue
+ Called in: app/controllers/issues_controller.rb
+
+controller_issues_new_before_save
+ Since: -
+ Context: :params, :issue
+ Called in: app/controllers/issues_controller.rb
+
+controller_journals_edit_post
+ Since: -
+ Context: :journal, :params
+ Called in: app/controllers/journals_controller.rb
+
+controller_messages_new_after_save
+ Since: -
+ Context: :params, :message
+ Called in: app/controllers/messages_controller.rb
+
+controller_messages_reply_after_save
+ Since: -
+ Context: :params, :message
+ Called in: app/controllers/messages_controller.rb
+
+controller_time_entries_bulk_edit_before_save
+ Since: 7.1.0
+ Context: -
+ Called in: app/controllers/timelog_controller.rb
+
+controller_timelog_edit_before_save
+ Since: -
+ Context: -
+ Called in: app/controllers/timelog_controller.rb
+
+controller_wiki_edit_after_save
+ Since: -
+ Context: :params, :page
+ Called in: app/controllers/wiki_controller.rb
+
+controller_wiki_show_before_render
+ Since: -
+ Context: :content, :format
+ Called in: app/controllers/wiki_controller.rb
+
+helper_issues_show_detail_after_setting
+ Since: -
+ Context: -
+ Called in: app/helpers/issues_helper.rb
+
+helper_queries_column_content
+ Since: -
+ Context: -
+ Called in: app/helpers/queries_helper.rb
+
+helper_queries_column_value
+ Since: -
+ Context: -
+ Called in: app/helpers/queries_helper.rb
+
+model_changeset_scan_commit_for_issue_ids_pre_issue_update
+ Since: -
+ Context: -
+ Called in: app/models/changeset.rb
+
+model_project_copy_before_save
+ Since: -
+ Context: -
+ Called in: app/models/project.rb
+
+some_hook
+ Since: -
+ Context: -
+ Called in: lib/redmine/hook.rb
+
+view_account_left_bottom
+ Since: -
+ Context: :user
+ Called in: app/views/users/show.html.erb
+
+view_account_login_bottom
+ Since: -
+ Context: -
+ Called in: app/views/account/login.html.erb
+
+view_account_login_top
+ Since: -
+ Context: -
+ Called in: app/views/account/login.html.erb
+
+view_account_right_bottom
+ Since: -
+ Context: :user
+ Called in: app/views/users/show.html.erb
+
+view_admin_projects_sidebar_queries_bottom
+ Since: -
+ Context: -
+ Called in: app/views/admin/projects.html.erb
+
+view_calendars_show_bottom
+ Since: -
+ Context: :year, :month, :project, :query
+ Called in: app/views/calendars/show.html.erb
+
+view_custom_fields_form_upper_box
+ Since: -
+ Context: :custom_field, :form
+ Called in: app/views/custom_fields/_form.html.erb
+
+view_groups_memberships_table_header
+ Since: -
+ Context: :group
+ Called in: app/helpers/principal_memberships_helper.rb
+
+view_groups_memberships_table_row
+ Since: -
+ Context: :group, :membership
+ Called in: app/helpers/principal_memberships_helper.rb
+
+view_issue_statuses_form
+ Since: -
+ Context: :issue_status
+ Called in: app/views/issue_statuses/_form.html.erb
+
+view_issues_bulk_edit_details_bottom
+ Since: -
+ Context: :issues
+ Called in: app/views/issues/bulk_edit.html.erb
+
+view_issues_context_menu_end
+ Since: -
+ Context: :issues, :can, :back
+ Called in: app/views/context_menus/issues.html.erb
+
+view_issues_context_menu_start
+ Since: -
+ Context: :issues, :can, :back
+ Called in: app/views/context_menus/issues.html.erb
+
+view_issues_edit_notes_bottom
+ Since: -
+ Context: :issue, :notes, :form
+ Called in: app/views/issues/_edit.html.erb
+
+view_issues_edit_top
+ Since: -
+ Context: :issue, :form
+ Called in: app/views/issues/_edit.html.erb
+
+view_issues_form_details_bottom
+ Since: -
+ Context: :issue, :form
+ Called in: app/views/issues/_form.html.erb
+
+view_issues_form_details_top
+ Since: -
+ Context: :issue, :form
+ Called in: app/views/issues/_form.html.erb
+
+view_issues_history_changeset_bottom
+ Since: -
+ Context: :changeset
+ Called in: app/views/issues/tabs/_changesets.html.erb
+
+view_issues_history_journal_bottom
+ Since: -
+ Context: :journal
+ Called in: app/views/issues/tabs/_history.html.erb
+
+view_issues_history_time_entry_bottom
+ Since: -
+ Context: :time_entry
+ Called in: app/views/issues/tabs/_time_entries.html.erb
+
+view_issues_index_bottom
+ Since: -
+ Context: :issues, :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_bottom
+ Since: 7.1.0
+ Context: :issue
+ Called in: app/views/issues/show.html.erb
+
+view_issues_show_description_bottom
+ Since: -
+ Context: :issue
+ Called in: app/views/issues/show.html.erb
+
+view_issues_show_details_bottom
+ Since: -
+ Context: :issue
+ Called in: app/views/issues/show.html.erb
+
+view_issues_show_details_end
+ Since: 7.1.0
+ Context: :issue
+ Called in: app/views/issues/show.html.erb
+
+view_issues_show_top
+ Since: 7.1.0
+ Context: :issue
+ Called in: app/views/issues/show.html.erb
+
+view_issues_sidebar_issues_bottom
+ Since: -
+ Context: -
+ Called in: app/views/issues/_sidebar.html.erb
+
+view_issues_sidebar_planning_bottom
+ Since: -
+ Context: -
+ Called in: app/views/issues/_sidebar.html.erb
+
+view_issues_sidebar_queries_bottom
+ Since: -
+ Context: -
+ Called in: app/views/issues/_sidebar.html.erb
+
+view_journals_notes_form_after_notes
+ Since: -
+ Context: :journal
+ Called in: app/views/journals/_notes_form.html.erb
+
+view_journals_update_js_bottom
+ Since: -
+ Context: :journal
+ Called in: app/views/journals/update.js.erb
+
+view_layouts_base_body_bottom
+ Since: -
+ Context: -
+ Called in: app/views/layouts/base.html.erb
+
+view_layouts_base_body_top
+ Since: -
+ Context: -
+ Called in: app/views/layouts/base.html.erb
+
+view_layouts_base_content
+ Since: -
+ Context: -
+ Called in: app/views/layouts/base.html.erb
+
+view_layouts_base_content_top
+ Since: 7.1.0
+ Context: -
+ Called in: app/views/layouts/base.html.erb
+
+view_layouts_base_footer_bottom
+ Since: 7.1.0
+ Context: -
+ Called in: app/views/layouts/base.html.erb
+
+view_layouts_base_footer_top
+ Since: 7.1.0
+ Context: -
+ Called in: app/views/layouts/base.html.erb
+
+view_layouts_base_header_bottom
+ Since: 7.1.0
+ Context: -
+ Called in: app/views/layouts/base.html.erb
+
+view_layouts_base_header_top
+ Since: 7.1.0
+ Context: -
+ Called in: app/views/layouts/base.html.erb
+
+view_layouts_base_html_head
+ Since: -
+ Context: -
+ Called in: app/views/layouts/base.html.erb
+
+view_layouts_base_sidebar
+ Since: -
+ Context: -
+ Called in: app/helpers/application_helper.rb
+
+view_layouts_base_sidebar_top
+ Since: 7.1.0
+ Context: -
+ Called in: app/helpers/application_helper.rb
+
+view_layouts_base_title_after
+ Since: 7.1.0
+ Context: :title
+ Called in: app/helpers/application_helper.rb
+
+view_my_account
+ Since: -
+ Context: :user, :form
+ Called in: app/views/my/account.html.erb
+
+view_my_account_contextual
+ Since: -
+ Context: :user
+ Called in: app/views/my/account.html.erb
+
+view_my_account_preferences
+ Since: -
+ Context: :user, :form
+ Called in: app/views/my/account.html.erb
+
+view_my_page_contextual
+ Since: -
+ Context: :user
+ Called in: app/views/my/page.html.erb
+
+view_my_page_splitcontent
+ Since: -
+ Context: :user
+ Called in: app/views/my/page.html.erb
+
+view_projects_copy_only_items
+ Since: -
+ Context: :project, :f
+ Called in: app/views/projects/copy.html.erb
+
+view_projects_form
+ Since: -
+ Context: :project, :form
+ Called in: app/views/projects/_form.html.erb
+
+view_projects_roadmap_version_bottom
+ Since: -
+ Context: :version
+ Called in: app/views/versions/index.html.erb
+
+view_projects_settings_members_table_header
+ Since: -
+ Context: :project
+ Called in: app/views/members/_members.html.erb
+
+view_projects_settings_members_table_row
+ Since: -
+ Context: :project, :member
+ Called in: app/views/members/_members.html.erb
+
+view_projects_show_left
+ Since: -
+ Context: :project
+ Called in: app/views/projects/show.html.erb
+
+view_projects_show_right
+ Since: -
+ Context: :project
+ Called in: app/views/projects/show.html.erb
+
+view_projects_show_sidebar_bottom
+ Since: -
+ Context: :project
+ Called in: app/views/projects/show.html.erb
+
+view_projects_sidebar_queries_bottom
+ Since: -
+ Context: -
+ Called in: app/views/projects/_sidebar.html.erb
+
+view_reports_issue_report_split_content_left
+ Since: -
+ Context: :project
+ Called in: app/views/reports/issue_report.html.erb
+
+view_reports_issue_report_split_content_right
+ Since: -
+ Context: :project
+ Called in: app/views/reports/issue_report.html.erb
+
+view_repositories_show_contextual
+ Since: -
+ Context: :repository, :project
+ Called in: app/views/repositories/annotate.html.erb
+ Called in: app/views/repositories/changes.html.erb
+ Called in: app/views/repositories/entry.html.erb
+ Called in: app/views/repositories/show.html.erb
+
+view_search_index_options_content_bottom
+ Since: -
+ Context: -
+ Called in: app/views/search/index.html.erb
+
+view_settings_general_form
+ Since: -
+ Context: -
+ Called in: app/views/settings/_general.html.erb
+
+view_time_entries_bulk_edit_details_bottom
+ Since: -
+ Context: :time_entries
+ Called in: app/views/timelog/bulk_edit.html.erb
+
+view_time_entries_context_menu_end
+ Since: -
+ Context: :time_entries, :can, :back
+ Called in: app/views/context_menus/time_entries.html.erb
+
+view_time_entries_context_menu_start
+ Since: -
+ Context: :time_entries, :can, :back
+ Called in: app/views/context_menus/time_entries.html.erb
+
+view_timelog_edit_form_bottom
+ Since: -
+ Context: :time_entry, :form
+ Called in: app/views/timelog/_form.html.erb
+
+view_users_form
+ Since: -
+ Context: :user, :form
+ Called in: app/views/users/_form.html.erb
+
+view_users_form_preferences
+ Since: -
+ Context: :user, :form
+ Called in: app/views/users/_form.html.erb
+
+view_users_memberships_table_header
+ Since: -
+ Context: :user
+ Called in: app/helpers/principal_memberships_helper.rb
+
+view_users_memberships_table_row
+ Since: -
+ Context: :user, :membership
+ Called in: app/helpers/principal_memberships_helper.rb
+
+view_users_sidebar_queries_bottom
+ Since: -
+ Context: -
+ Called in: app/views/users/index.html.erb
+
+view_versions_show_bottom
+ Since: -
+ Context: :version
+ Called in: app/views/versions/show.html.erb
+
+view_versions_show_contextual
+ Since: -
+ Context: :version, :project
+ Called in: app/views/versions/show.html.erb
+
+view_welcome_index_left
+ Since: -
+ Context: -
+ Called in: app/views/welcome/index.html.erb
+
+view_welcome_index_right
+ Since: -
+ Context: -
+ Called in: app/views/welcome/index.html.erb
+
+view_wiki_show_sidebar_bottom
+ Since: -
+ Context: :wiki, :page
+ Called in: app/views/wiki/_sidebar.html.erb
diff --git a/test/integration/lib/redmine/view_hooks_test.rb b/test/integration/lib/redmine/view_hooks_test.rb
new file mode 100644
index 0000000..41e1c4e
--- /dev/null
+++ b/test/integration/lib/redmine/view_hooks_test.rb
@@ -0,0 +1,88 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006- Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require_relative '../../../test_helper'
+
+# The hooks 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),
+ '/users/2/edit' => %w(view_layouts_base_title_after),
+ '/admin/plugins' => %w(view_layouts_base_title_after)
+ }
+
+ # Answers every hook with a marker that is valid where the hook is called
+ class MarkerListener < Redmine::Hook::ViewListener
+ PAGES.values.flatten.uniq.each do |hook|
+ define_method(hook) do |context|
+ content_tag('span', 'marker', :class => "hook-#{hook}")
+ end
+ end
+ end
+
+ def setup
+ Redmine::Hook.clear_listeners
+ log_user('admin', 'admin')
+ end
+
+ def teardown
+ Redmine::Hook.clear_listeners
+ end
+
+ def html_errors
+ Nokogiri::HTML5(response.body, :max_errors => 100).errors.map(&:to_s)
+ end
+
+ def test_hooks_should_be_called_on_their_pages
+ Redmine::Hook.add_listener(MarkerListener)
+ PAGES.each do |path, hooks|
+ get path
+ assert_response :success, path
+ hooks.each do |hook|
+ assert_select ".hook-#{hook}", {:minimum => 1}, "#{hook} not called on #{path}"
+ end
+ end
+ end
+
+ def test_hook_output_should_not_make_the_html_invalid
+ PAGES.each_key do |path|
+ Redmine::Hook.clear_listeners
+ get path
+ without = html_errors
+ Redmine::Hook.add_listener(MarkerListener)
+ get path
+ assert_equal without, html_errors, "The hooks made the HTML of #{path} invalid"
+ end
+ end
+
+ def test_title_after_hook_should_leave_the_avatar_in_the_title
+ Redmine::Hook.add_listener(MarkerListener)
+ with_settings :gravatar_enabled => '1' do
+ get '/users/2/edit'
+ end
+ assert_select 'h2>a+img.gravatar'
+ assert_select 'h2 + span.hook-view_layouts_base_title_after'
+ end
+end
diff --git a/test/unit/lib/redmine/hook_list_test.rb b/test/unit/lib/redmine/hook_list_test.rb
new file mode 100644
index 0000000..87c5c96
--- /dev/null
+++ b/test/unit/lib/redmine/hook_list_test.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006- Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require_relative '../../../test_helper'
+
+# doc/HOOKS lists the hooks that Redmine calls; plugins rely on that list
+class Redmine::HookListTest < ActiveSupport::TestCase
+ def documented_hooks
+ Rails.root.join('doc/HOOKS').readlines.filter_map {|line| line[/\A([a-z0-9_]+)\s*\z/, 1]}
+ end
+
+ def called_hooks
+ Dir.glob(Rails.root.join('{app,lib}/**/*.{erb,rb}')).flat_map do |path|
+ File.read(path).scan(/call_hook\(?\s*:([a-z0-9_]+)/).flatten
+ end.uniq
+ end
+
+ def test_every_hook_called_should_be_documented
+ missing = called_hooks - documented_hooks
+ assert missing.empty?, "Hooks called but not listed in doc/HOOKS: #{missing.sort.join(', ')}"
+ end
+
+ def test_every_documented_hook_should_be_called
+ gone = documented_hooks - called_hooks
+ assert gone.empty?, "Hooks listed in doc/HOOKS but no longer called: #{gone.sort.join(', ')}"
+ end
+end