Permet de configurer le mail de réexamen du dossier par l'administrateur

This commit is contained in:
Kara Diaby 2023-11-08 13:41:22 +00:00
parent f692a9e5e4
commit fa874a0ea3
17 changed files with 81 additions and 65 deletions

View file

@ -1,5 +1,5 @@
class Procedure::Card::EmailsComponent < ApplicationComponent
CUSTOMIZABLE_COUNT = 5
CUSTOMIZABLE_COUNT = 6
def initialize(procedure:)
@procedure = procedure
@ -31,7 +31,8 @@ class Procedure::Card::EmailsComponent < ApplicationComponent
@procedure.received_mail,
@procedure.closed_mail,
@procedure.refused_mail,
@procedure.without_continuation_mail
@procedure.without_continuation_mail,
@procedure.re_instructed_mail
].map { |mail| mail&.updated_at }.compact.size
end
end

View file

@ -25,7 +25,7 @@ class Procedure::PublicationWarningComponent < ApplicationComponent
champs_admin_procedure_path(@procedure)
when :attestation_template
edit_admin_procedure_attestation_template_path(@procedure)
when :initiated_mail, :received_mail, :closed_mail, :refused_mail, :without_continuation_mail
when :initiated_mail, :received_mail, :closed_mail, :refused_mail, :without_continuation_mail, :re_instructed_mail
admin_procedure_mail_templates_path(@procedure)
end
end

View file

@ -58,7 +58,8 @@ module Administrateurs
procedure.received_mail_template,
procedure.closed_mail_template,
procedure.refused_mail_template,
procedure.without_continuation_mail_template
procedure.without_continuation_mail_template,
procedure.re_instructed_mail_template
]
end

View file

@ -116,7 +116,8 @@ module Administrateurs
received_mail: [],
closed_mail: [],
refused_mail: [],
without_continuation_mail: []
without_continuation_mail: [],
re_instructed_mail: []
)
.find(params[:id])

View file

@ -38,6 +38,7 @@ class ProcedureDashboard < Administrate::BaseDashboard
closed_mail_template: MailTemplateField,
refused_mail_template: MailTemplateField,
without_continuation_mail_template: MailTemplateField,
re_instructed_mail_template: MailTemplateField,
attestation_template: AttestationTemplateField,
procedure_expires_when_termine_enabled: Field::Boolean,
duree_conservation_dossiers_dans_ds: Field::Number,
@ -97,6 +98,7 @@ class ProcedureDashboard < Administrate::BaseDashboard
:closed_mail_template,
:refused_mail_template,
:without_continuation_mail_template,
:re_instructed_mail_template,
:attestation_template,
:procedure_expires_when_termine_enabled,
:duree_conservation_dossiers_dans_ds,

View file

@ -81,21 +81,6 @@ class DossierMailer < ApplicationMailer
end
end
def notify_revert_to_instruction(dossier)
I18n.with_locale(dossier.user_locale) do
@dossier = dossier
@service = dossier.procedure.service
@logo_url = procedure_logo_url(@dossier.procedure)
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
MailTemplatePresenterService.create_commentaire_for_state(dossier)
mail(to: dossier.user_email_for(:notification), subject: @subject) do |format|
format.html { render layout: 'mailers/notifications_layout' }
end
end
end
def notify_brouillon_near_deletion(dossiers, to_email)
I18n.with_locale(dossiers.first.user_locale) do
@subject = default_i18n_subject(count: dossiers.size)

View file

@ -44,6 +44,10 @@ class NotificationMailer < ApplicationMailer
with(dossier: dossier, state: Dossier.states.fetch(:sans_suite)).send_notification
end
def self.send_repasser_en_instruction_notification(dossier)
with(dossier: dossier, state: Dossier.states.fetch(:en_instruction)).send_notification
end
def self.send_pending_correction(dossier)
with(dossier: dossier).send_notification
end

View file

@ -876,7 +876,7 @@ class Dossier < ApplicationRecord
end
def mail_template_for_state
procedure.mail_template_for(state)
procedure.mail_template_for(self)
end
def after_passer_en_construction
@ -978,12 +978,14 @@ class Dossier < ApplicationRecord
self.sva_svr_decision_on = nil
self.motivation = nil
self.justificatif_motivation.purge_later
self.re_instructed_at = Time.zone.now
save!
rebase_later
MailTemplatePresenterService.create_commentaire_for_state(self)
if !disable_notification
# pourquoi pas de commentaire automatique ici ?
DossierMailer.notify_revert_to_instruction(self).deliver_later
NotificationMailer.send_repasser_en_instruction_notification(self).deliver_later
end
log_dossier_operation(instructeur, :repasser_en_instruction)
end

View file

@ -0,0 +1,27 @@
# == Schema Information
#
# Table name: re_instructed_mails
#
# id :integer not null, primary key
# body :text
# subject :string
# created_at :datetime not null
# updated_at :datetime not null
# procedure_id :integer
#
module Mails
class ReInstructedMail < ApplicationRecord
include MailTemplateConcern
belongs_to :procedure, optional: false
validates :subject, tags: true
validates :body, tags: true
SLUG = "re_instructed_mail"
DEFAULT_TEMPLATE_NAME = "notification_mailer/default_templates/re_instructed_mail"
DISPLAYED_NAME = I18n.t('activerecord.models.mail.re_instructed_mail.under_re_instruction')
DEFAULT_SUBJECT = I18n.t('activerecord.models.mail.re_instructed_mail.default_subject', dossier_number: '--numéro du dossier--', procedure_libelle: '--libellé démarche--')
DOSSIER_STATE = Dossier.states.fetch(:en_instruction)
end
end

View file

@ -156,6 +156,7 @@ class Procedure < ApplicationRecord
has_one :closed_mail, class_name: "Mails::ClosedMail", dependent: :destroy
has_one :refused_mail, class_name: "Mails::RefusedMail", dependent: :destroy
has_one :without_continuation_mail, class_name: "Mails::WithoutContinuationMail", dependent: :destroy
has_one :re_instructed_mail, class_name: "Mails::ReInstructedMail", dependent: :destroy
belongs_to :defaut_groupe_instructeur, class_name: 'GroupeInstructeur', inverse_of: false, optional: true
@ -272,6 +273,7 @@ class Procedure < ApplicationRecord
validates_associated :closed_mail, on: :publication
validates_associated :refused_mail, on: :publication
validates_associated :without_continuation_mail, on: :publication
validates_associated :re_instructed_mail, on: :publication
validates_associated :attestation_template, on: :publication, if: -> { attestation_template&.activated? }
FILE_MAX_SIZE = 20.megabytes
@ -506,6 +508,7 @@ class Procedure < ApplicationRecord
procedure.closed_mail = closed_mail&.dup
procedure.refused_mail = refused_mail&.dup
procedure.without_continuation_mail = without_continuation_mail&.dup
procedure.re_instructed_mail = re_instructed_mail&.dup
procedure.ask_birthday = false # see issue #4242
procedure.cloned_from_library = from_library
@ -582,12 +585,16 @@ class Procedure < ApplicationRecord
without_continuation_mail || Mails::WithoutContinuationMail.default_for_procedure(self)
end
def mail_template_for(state)
case state
def re_instructed_mail_template
re_instructed_mail || Mails::ReInstructedMail.default_for_procedure(self)
end
def mail_template_for(dossier)
case dossier.state
when Dossier.states.fetch(:en_construction)
initiated_mail_template
when Dossier.states.fetch(:en_instruction)
received_mail_template
dossier.re_instructed_at.present? ? re_instructed_mail_template : received_mail_template
when Dossier.states.fetch(:accepte)
closed_mail_template
when Dossier.states.fetch(:refuse)

View file

@ -1,17 +0,0 @@
- content_for :procedure_logo do
= render 'layouts/mailers/logo', url: @logo_url
%p= t(:hello, scope: [:views, :shared, :greetings])
%p
= t('.body_html', dossier_id: @dossier.id, libelle_demarche: @dossier.procedure.libelle)
= link_to dossier_url(@dossier), dossier_url(@dossier), target: '_blank', rel: 'noopener'
- if @dossier.procedure.service.present?
%p
= t('.contact')
= mail_to @dossier.procedure.service.email, @dossier.procedure.service.email
= render 'layouts/mailers/signature'
- content_for :footer do
= render 'layouts/mailers/service_footer', service: @service, dossier: @dossier

View file

@ -0,0 +1,11 @@
%p
Bonjour,
%p
Votre dossier nº --numéro du dossier--
va être réexaminé, la précédente décision sur ce dossier est caduque.
Vous pouvez retrouver le dossier que vous avez créé pour la démarche --libellé démarche-- à ladresse suivante : --lien dossier--
Pour obtenir le détail de cette modification de la décision, vous pouvez contacter le service : --nom du service--.
= render partial: "notification_mailer/default_templates/signature"

View file

@ -0,0 +1,7 @@
en:
activerecord:
models:
mail:
re_instructed_mail:
default_subject: Your file nº %{dossier_number} will be examined (%{procedure_libelle})
under_re_instruction: Acknowledgment of being under instruction

View file

@ -0,0 +1,7 @@
fr:
activerecord:
models:
mail:
re_instructed_mail:
default_subject: Votre dossier nº %{dossier_number} est en train d'être réexaminé (%{procedure_libelle})
under_re_instruction: Réexamen du dossier

View file

@ -1,9 +0,0 @@
en:
dossier_mailer:
notify_revert_to_instruction:
subject: Your file nº %{dossier_id} « %{libelle_demarche} » will be reexamined
body_html: |
Your file nº %{dossier_id} will be reexamined. All previous decisions are void.
To see the file created on procedure <b>« %{libelle_demarche} »</b>, select the following link:
contact: |
In order to get more details about the decision to reexamin, please contact the following service:

View file

@ -1,9 +0,0 @@
fr:
dossier_mailer:
notify_revert_to_instruction:
subject: Votre dossier nº %{dossier_id} sur la démarche « %{libelle_demarche} » est en train dêtre réexaminé
body_html: |
Votre dossier nº %{dossier_id} va être réexaminé, la précédente décision sur ce dossier est caduque.
Vous pouvez retrouver le dossier que vous avez créé pour la démarche <b>« %{libelle_demarche} »</b> à ladresse suivante :
contact: |
Pour obtenir le détail de cette modification de la décision, vous pouvez contacter par email :

View file

@ -18,10 +18,6 @@ class DossierMailerPreview < ActionMailer::Preview
DossierMailer.with(commentaire:).notify_pending_correction
end
def notify_revert_to_instruction
DossierMailer.notify_revert_to_instruction(dossier)
end
def notify_brouillon_near_deletion
DossierMailer.notify_brouillon_near_deletion([dossier], usager_email)
end