#557 Notifications sent to watchers
This commit is contained in:
parent
e028d1f83c
commit
218bf47fdf
@ -75,7 +75,7 @@ class DmsfWorkflowsController < ApplicationController
|
||||
if revision.workflow == DmsfWorkflow::STATE_APPROVED
|
||||
# Just approved
|
||||
if Setting.notified_events.include?('dmsf_workflow_action')
|
||||
recipients = DmsfMailer.get_notify_users(@project, [revision.dmsf_file], true)
|
||||
recipients = DmsfMailer.get_notify_users(@project, revision.dmsf_file, true)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
recipients,
|
||||
@dmsf_workflow,
|
||||
@ -97,7 +97,7 @@ class DmsfWorkflowsController < ApplicationController
|
||||
recipients = @dmsf_workflow.participiants
|
||||
recipients.push revision.dmsf_workflow_assigned_by_user
|
||||
recipients.uniq!
|
||||
recipients = recipients & DmsfMailer.get_notify_users(@project, [revision.dmsf_file], true)
|
||||
recipients = recipients & DmsfMailer.get_notify_users(@project, revision.dmsf_file, true)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
recipients,
|
||||
@dmsf_workflow,
|
||||
@ -120,7 +120,7 @@ class DmsfWorkflowsController < ApplicationController
|
||||
# Delegation
|
||||
if Setting.notified_events.include?('dmsf_workflow_action')
|
||||
delegate = User.active.find_by(id: params[:step_action].to_i / 10)
|
||||
if DmsfMailer.get_notify_users(@project, [revision.dmsf_file], true).include?(delegate)
|
||||
if DmsfMailer.get_notify_users(@project, revision.dmsf_file, true).include?(delegate)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
[delegate],
|
||||
@dmsf_workflow,
|
||||
@ -143,7 +143,7 @@ class DmsfWorkflowsController < ApplicationController
|
||||
if assignments.first.dmsf_workflow_step.step != action.dmsf_workflow_step_assignment.dmsf_workflow_step.step
|
||||
# Next step
|
||||
assignments.each do |assignment|
|
||||
if assignment.user && DmsfMailer.get_notify_users(@project, [revision.dmsf_file],
|
||||
if assignment.user && DmsfMailer.get_notify_users(@project, revision.dmsf_file,
|
||||
true).include?(assignment.user)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
[assignment.user],
|
||||
@ -157,7 +157,7 @@ class DmsfWorkflowsController < ApplicationController
|
||||
end
|
||||
end
|
||||
to = revision.dmsf_workflow_assigned_by_user
|
||||
if to && DmsfMailer.get_notify_users(@project, [revision.dmsf_file],
|
||||
if to && DmsfMailer.get_notify_users(@project, revision.dmsf_file,
|
||||
true).include?(to)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
[to],
|
||||
@ -171,7 +171,7 @@ class DmsfWorkflowsController < ApplicationController
|
||||
recipients = assignments.collect{ |a| a.user }
|
||||
recipients << to if to
|
||||
recipients.uniq!
|
||||
recipients = recipients & DmsfMailer.get_notify_users(@project, [revision.dmsf_file],
|
||||
recipients = recipients & DmsfMailer.get_notify_users(@project, revision.dmsf_file,
|
||||
true)
|
||||
unless recipients.empty?
|
||||
to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ')
|
||||
|
||||
@ -147,19 +147,17 @@ module DmsfUploadHelper
|
||||
end
|
||||
end
|
||||
# Notifications
|
||||
if (folder && folder.notification?) || (!folder && project.dmsf_notification?)
|
||||
begin
|
||||
recipients = DmsfMailer.deliver_files_updated(project, files)
|
||||
if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients']
|
||||
unless recipients.empty?
|
||||
to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ')
|
||||
to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.')
|
||||
controller.flash[:warning] = l(:warning_email_notifications, to: to) if controller
|
||||
end
|
||||
begin
|
||||
recipients = DmsfMailer.deliver_files_updated(project, files)
|
||||
if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients']
|
||||
unless recipients.empty?
|
||||
to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ')
|
||||
to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.')
|
||||
controller.flash[:warning] = l(:warning_email_notifications, to: to) if controller
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.error "Could not send email notifications: #{e.message}"
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.error "Could not send email notifications: #{e.message}"
|
||||
end
|
||||
end
|
||||
if failed_uploads.present? && controller
|
||||
|
||||
@ -215,10 +215,16 @@ class DmsfFile < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def notify?
|
||||
return true if notification
|
||||
return true if dmsf_folder && dmsf_folder.notify?
|
||||
return true if !dmsf_folder && project.dmsf_notification
|
||||
false
|
||||
notification dmsf_folder&.notify? || (!dmsf_folder && project.dmsf_notification)
|
||||
end
|
||||
|
||||
def get_all_watchers(watchers)
|
||||
watchers.concat notified_watchers
|
||||
if dmsf_folder
|
||||
watchers.concat dmsf_folder.notified_watchers
|
||||
else
|
||||
watchers.concat project.notified_watchers
|
||||
end
|
||||
end
|
||||
|
||||
def notify_deactivate
|
||||
|
||||
@ -203,10 +203,16 @@ class DmsfFolder < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def notify?
|
||||
return true if notification
|
||||
return true if dmsf_folder&.notify?
|
||||
return true if !dmsf_folder && project.dmsf_notification
|
||||
false
|
||||
notification || dmsf_folder&.notify? || (!dmsf_folder && project.dmsf_notification)
|
||||
end
|
||||
|
||||
def get_all_watchers(watchers)
|
||||
watchers << notified_watchers
|
||||
if dmsf_folder
|
||||
watchers << dmsf_folder.notified_watchers
|
||||
else
|
||||
watchers << project.notified_watchers
|
||||
end
|
||||
end
|
||||
|
||||
def notify_deactivate
|
||||
|
||||
@ -26,8 +26,7 @@ class DmsfMailer < Mailer
|
||||
layout 'mailer'
|
||||
|
||||
def self.deliver_files_updated(project, files)
|
||||
users = get_notify_users(project, files)
|
||||
files = files.select { |file| file.notify? }
|
||||
users = get_notify_users(project, files.first)
|
||||
users.each do |user|
|
||||
files_updated(user, project, files).deliver_later
|
||||
end
|
||||
@ -48,8 +47,7 @@ class DmsfMailer < Mailer
|
||||
end
|
||||
|
||||
def self.deliver_files_deleted(project, files)
|
||||
users = get_notify_users(project, files)
|
||||
files = files.select { |file| file.notify? }
|
||||
users = get_notify_users(project, file.first)
|
||||
users.each do |user|
|
||||
files_deleted(user, project, files).deliver_later
|
||||
end
|
||||
@ -137,60 +135,46 @@ class DmsfMailer < Mailer
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_notify_users(project, files = [], force_notification = false)
|
||||
# force_notification = true => approval workflow's notifications
|
||||
def self.get_notify_users(project, file, force_notification = false)
|
||||
return [] unless project.active?
|
||||
if !force_notification && files.present?
|
||||
notify_files = files.select { |file| file.notify? }
|
||||
return [] if notify_files.empty?
|
||||
end
|
||||
notify_members = project.members.active.select do |notify_member|
|
||||
notify_user = notify_member.user
|
||||
if notify_user == User.current && notify_user.pref.no_self_notified
|
||||
false
|
||||
else
|
||||
if notify_member.dmsf_mail_notification.nil?
|
||||
case notify_user.mail_notification
|
||||
when 'all'
|
||||
true
|
||||
when 'selected'
|
||||
notify_member.mail_notification?
|
||||
when 'only_my_events'
|
||||
author = false
|
||||
files.each do |file|
|
||||
if file.involved?(notify_user) || file.assigned?(notify_user)
|
||||
author = true
|
||||
break
|
||||
end
|
||||
end
|
||||
author
|
||||
when 'only_owner'
|
||||
owner = false
|
||||
files.each do |file|
|
||||
if file.owner?(notify_user)
|
||||
owner = true
|
||||
break
|
||||
end
|
||||
end
|
||||
owner
|
||||
when 'only_assigned'
|
||||
assignee = false
|
||||
files.each do |file|
|
||||
if file.assigned?(notify_user)
|
||||
assignee = true
|
||||
break
|
||||
end
|
||||
end
|
||||
assignee
|
||||
else
|
||||
false
|
||||
end
|
||||
# Notifications
|
||||
if (force_notification && Setting.notified_events.include?('dmsf_workflow_plural')) ||
|
||||
(Setting.notified_events.include?('dmsf_legacy_notifications') && file&.notify?)
|
||||
notify_members = project.members.active.select do |notify_member|
|
||||
notify_user = notify_member.user
|
||||
if notify_user == User.current && notify_user.pref.no_self_notified
|
||||
false
|
||||
else
|
||||
notify_member.dmsf_mail_notification
|
||||
if notify_member.dmsf_mail_notification.nil?
|
||||
case notify_user.mail_notification
|
||||
when 'all'
|
||||
true
|
||||
when 'selected'
|
||||
notify_member.mail_notification?
|
||||
when 'only_my_events'
|
||||
file.involved?(notify_user) || file.assigned?(notify_user)
|
||||
when 'only_owner'
|
||||
file.owner? notify_user
|
||||
when 'only_assigned'
|
||||
file.assigned? notify_user
|
||||
else
|
||||
false
|
||||
end
|
||||
else
|
||||
notify_member.dmsf_mail_notification
|
||||
end
|
||||
end
|
||||
end
|
||||
users = notify_members.collect { |m| m.user }
|
||||
else
|
||||
users = []
|
||||
end
|
||||
|
||||
notify_members.collect { |m| m.user }.uniq
|
||||
# Watchers
|
||||
watchers = []
|
||||
file.get_all_watchers(watchers)
|
||||
users.concat watchers
|
||||
users.uniq
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -211,7 +211,7 @@ class DmsfWorkflow < ActiveRecord::Base
|
||||
assignments = next_assignments(revision.id)
|
||||
recipients = assignments.collect{ |a| a.user }
|
||||
recipients.uniq!
|
||||
recipients = recipients & DmsfMailer.get_notify_users(project, [revision.dmsf_file], true)
|
||||
recipients = recipients & DmsfMailer.get_notify_users(project, revision.dmsf_file, true)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
recipients,
|
||||
self,
|
||||
|
||||
@ -428,6 +428,7 @@ en:
|
||||
label_project_watchers: Watchers
|
||||
label_dmsf_folder_watchers: Watchers
|
||||
label_dmsf_file_watchers: Watchers
|
||||
dmsf_legacy_notifications: Legacy DMS notifications
|
||||
permission_view_dmsf_folder_watchers: View folder's watchers
|
||||
permission_add_dmsf_folder_watchers: Add folder's watchers
|
||||
permission_delete_dmsf_folder_watchers: Delete folder's watchers
|
||||
|
||||
@ -39,6 +39,7 @@ module RedmineDmsf
|
||||
def all
|
||||
notifications = super
|
||||
notifications << Redmine::Notifiable.new('dmsf_workflow_plural')
|
||||
notifications << Redmine::Notifiable.new('dmsf_legacy_notifications')
|
||||
notifications
|
||||
end
|
||||
|
||||
|
||||
@ -94,19 +94,19 @@ class DmsfMailerTest < RedmineDmsf::Test::UnitTest
|
||||
end
|
||||
|
||||
def test_get_notify_users
|
||||
users = DmsfMailer.get_notify_users(@project1, [@file1])
|
||||
users = DmsfMailer.get_notify_users(@project1, @file1)
|
||||
assert users.present?
|
||||
end
|
||||
|
||||
def test_get_notify_users_notification_switched_off
|
||||
@file1.notify_deactivate
|
||||
users = DmsfMailer.get_notify_users(@project1, [@file1])
|
||||
users = DmsfMailer.get_notify_users(@project1, @file1)
|
||||
assert users.blank?
|
||||
end
|
||||
|
||||
def test_get_notify_users_on_inactive_projects
|
||||
@project1.status = Project::STATUS_CLOSED
|
||||
users = DmsfMailer.get_notify_users(@project1, [@file1])
|
||||
users = DmsfMailer.get_notify_users(@project1, @file1)
|
||||
assert users.blank?
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user