From 5e058f5aef1092761661e91b5ed1804246c62f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Tue, 23 May 2023 15:15:27 +0200 Subject: [PATCH] Empty array of notifications recipients --- app/controllers/dmsf_controller.rb | 6 ++++-- app/controllers/dmsf_files_controller.rb | 10 +++++++--- app/controllers/dmsf_workflows_controller.rb | 18 ++++++++++++------ app/helpers/dmsf_upload_helper.rb | 6 ++++-- app/models/dmsf_workflow.rb | 4 +++- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index a246f99e..a97dde58 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -634,8 +634,10 @@ class DmsfController < ApplicationController if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && recipients.any? max_receivers = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i to = recipients.collect { |user, _| user.name }.first(max_receivers).join(', ') - to << (recipients.count > max_receivers ? ',...' : '.') - flash[:warning] = l(:warning_email_notifications, to: to) if to.present? + if to.present? + to << (recipients.count > max_receivers ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, to: to) + end end rescue StandardError => e Rails.logger.error { "Could not send email notifications: #{e.message}" } diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index 8589b842..a74f5f4b 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -182,7 +182,9 @@ class DmsfFilesController < ApplicationController if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && recipients.any? max_notifications = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i to = recipients.collect { |user, _| user.name }.first(max_notifications).join(', ') - to << (recipients.count > max_notifications ? ',...' : '.') + if to.present? + to << (recipients.count > max_notifications ? ',...' : '.') + end end rescue StandardError => e Rails.logger.error "Could not send email notifications: #{e.message}" @@ -223,8 +225,10 @@ class DmsfFilesController < ApplicationController if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && recipients.any? max_notification = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i to = recipients.collect { |user, _| user.name }.first(max_notification).join(', ') - to << (recipients.count > max_notification ? ',...' : '.') - flash[:warning] = l(:warning_email_notifications, to: to) if to.present? + if to.present? + to << (recipients.count > max_notification ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, to: to) + end end rescue StandardError => 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 bb6b776a..081fe1f5 100644 --- a/app/controllers/dmsf_workflows_controller.rb +++ b/app/controllers/dmsf_workflows_controller.rb @@ -101,8 +101,10 @@ class DmsfWorkflowsController < ApplicationController if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && recipients.present? max_notifications = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i to = recipients.collect(&:name).first(max_notifications).join(', ') - to << (recipients.count > max_notifications ? ',...' : '.') - flash[:warning] = l(:warning_email_notifications, to: to) if to.present? + if to.present? + to << (recipients.count > max_notifications ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, to: to) + end end end elsif Setting.notified_events.include?('dmsf_workflow_plural') # Just rejected @@ -122,8 +124,10 @@ class DmsfWorkflowsController < ApplicationController if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && recipients.present? max_notifications = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i to = recipients.collect(&:name).first(max_notifications).join(', ') - to << (recipients.count > max_notifications ? ',...' : '.') - flash[:warning] = l(:warning_email_notifications, to: to) if to.present? + if to.present? + to << (recipients.count > max_notifications ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, to: to) + end end end elsif action.action == DmsfWorkflowStepAction::ACTION_DELEGATE @@ -189,8 +193,10 @@ class DmsfWorkflowsController < ApplicationController unless recipients.empty? max_notifications = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i to = recipients.collect(&:name).first(max_notifications).join(', ') - to << (recipients.count > max_notifications ? ',...' : '.') - flash[:warning] = l(:warning_email_notifications, to: to) if to.present? + if to.present? + to << (recipients.count > max_notifications ? ',...' : '.') + flash[:warning] = l(:warning_email_notifications, to: to) + end end end end diff --git a/app/helpers/dmsf_upload_helper.rb b/app/helpers/dmsf_upload_helper.rb index 117a7b55..3600832d 100644 --- a/app/helpers/dmsf_upload_helper.rb +++ b/app/helpers/dmsf_upload_helper.rb @@ -141,8 +141,10 @@ module DmsfUploadHelper if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients'] && recipients.any? max_recipients = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i to = recipients.collect { |user, _| user.name }.first(max_recipients).join(', ') - to << (recipients.count > max_recipients ? ',...' : '.') - controller.flash[:warning] = l(:warning_email_notifications, to: to) if controller && to.present? + if to.present? + to << (recipients.count > max_recipients ? ',...' : '.') + controller.flash[:warning] = l(:warning_email_notifications, to: to) if controller + end end rescue StandardError => e Rails.logger.error { "Could not send email notifications: #{e.message}" } diff --git a/app/models/dmsf_workflow.rb b/app/models/dmsf_workflow.rb index a089d28a..ccdd8d80 100644 --- a/app/models/dmsf_workflow.rb +++ b/app/models/dmsf_workflow.rb @@ -253,7 +253,9 @@ class DmsfWorkflow < ApplicationRecord max_recipients = Setting.plugin_redmine_dmsf['dmsf_max_notification_receivers_info'].to_i to = recipients.collect(&:name).first(max_recipients).join(', ') + return if to.blank? + to << (recipients.count > max_recipients.to_i ? ',...' : '.') - controller.flash[:warning] = l(:warning_email_notifications, to: to) if controller && to.present? + controller.flash[:warning] = l(:warning_email_notifications, to: to) if controller end end