From 1f8ad9bf4d9991595028dde87781267b6866182e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Tue, 2 Jul 2024 10:12:43 +0200 Subject: [PATCH] Use an existing hook rather than re-rendering the original view (prevent view_paths.unshift) --- .../redmine_dmsf/_view_mailer_issue.html.erb} | 27 ++++-------- .../redmine_dmsf/_view_mailer_issue.text.erb | 26 ++++++++++++ .../redmine_dmsf/_view_my_account.html.erb | 12 ++++++ app/views/mailer/_issue.html.erb | 10 +---- app/views/mailer/_issue.text.erb | 7 +--- lib/redmine_dmsf.rb | 1 + .../hooks/views/mailer_view_hooks.rb | 41 +++++++++++++++++++ .../hooks/views/my_account_view_hooks.rb | 5 +-- 8 files changed, 91 insertions(+), 38 deletions(-) rename app/views/{my/_sidebar.html.erb => hooks/redmine_dmsf/_view_mailer_issue.html.erb} (53%) create mode 100644 app/views/hooks/redmine_dmsf/_view_mailer_issue.text.erb create mode 100644 lib/redmine_dmsf/hooks/views/mailer_view_hooks.rb diff --git a/app/views/my/_sidebar.html.erb b/app/views/hooks/redmine_dmsf/_view_mailer_issue.html.erb similarity index 53% rename from app/views/my/_sidebar.html.erb rename to app/views/hooks/redmine_dmsf/_view_mailer_issue.html.erb index b9fe2eb9..79c12d74 100644 --- a/app/views/my/_sidebar.html.erb +++ b/app/views/hooks/redmine_dmsf/_view_mailer_issue.html.erb @@ -1,9 +1,7 @@ <% - # encoding: utf-8 - # # Redmine plugin for Document Management System "Features" # - # Karel Pičman + # Vít Jonáš , Daniel Munn , Karel Pičman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -20,21 +18,12 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. %> -<%# Render the original view %> -<% view_paths.unshift Rails.root.join('app/views').to_s %> -<%= render partial: 'my/sidebar' %> - -<%# DMSF extension do %> -<% if Setting.plugin_redmine_dmsf['dmsf_webdav_authentication'] == 'Digest' %> -

<%= l(:label_dmsf_webdav_digest) %>

-

- <% token = Token.find_by(user_id: @user.id, action: 'dmsf-webdav-digest') %> - <% if token %> - <%= l(:label_dmsf_webdav_digest_created_on, distance_of_time_in_words(Time.now, token.created_on)) %> - <% else %> - <%= l(:label_missing_dmsf_webdav_digest) %> +<% if issue.dmsf_files.any? %> +
+

<%= l(:label_dmsf_file_plural) %> + <% issue.dmsf_files.each do |f| %> + <%= link_to h(f.name), static_dmsf_file_url(f, filename: f.name) %> + (<%= number_to_human_size(f.last_revision.size) %>)
<% end %> - (<%= link_to l(:button_reset), dmsf_digest_path, remote: true %>) -

+
<% end %> -<%# end %> diff --git a/app/views/hooks/redmine_dmsf/_view_mailer_issue.text.erb b/app/views/hooks/redmine_dmsf/_view_mailer_issue.text.erb new file mode 100644 index 00000000..dd93622e --- /dev/null +++ b/app/views/hooks/redmine_dmsf/_view_mailer_issue.text.erb @@ -0,0 +1,26 @@ +<% + # Redmine plugin for Document Management System "Features" + # + # Vít Jonáš , Daniel Munn , Karel Pičman + # + # 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. +%> + +<% if issue.dmsf_files.any? %> + ---<%= l(:label_dmsf_file_plural).ljust(37, '-') %> + <% issue.dmsf_files.each do |f| %> + <%= f.name %> (<%= number_to_human_size(f.last_revision.size) %>) + <% end %> +<% end %> diff --git a/app/views/hooks/redmine_dmsf/_view_my_account.html.erb b/app/views/hooks/redmine_dmsf/_view_my_account.html.erb index 5765d0b2..642c8e3e 100644 --- a/app/views/hooks/redmine_dmsf/_view_my_account.html.erb +++ b/app/views/hooks/redmine_dmsf/_view_my_account.html.erb @@ -28,3 +28,15 @@

<%= pref_fields.check_box :receive_download_notification %>

<% end %> +<% if Setting.plugin_redmine_dmsf['dmsf_webdav_authentication'] == 'Digest' %> +

+ + <% token = Token.find_by(user_id: @user.id, action: 'dmsf-webdav-digest') %> + <% if token %> + <%= l(:label_dmsf_webdav_digest_created_on, distance_of_time_in_words(Time.now, token.created_on)) %> + <% else %> + <%= l(:label_missing_dmsf_webdav_digest) %> + <% end %> + (<%= link_to l(:button_reset), dmsf_digest_path, remote: true, id: 'webdav_digest_reset' %>) +

+<% end %> diff --git a/app/views/mailer/_issue.html.erb b/app/views/mailer/_issue.html.erb index 04124883..d918a6ac 100644 --- a/app/views/mailer/_issue.html.erb +++ b/app/views/mailer/_issue.html.erb @@ -25,13 +25,5 @@ <%= render partial: 'mailer/issue', locals: { issue: issue, issue_url: issue_url, user: user } %> <%# DMSF extension do %> -<% if issue.dmsf_files.any? %> -
-
<%= l(:label_dmsf_file_plural) %> - <% issue.dmsf_files.each do |f| %> - <%= link_to h(f.name), static_dmsf_file_url(f, filename: f.name) %> - (<%= number_to_human_size(f.last_revision.size) %>)
- <% end %> -
-<% end %> + <%= render partial: 'hooks/redmine_dmsf/view_mailer_issue', locals: { issue: issue } %> <%# end %> diff --git a/app/views/mailer/_issue.text.erb b/app/views/mailer/_issue.text.erb index d5e7c64d..d918a6ac 100644 --- a/app/views/mailer/_issue.text.erb +++ b/app/views/mailer/_issue.text.erb @@ -25,10 +25,5 @@ <%= render partial: 'mailer/issue', locals: { issue: issue, issue_url: issue_url, user: user } %> <%# DMSF extension do %> -<% if issue.dmsf_files.any? %> ----<%= l(:label_dmsf_file_plural).ljust(37, '-') %> -<% issue.dmsf_files.each do |f| %> -<%= f.name %> (<%= number_to_human_size(f.last_revision.size) %>) -<% end %> -<% end %> + <%= render partial: 'hooks/redmine_dmsf/view_mailer_issue', locals: { issue: issue } %> <%# end %> diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index ea387f13..417eeaab 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -77,6 +77,7 @@ def require_hooks require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/base_view_hooks" require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/custom_field_view_hooks" require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/issue_view_hooks" + require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/mailer_view_hooks" require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/my_account_view_hooks" require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/views/search_view_hooks" require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/helpers/issues_helper_hooks" diff --git a/lib/redmine_dmsf/hooks/views/mailer_view_hooks.rb b/lib/redmine_dmsf/hooks/views/mailer_view_hooks.rb new file mode 100644 index 00000000..8e5bb142 --- /dev/null +++ b/lib/redmine_dmsf/hooks/views/mailer_view_hooks.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +# Redmine plugin for Document Management System "Features" +# +# Karel Pičman +# +# 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. +# User form view hooks + +module RedmineDmsf + module Hooks + module Views + # Mailer view hooks + class MailerViewHooks < Redmine::Hook::ViewListener + def view_mailer_issue_show_text_bottom(context = {}) + context[:controller].send :render_to_string, + { partial: 'hooks/redmine_dmsf/view_mailer_issue', + locals: { issue: context[:issue] } } + end + + def view_mailer_issue_show_html_bottom(context = {}) + context[:controller].send :render_to_string, + { partial: 'hooks/redmine_dmsf/view_mailer_issue', + locals: { issue: context[:issue] } } + end + end + end + end +end diff --git a/lib/redmine_dmsf/hooks/views/my_account_view_hooks.rb b/lib/redmine_dmsf/hooks/views/my_account_view_hooks.rb index 20146f27..d9bd322e 100644 --- a/lib/redmine_dmsf/hooks/views/my_account_view_hooks.rb +++ b/lib/redmine_dmsf/hooks/views/my_account_view_hooks.rb @@ -25,10 +25,7 @@ module RedmineDmsf # My account view hooks class MyAccountViewHooks < Redmine::Hook::ViewListener def view_my_account_preferences(context = {}) - return unless context.is_a?(Hash) && context[:user] - - context[:controller].send :render_to_string, - { partial: 'hooks/redmine_dmsf/view_my_account', locals: context } + context[:controller].send :render_to_string, { partial: 'hooks/redmine_dmsf/view_my_account' } end end end