2018-11-20 11:57:51 +01:00
|
|
|
# Preview all emails at http://localhost:3000/rails/mailers/dossier_mailer
|
2018-05-24 15:55:47 +02:00
|
|
|
class DossierMailer < ApplicationMailer
|
2019-07-17 14:12:57 +02:00
|
|
|
helper ServiceHelper
|
2019-07-17 16:42:34 +02:00
|
|
|
helper MailerHelper
|
2020-05-27 11:33:04 +02:00
|
|
|
helper ProcedureHelper
|
2019-07-17 14:12:57 +02:00
|
|
|
|
2018-05-24 15:55:47 +02:00
|
|
|
layout 'mailers/layout'
|
2021-09-01 18:52:01 +02:00
|
|
|
default from: NO_REPLY_EMAIL
|
2023-06-20 18:14:34 +02:00
|
|
|
after_action :prevent_perform_deliveries, only: [:notify_new_draft, :notify_new_answer, :notify_pending_correction]
|
2018-05-24 15:55:47 +02:00
|
|
|
|
2022-12-21 17:18:19 +01:00
|
|
|
def notify_new_draft
|
|
|
|
@dossier = params[:dossier]
|
|
|
|
I18n.with_locale(@dossier.user_locale) do
|
|
|
|
@service = @dossier.procedure.service
|
|
|
|
@logo_url = attach_logo(@dossier.procedure)
|
|
|
|
@subject = default_i18n_subject(libelle_demarche: @dossier.procedure.libelle)
|
2021-09-01 18:52:01 +02:00
|
|
|
|
2022-12-21 17:18:19 +01:00
|
|
|
mail(to: @dossier.user_email_for(:notification), subject: @subject) do |format|
|
2021-09-01 18:52:01 +02:00
|
|
|
format.html { render layout: 'mailers/notifications_layout' }
|
|
|
|
end
|
2019-07-17 14:41:37 +02:00
|
|
|
end
|
2018-11-20 11:50:25 +01:00
|
|
|
end
|
|
|
|
|
2021-11-16 15:12:05 +01:00
|
|
|
def notify_new_answer
|
2021-11-16 16:10:08 +01:00
|
|
|
commentaire = params[:commentaire]
|
|
|
|
dossier = commentaire.dossier
|
2021-09-01 18:52:01 +02:00
|
|
|
I18n.with_locale(dossier.user_locale) do
|
|
|
|
@dossier = dossier
|
|
|
|
@service = dossier.procedure.service
|
|
|
|
@logo_url = attach_logo(dossier.procedure)
|
2021-11-16 15:12:05 +01:00
|
|
|
@body = commentaire.body
|
2021-09-01 18:52:01 +02:00
|
|
|
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
|
|
|
|
|
|
|
|
mail(to: dossier.user_email_for(:notification), subject: @subject) do |format|
|
|
|
|
format.html { render layout: 'mailers/notifications_layout' }
|
|
|
|
end
|
2018-11-20 12:07:39 +01:00
|
|
|
end
|
2018-11-20 11:50:25 +01:00
|
|
|
end
|
|
|
|
|
2020-04-01 16:23:03 +02:00
|
|
|
def notify_new_commentaire_to_instructeur(dossier, instructeur_email)
|
2021-09-01 18:52:01 +02:00
|
|
|
I18n.with_locale(dossier.user_locale) do
|
|
|
|
@dossier = dossier
|
|
|
|
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
|
|
|
|
|
|
|
|
mail(to: instructeur_email, subject: @subject)
|
|
|
|
end
|
2020-04-01 16:23:03 +02:00
|
|
|
end
|
|
|
|
|
2023-06-20 18:14:34 +02:00
|
|
|
def notify_pending_correction
|
|
|
|
commentaire = params[:commentaire]
|
|
|
|
dossier = commentaire.dossier
|
2023-03-14 18:48:19 +01:00
|
|
|
I18n.with_locale(dossier.user_locale) do
|
|
|
|
@dossier = dossier
|
|
|
|
@service = dossier.procedure.service
|
|
|
|
@logo_url = attach_logo(dossier.procedure)
|
|
|
|
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
|
|
|
|
|
|
|
|
mail(to: dossier.user_email_for(:notification), subject: @subject) do |format|
|
|
|
|
format.html { render layout: 'mailers/notifications_layout' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-30 21:41:36 +02:00
|
|
|
def notify_new_avis_to_instructeur(avis, instructeur_email)
|
|
|
|
I18n.with_locale(avis.dossier.user_locale) do
|
|
|
|
@avis = avis
|
|
|
|
@subject = default_i18n_subject(dossier_id: avis.dossier.id, libelle_demarche: avis.procedure.libelle)
|
|
|
|
|
|
|
|
mail(to: instructeur_email, subject: @subject)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-09 09:22:37 +02:00
|
|
|
def notify_new_dossier_depose_to_instructeur(dossier, instructeur_email)
|
2021-09-01 18:52:01 +02:00
|
|
|
I18n.with_locale(dossier.user_locale) do
|
|
|
|
@dossier = dossier
|
|
|
|
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
|
|
|
|
|
|
|
|
mail(to: instructeur_email, subject: @subject)
|
|
|
|
end
|
2020-04-09 09:22:37 +02:00
|
|
|
end
|
|
|
|
|
2019-03-25 16:04:33 +01:00
|
|
|
def notify_revert_to_instruction(dossier)
|
2021-09-01 18:52:01 +02:00
|
|
|
I18n.with_locale(dossier.user_locale) do
|
|
|
|
@dossier = dossier
|
|
|
|
@service = dossier.procedure.service
|
|
|
|
@logo_url = attach_logo(dossier.procedure)
|
|
|
|
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
|
|
|
|
|
|
|
|
mail(to: dossier.user_email_for(:notification), subject: @subject) do |format|
|
|
|
|
format.html { render layout: 'mailers/notifications_layout' }
|
|
|
|
end
|
2019-09-10 11:05:04 +02:00
|
|
|
end
|
2019-03-25 16:04:33 +01:00
|
|
|
end
|
2019-12-03 10:31:10 +01:00
|
|
|
|
2020-03-19 09:49:25 +01:00
|
|
|
def notify_brouillon_near_deletion(dossiers, to_email)
|
2021-09-01 18:52:01 +02:00
|
|
|
I18n.with_locale(dossiers.first.user_locale) do
|
2021-09-07 15:33:25 +02:00
|
|
|
@subject = default_i18n_subject(count: dossiers.size)
|
2021-09-01 18:52:01 +02:00
|
|
|
@dossiers = dossiers
|
2019-12-03 15:51:16 +01:00
|
|
|
|
2021-09-01 18:52:01 +02:00
|
|
|
mail(to: to_email, subject: @subject)
|
|
|
|
end
|
2019-12-03 10:31:10 +01:00
|
|
|
end
|
2019-12-03 10:46:44 +01:00
|
|
|
|
2020-03-19 09:49:25 +01:00
|
|
|
def notify_brouillon_deletion(dossier_hashes, to_email)
|
2021-09-07 15:33:25 +02:00
|
|
|
@subject = default_i18n_subject(count: dossier_hashes.size)
|
2019-11-28 18:03:23 +01:00
|
|
|
@dossier_hashes = dossier_hashes
|
|
|
|
|
2020-03-19 09:49:25 +01:00
|
|
|
mail(to: to_email, subject: @subject)
|
2019-12-03 10:46:44 +01:00
|
|
|
end
|
2020-02-18 17:15:32 +01:00
|
|
|
|
2022-01-19 14:34:28 +01:00
|
|
|
def notify_en_construction_deletion_to_administration(dossier, to_email)
|
|
|
|
@subject = default_i18n_subject(dossier_id: dossier.id)
|
|
|
|
@dossier = dossier
|
2020-02-18 17:15:32 +01:00
|
|
|
|
2022-01-19 14:34:28 +01:00
|
|
|
mail(to: to_email, subject: @subject)
|
2020-11-17 13:25:35 +01:00
|
|
|
end
|
|
|
|
|
2020-03-19 09:49:25 +01:00
|
|
|
def notify_deletion_to_administration(deleted_dossier, to_email)
|
|
|
|
@subject = default_i18n_subject(dossier_id: deleted_dossier.dossier_id)
|
|
|
|
@deleted_dossier = deleted_dossier
|
|
|
|
|
|
|
|
mail(to: to_email, subject: @subject)
|
|
|
|
end
|
|
|
|
|
|
|
|
def notify_automatic_deletion_to_user(deleted_dossiers, to_email)
|
2021-09-01 18:52:01 +02:00
|
|
|
I18n.with_locale(deleted_dossiers.first.user_locale) do
|
|
|
|
@state = deleted_dossiers.first.state
|
2021-09-07 15:33:25 +02:00
|
|
|
@subject = default_i18n_subject(count: deleted_dossiers.size)
|
2021-09-01 18:52:01 +02:00
|
|
|
@deleted_dossiers = deleted_dossiers
|
2020-03-19 09:49:25 +01:00
|
|
|
|
2021-09-01 18:52:01 +02:00
|
|
|
mail(to: to_email, subject: @subject)
|
|
|
|
end
|
2020-03-19 09:49:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def notify_automatic_deletion_to_administration(deleted_dossiers, to_email)
|
2021-09-07 15:33:25 +02:00
|
|
|
@subject = default_i18n_subject(count: deleted_dossiers.size)
|
2020-03-19 09:49:25 +01:00
|
|
|
@deleted_dossiers = deleted_dossiers
|
|
|
|
|
|
|
|
mail(to: to_email, subject: @subject)
|
|
|
|
end
|
|
|
|
|
2020-04-01 17:08:50 +02:00
|
|
|
def notify_near_deletion_to_user(dossiers, to_email)
|
2021-09-01 18:52:01 +02:00
|
|
|
I18n.with_locale(dossiers.first.user_locale) do
|
|
|
|
@state = dossiers.first.state
|
2021-09-07 15:33:25 +02:00
|
|
|
@subject = default_i18n_subject(count: dossiers.size, state: @state)
|
2021-09-01 18:52:01 +02:00
|
|
|
@dossiers = dossiers
|
2020-02-18 17:18:06 +01:00
|
|
|
|
2021-09-01 18:52:01 +02:00
|
|
|
mail(to: to_email, subject: @subject)
|
|
|
|
end
|
2020-02-18 17:18:06 +01:00
|
|
|
end
|
2020-02-18 17:18:14 +01:00
|
|
|
|
2020-04-01 17:08:50 +02:00
|
|
|
def notify_near_deletion_to_administration(dossiers, to_email)
|
|
|
|
@state = dossiers.first.state
|
2021-09-07 15:33:25 +02:00
|
|
|
@subject = default_i18n_subject(count: dossiers.size, state: @state)
|
2020-02-18 17:18:14 +01:00
|
|
|
@dossiers = dossiers
|
|
|
|
|
2020-03-19 09:49:25 +01:00
|
|
|
mail(to: to_email, subject: @subject)
|
2020-02-18 17:18:14 +01:00
|
|
|
end
|
2020-02-25 18:16:21 +01:00
|
|
|
|
|
|
|
def notify_groupe_instructeur_changed(instructeur, dossier)
|
2021-09-01 18:52:01 +02:00
|
|
|
@subject = default_i18n_subject(dossier_id: dossier.id)
|
|
|
|
@dossier = dossier
|
2020-02-25 18:16:21 +01:00
|
|
|
|
2021-09-01 18:52:01 +02:00
|
|
|
mail(to: instructeur.email, subject: @subject)
|
2020-02-25 18:16:21 +01:00
|
|
|
end
|
2020-02-05 22:10:22 +01:00
|
|
|
|
2020-03-19 03:46:12 +01:00
|
|
|
def notify_brouillon_not_submitted(dossier)
|
2021-09-01 18:52:01 +02:00
|
|
|
I18n.with_locale(dossier.user_locale) do
|
|
|
|
@subject = default_i18n_subject(dossier_id: dossier.id)
|
|
|
|
@dossier = dossier
|
2020-02-05 22:10:22 +01:00
|
|
|
|
2021-09-01 18:52:01 +02:00
|
|
|
mail(to: dossier.user_email_for(:notification), subject: @subject)
|
|
|
|
end
|
2020-02-05 22:10:22 +01:00
|
|
|
end
|
2020-04-01 17:08:50 +02:00
|
|
|
|
2021-09-07 10:36:09 +02:00
|
|
|
def notify_transfer(transfer)
|
|
|
|
I18n.with_locale(transfer.user_locale) do
|
2021-09-07 15:33:25 +02:00
|
|
|
@subject = default_i18n_subject(count: transfer.dossiers.size)
|
2021-09-07 10:36:09 +02:00
|
|
|
@transfer = transfer
|
|
|
|
|
|
|
|
mail(to: transfer.email, subject: @subject)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-01 17:08:50 +02:00
|
|
|
protected
|
|
|
|
|
2021-11-16 15:12:05 +01:00
|
|
|
def prevent_perform_deliveries
|
2023-06-20 18:14:34 +02:00
|
|
|
commentaire = params[:commentaire]
|
|
|
|
dossier = commentaire&.dossier || params[:dossier]
|
|
|
|
|
|
|
|
if commentaire&.discarded? || dossier&.skip_user_notification_email?
|
2022-12-21 17:18:19 +01:00
|
|
|
mail.perform_deliveries = false
|
|
|
|
end
|
2021-11-16 15:12:05 +01:00
|
|
|
end
|
|
|
|
|
2020-04-01 17:08:50 +02:00
|
|
|
# This is an override of `default_i18n_subject` method
|
|
|
|
# https://api.rubyonrails.org/v5.0.0/classes/ActionMailer/Base.html#method-i-default_i18n_subject
|
2021-09-16 21:20:28 +02:00
|
|
|
#
|
|
|
|
# i18n-tasks-use t("dossier_mailer.#{action}.subject")
|
2020-04-01 17:08:50 +02:00
|
|
|
def default_i18n_subject(interpolations = {})
|
|
|
|
if interpolations[:state]
|
|
|
|
mailer_scope = self.class.mailer_name.tr('/', '.')
|
2020-04-02 15:05:16 +02:00
|
|
|
state = interpolations[:state].in?(Dossier::TERMINE) ? 'termine' : interpolations[:state]
|
2021-02-04 13:03:04 +01:00
|
|
|
I18n.t("subject_#{state}", **interpolations.merge(scope: [mailer_scope, action_name]))
|
2020-04-01 17:08:50 +02:00
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
2018-05-24 15:55:47 +02:00
|
|
|
end
|