From 2662c1f9aca07e79d1d8868370cc725e52b374b6 Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Fri, 14 Mar 2014 08:04:46 +0100 Subject: [PATCH] A configurable option to inform the user about notifications recipients added --- app/controllers/dmsf_files_controller.rb | 12 ++++- app/controllers/dmsf_upload_controller.rb | 10 +++- app/controllers/dmsf_workflows_controller.rb | 55 ++++++++++++++++---- app/models/dmsf_workflow.rb | 2 +- app/views/settings/_dmsf_settings.html.erb | 17 +++++- config/locales/cs.yml | 4 ++ config/locales/de.yml | 4 ++ config/locales/en.yml | 4 ++ config/locales/es.yml | 4 ++ config/locales/fr.yml | 4 ++ config/locales/ja.yml | 4 ++ config/locales/ru.yml | 4 ++ config/locales/sl.yml | 4 ++ config/locales/zh.yml | 4 ++ init.rb | 9 ++-- lib/redmine_dmsf.rb | 2 + 16 files changed, 124 insertions(+), 19 deletions(-) diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index 0d33d6eb..16dabde0 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -117,9 +117,17 @@ class DmsfFilesController < ApplicationController flash[:notice] = (flash[:notice].nil? ? '' : flash[:notice]) + l(:notice_file_revision_created) log_activity('new revision') - begin - DmsfMailer.get_notify_users(User.current, [@file]).each do |u| + begin + recipients = DmsfMailer.get_notify_users(User.current, [@file]) + recipients.each do |u| DmsfMailer.files_updated(u, @project, [@file]).deliver + end + if Setting.plugin_redmine_dmsf[:dmsf_display_notified_recipients] == '1' + unless recipients.empty? + to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ') + to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, :to => to) + end end rescue Exception => e logger.error "Could not send email notifications: #{e.message}" diff --git a/app/controllers/dmsf_upload_controller.rb b/app/controllers/dmsf_upload_controller.rb index 1145af60..2344cb8f 100644 --- a/app/controllers/dmsf_upload_controller.rb +++ b/app/controllers/dmsf_upload_controller.rb @@ -174,8 +174,16 @@ class DmsfUploadController < ApplicationController unless files.empty? files.each { |file| log_activity(file, 'uploaded') if file } begin - DmsfMailer.get_notify_users(User.current, files).each do |u| + recipients = DmsfMailer.get_notify_users(User.current, files) + recipients.each do |u| DmsfMailer.files_updated(u, @project, files).deliver + end + if Setting.plugin_redmine_dmsf[:dmsf_display_notified_recipients] == '1' + unless recipients.empty? + to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ') + to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, :to => to) + end end rescue Exception => e Rails.logger.error "Could not send email notifications: #{e.message}" diff --git a/app/controllers/dmsf_workflows_controller.rb b/app/controllers/dmsf_workflows_controller.rb index 0594f209..a3b89034 100644 --- a/app/controllers/dmsf_workflows_controller.rb +++ b/app/controllers/dmsf_workflows_controller.rb @@ -67,6 +67,14 @@ class DmsfWorkflowsController < ApplicationController l(:text_email_finished_approved, :name => @dmsf_workflow.name, :filename => revision.file.name), l(:text_email_to_see_history)).deliver if member.user end + if Setting.plugin_redmine_dmsf[:dmsf_display_notified_recipients] == '1' + recipients = revision.file.project.members.collect{ |m| m.user } + unless recipients.empty? + to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ') + to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, :to => to) + end + end else # Just rejected recipients = @dmsf_workflow.participiants @@ -80,18 +88,30 @@ class DmsfWorkflowsController < ApplicationController l(:text_email_finished_rejected, :name => @dmsf_workflow.name, :filename => revision.file.name, :notice => action.note), l(:text_email_to_see_history)).deliver if user end + if Setting.plugin_redmine_dmsf[:dmsf_display_notified_recipients] == '1' + unless recipients.empty? + to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ') + to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, :to => to) + end + end end else if action.action == DmsfWorkflowStepAction::ACTION_DELEGATE # Delegation - delegate = User.find_by_id params[:step_action].to_i / 10 - DmsfMailer.workflow_notification( - delegate, - @dmsf_workflow, - revision, - l(:text_email_subject_delegated, :name => @dmsf_workflow.name), - l(:text_email_finished_delegated, :name => @dmsf_workflow.name, :filename => revision.file.name, :notice => action.note), - l(:text_email_to_proceed)).deliver if delegate + delegate = User.find_by_id params[:step_action].to_i / 10 + if delegate + DmsfMailer.workflow_notification( + delegate, + @dmsf_workflow, + revision, + l(:text_email_subject_delegated, :name => @dmsf_workflow.name), + l(:text_email_finished_delegated, :name => @dmsf_workflow.name, :filename => revision.file.name, :notice => action.note), + l(:text_email_to_proceed)).deliver + if Setting.plugin_redmine_dmsf[:dmsf_display_notified_recipients] == '1' + flash[:warning] = l(:warning_email_notifications, :to => delegate.name) + end + end else # Next step assignments = @dmsf_workflow.next_assignments revision.id @@ -115,7 +135,16 @@ class DmsfWorkflowsController < ApplicationController l(:text_email_subject_updated, :name => @dmsf_workflow.name), l(:text_email_finished_step_short, :name => @dmsf_workflow.name, :filename => revision.file.name), l(:text_email_to_see_status)).deliver if to - end + if Setting.plugin_redmine_dmsf[:dmsf_display_notified_recipients] == '1' + recipients = assignments.collect{ |a| a.user } + recipients << to if to && !recipients.include?(to) + unless recipients.empty? + to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ') + to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, :to => to) + end + end + end end end end @@ -283,6 +312,14 @@ class DmsfWorkflowsController < ApplicationController l(:text_email_started, :name => @dmsf_workflow.name, :filename => revision.file.name), l(:text_email_to_proceed)).deliver if assignment.user end + if Setting.plugin_redmine_dmsf[:dmsf_display_notified_recipients] == '1' + recipients = assignments.collect { |a| a.user } + unless recipients.empty? + to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ') + to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, :to => to) + end + end flash[:notice] = l(:notice_workflow_started) else flash[:error] = l(:notice_cannot_start_workflow) diff --git a/app/models/dmsf_workflow.rb b/app/models/dmsf_workflow.rb index df51b9b2..480e6b82 100644 --- a/app/models/dmsf_workflow.rb +++ b/app/models/dmsf_workflow.rb @@ -110,7 +110,7 @@ class DmsfWorkflow < ActiveRecord::Base sql = '1=1' end - unless q.nil? || q.empty? + if q.present? User.active.sorted.where(sql).like(q) else User.active.sorted.where(sql) diff --git a/app/views/settings/_dmsf_settings.html.erb b/app/views/settings/_dmsf_settings.html.erb index 3b22f537..1e784699 100644 --- a/app/views/settings/_dmsf_settings.html.erb +++ b/app/views/settings/_dmsf_settings.html.erb @@ -1,7 +1,8 @@ <%# Redmine plugin for Document Management System "Features" # -# Copyright (C) 2011 Vít Jonáš -# Copyright (C) 2012 Daniel Munn +# Copyright (C) 2011 Vít Jonáš +# Copyright (C) 2012 Daniel Munn +# Copyright (C) 2011-14 Karel Picman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -93,6 +94,18 @@ (<%= l(:label_default) %>: <%= l(:select_option_deactivated) %>)

+

+ <%= content_tag(:label, "#{l(:label_display_notified_recipients)}:") %> + <%= select_tag('settings[dmsf_display_notified_recipients]', + options_for_select([ + [l(:select_option_deactivated), nil], + [l(:select_option_activated), '1']], + :selected => @settings['dmsf_display_notified_recipients'])) %>
+ (<%= l(:label_default) %>: <%= l(:select_option_deactivated) %>) +
+ <%= l(:note_display_notified_recipients).html_safe %> +

+

diff --git a/config/locales/cs.yml b/config/locales/cs.yml index 52887000..7c3c6eba 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -294,6 +294,10 @@ cs: text_email_doc_deleted_subject: "Dokumenty projektu %{project} smazány" text_email_doc_deleted: právě smazal dokumety projektu label_links_only: pouze odkazy + + label_display_notified_recipients: Zobrazit příjemce notifikací + note_display_notified_recipients: Uživatel bude informován o příjemcích právě odeslané emailové notifikace. + warning_email_notifications: "Notifikační email poslán na uživatele %{to}" my: blocks: diff --git a/config/locales/de.yml b/config/locales/de.yml index ff410094..c87ea962 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -295,6 +295,10 @@ de: text_email_doc_deleted: has just deleted documents of label_links_only: links only + label_display_notified_recipients: Display notified recipients + note_display_notified_recipients: The user will be informed about all recipients of just sent the email notification. + warning_email_notifications: "Email notifications sent to %{to}" + my: blocks: locked_documents: Locked documents diff --git a/config/locales/en.yml b/config/locales/en.yml index a7a30a18..ab19583e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -295,6 +295,10 @@ en: text_email_doc_deleted: has just deleted documents of label_links_only: links only + label_display_notified_recipients: Display notified recipients + note_display_notified_recipients: The user will be informed about all recipients of just sent the email notification. + warning_email_notifications: "Email notifications sent to %{to}" + my: blocks: locked_documents: Locked documents diff --git a/config/locales/es.yml b/config/locales/es.yml index c0a248a0..c723ff91 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -295,6 +295,10 @@ es: text_email_doc_deleted: has just deleted documents of label_links_only: links only + label_display_notified_recipients: Display notified recipients + note_display_notified_recipients: The user will be informed about all recipients of just sent the email notification. + warning_email_notifications: "Email notifications sent to %{to}" + my: blocks: locked_documents: Locked documents diff --git a/config/locales/fr.yml b/config/locales/fr.yml index ca857ef9..4e233ad8 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -294,6 +294,10 @@ fr: text_email_doc_deleted_subject: "Documents of %{project} deleted" text_email_doc_deleted: has just deleted documents of label_links_only: links only + + label_display_notified_recipients: Display notified recipients + note_display_notified_recipients: The user will be informed about all recipients of just sent the email notification. + warning_email_notifications: "Email notifications sent to %{to}" my: blocks: diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 2e513374..dcf00ba8 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -295,6 +295,10 @@ ja: text_email_doc_deleted: has just deleted documents of label_links_only: links only + label_display_notified_recipients: Display notified recipients + note_display_notified_recipients: The user will be informed about all recipients of just sent the email notification. + warning_email_notifications: "Email notifications sent to %{to}" + my: blocks: locked_documents: Locked documents diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 6df546b6..d956f002 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -295,6 +295,10 @@ ru: text_email_doc_deleted: has just deleted documents of label_links_only: links only + label_display_notified_recipients: Display notified recipients + note_display_notified_recipients: The user will be informed about all recipients of just sent the email notification. + warning_email_notifications: "Email notifications sent to %{to}" + my: blocks: locked_documents: Locked documents diff --git a/config/locales/sl.yml b/config/locales/sl.yml index d7209f60..c59ea113 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -295,6 +295,10 @@ sl: text_email_doc_deleted: has just deleted documents of label_links_only: links only + label_display_notified_recipients: Display notified recipients + note_display_notified_recipients: The user will be informed about all recipients of just sent the email notification. + warning_email_notifications: "Email notifications sent to %{to}" + my: blocks: locked_documents: Locked documents diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 85d1e22c..41b08d87 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -295,6 +295,10 @@ zh: text_email_doc_deleted: has just deleted documents of label_links_only: links only + label_display_notified_recipients: Display notified recipients + note_display_notified_recipients: The user will be informed about all recipients of just sent the email notification. + warning_email_notifications: "Email notifications sent to %{to}" + my: blocks: locked_documents: Locked documents diff --git a/init.rb b/init.rb index d9975a94..49874718 100644 --- a/init.rb +++ b/init.rb @@ -1,8 +1,8 @@ # Redmine plugin for Document Management System "Features" # -# Copyright (C) 2011 Vít Jonáš -# Copyright (C) 2012 Daniel Munn -# Copyright (C) 2014 Karel Picman +# Copyright (C) 2011 Vít Jonáš +# Copyright (C) 2012 Daniel Munn +# Copyright (C) 2011-14 Karel Picman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -42,7 +42,8 @@ Redmine::Plugin.register :redmine_dmsf do 'dmsf_index_database' => Rails.root.join('files/dmsf_index').to_s, 'dmsf_stemming_lang' => 'english', 'dmsf_stemming_strategy' => 'STEM_NONE', - 'dmsf_webdav' => '1' + 'dmsf_webdav' => '1', + 'dmsf_display_notified_recipients' => 0 } menu :project_menu, :dmsf, { :controller => 'dmsf', :action => 'show' }, :caption => :menu_dmsf, :before => :documents, :param => :id diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index 49aa857c..ae1a483c 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -18,6 +18,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +DMSF_MAX_NOTIFICATION_RECEIVERS_INFO = 10 + # Vendor require 'redmine_dmsf/vendored_dav4rack'