#557 Approval workflow notifications controlled by global email notifications settings
This commit is contained in:
parent
a3a68edb98
commit
7938532c0e
@ -74,99 +74,110 @@ class DmsfWorkflowsController < ApplicationController
|
||||
end
|
||||
if revision.workflow == DmsfWorkflow::STATE_APPROVED
|
||||
# Just approved
|
||||
recipients = DmsfMailer.get_notify_users(@project, [revision.dmsf_file], true)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
recipients,
|
||||
@dmsf_workflow,
|
||||
revision,
|
||||
:text_email_subject_approved,
|
||||
:text_email_finished_approved,
|
||||
:text_email_to_see_history)
|
||||
if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients']
|
||||
unless recipients.blank?
|
||||
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)
|
||||
if Setting.notified_events.include?('dmsf_workflow_action')
|
||||
recipients = DmsfMailer.get_notify_users(@project, [revision.dmsf_file], true)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
recipients,
|
||||
@dmsf_workflow,
|
||||
revision,
|
||||
:text_email_subject_approved,
|
||||
:text_email_finished_approved,
|
||||
:text_email_to_see_history)
|
||||
if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients']
|
||||
unless recipients.blank?
|
||||
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
|
||||
# Just rejected
|
||||
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)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
recipients,
|
||||
@dmsf_workflow,
|
||||
revision,
|
||||
:text_email_subject_rejected,
|
||||
:text_email_finished_rejected,
|
||||
:text_email_to_see_history,
|
||||
action.note)
|
||||
if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients']
|
||||
unless recipients.blank?
|
||||
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)
|
||||
if Setting.notified_events.include?('dmsf_workflow_action')
|
||||
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)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
recipients,
|
||||
@dmsf_workflow,
|
||||
revision,
|
||||
:text_email_subject_rejected,
|
||||
:text_email_finished_rejected,
|
||||
:text_email_to_see_history,
|
||||
action.note)
|
||||
if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients']
|
||||
unless recipients.blank?
|
||||
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
|
||||
else
|
||||
if action.action == DmsfWorkflowStepAction::ACTION_DELEGATE
|
||||
# Delegation
|
||||
delegate = User.active.find_by(id: params[:step_action].to_i / 10)
|
||||
if DmsfMailer.get_notify_users(@project, [revision.dmsf_file], true).include?(delegate)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
[delegate],
|
||||
@dmsf_workflow,
|
||||
revision,
|
||||
:text_email_subject_delegated,
|
||||
:text_email_finished_delegated,
|
||||
:text_email_to_proceed,
|
||||
action.note,
|
||||
action.dmsf_workflow_step_assignment.dmsf_workflow_step)
|
||||
if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients']
|
||||
flash[:warning] = l(:warning_email_notifications, to: delegate.name)
|
||||
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)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
[delegate],
|
||||
@dmsf_workflow,
|
||||
revision,
|
||||
:text_email_subject_delegated,
|
||||
:text_email_finished_delegated,
|
||||
:text_email_to_proceed,
|
||||
action.note,
|
||||
action.dmsf_workflow_step_assignment.dmsf_workflow_step)
|
||||
if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients']
|
||||
flash[:warning] = l(:warning_email_notifications, to: delegate.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
# Next step
|
||||
assignments = @dmsf_workflow.next_assignments revision.id
|
||||
unless assignments.empty?
|
||||
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], true).include?(assignment.user)
|
||||
if Setting.notified_events.include?('dmsf_workflow_action')
|
||||
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],
|
||||
true).include?(assignment.user)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
[assignment.user],
|
||||
@dmsf_workflow,
|
||||
revision,
|
||||
:text_email_subject_requires_approval,
|
||||
:text_email_finished_step,
|
||||
:text_email_to_proceed,
|
||||
nil,
|
||||
assignment.dmsf_workflow_step)
|
||||
end
|
||||
end
|
||||
to = revision.dmsf_workflow_assigned_by_user
|
||||
if to && DmsfMailer.get_notify_users(@project, [revision.dmsf_file],
|
||||
true).include?(to)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
[assignment.user],
|
||||
[to],
|
||||
@dmsf_workflow,
|
||||
revision,
|
||||
:text_email_subject_requires_approval,
|
||||
:text_email_finished_step,
|
||||
:text_email_to_proceed,
|
||||
nil,
|
||||
assignment.dmsf_workflow_step)
|
||||
:text_email_subject_updated,
|
||||
:text_email_finished_step_short,
|
||||
:text_email_to_see_status)
|
||||
end
|
||||
end
|
||||
to = revision.dmsf_workflow_assigned_by_user
|
||||
if to && DmsfMailer.get_notify_users(@project, [revision.dmsf_file], true).include?(to)
|
||||
DmsfMailer.deliver_workflow_notification(
|
||||
[to],
|
||||
@dmsf_workflow,
|
||||
revision,
|
||||
:text_email_subject_updated,
|
||||
:text_email_finished_step_short,
|
||||
:text_email_to_see_status)
|
||||
end
|
||||
if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients']
|
||||
recipients = assignments.collect{ |a| a.user }
|
||||
recipients << to if to
|
||||
recipients.uniq!
|
||||
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(', ')
|
||||
to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.')
|
||||
flash[:warning] = l(:warning_email_notifications, to: to)
|
||||
if Setting.plugin_redmine_dmsf['dmsf_display_notified_recipients']
|
||||
recipients = assignments.collect{ |a| a.user }
|
||||
recipients << to if to
|
||||
recipients.uniq!
|
||||
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(', ')
|
||||
to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.')
|
||||
flash[:warning] = l(:warning_email_notifications, to: to)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -411,7 +422,9 @@ class DmsfWorkflowsController < ApplicationController
|
||||
if revision
|
||||
revision.set_workflow(@dmsf_workflow.id, params[:action])
|
||||
if revision.save
|
||||
@dmsf_workflow.notify_users(@project, revision, self)
|
||||
if Setting.notified_events.include?('dmsf_workflow_action')
|
||||
@dmsf_workflow.notify_users(@project, revision, self)
|
||||
end
|
||||
flash[:notice] = l(:notice_workflow_started)
|
||||
else
|
||||
flash[:error] = l(:notice_cannot_start_workflow)
|
||||
|
||||
@ -40,6 +40,7 @@ require 'redmine_dmsf/patches/user_patch'
|
||||
require 'redmine_dmsf/patches/issue_patch'
|
||||
require 'redmine_dmsf/patches/role_patch'
|
||||
require 'redmine_dmsf/patches/queries_controller_patch'
|
||||
require 'redmine_dmsf/patches/notifiable_patch'
|
||||
|
||||
if defined?(EasyExtensions)
|
||||
require 'redmine_dmsf/patches/easy_crm_case_patch'
|
||||
|
||||
52
lib/redmine_dmsf/patches/notifiable_patch.rb
Normal file
52
lib/redmine_dmsf/patches/notifiable_patch.rb
Normal file
@ -0,0 +1,52 @@
|
||||
# encoding: utf-8
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
# Redmine plugin for Document Management System "Features"
|
||||
#
|
||||
# Copyright © 2011-22 Karel Pičman <karel.picman@kontron.com>
|
||||
#
|
||||
# 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.
|
||||
|
||||
module RedmineDmsf
|
||||
module Patches
|
||||
module NotifiablePatch
|
||||
|
||||
def self.prepended(base)
|
||||
|
||||
class << base
|
||||
prepend ClassMethods
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
################################################################################################################
|
||||
# Overriden methods
|
||||
#
|
||||
def all
|
||||
notifications = super
|
||||
notifications << Redmine::Notifiable.new('dmsf_workflow_plural')
|
||||
notifications
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RedmineExtensions::PatchManager.register_patch_to_be_first 'Redmine::Notifiable',
|
||||
'RedmineDmsf::Patches::NotifiablePatch', prepend: true, first: true
|
||||
Loading…
x
Reference in New Issue
Block a user