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