demarches-normaliennes/app/mailers/dossier_mailer.rb

159 lines
5.2 KiB
Ruby
Raw Normal View History

# Preview all emails at http://localhost:3000/rails/mailers/dossier_mailer
class DossierMailer < ApplicationMailer
helper ServiceHelper
helper MailerHelper
helper ProcedureHelper
layout 'mailers/layout'
def notify_new_draft(dossier)
@dossier = dossier
@service = dossier.procedure.service
@logo_url = attach_logo(dossier.procedure)
2019-07-17 13:42:14 +02:00
subject = "Retrouvez votre brouillon pour la démarche « #{dossier.procedure.libelle} »"
mail(from: NO_REPLY_EMAIL, to: dossier.user.email, subject: subject) do |format|
format.html { render layout: 'mailers/notifications_layout' }
end
end
def notify_new_answer(dossier)
@dossier = dossier
@service = dossier.procedure.service
@logo_url = attach_logo(dossier.procedure)
subject = "Nouveau message pour votre dossier nº #{dossier.id} (#{dossier.procedure.libelle})"
mail(from: NO_REPLY_EMAIL, to: dossier.user.email, subject: subject) do |format|
format.html { render layout: 'mailers/notifications_layout' }
end
end
def notify_new_commentaire_to_instructeur(dossier, instructeur_email)
@dossier = dossier
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
mail(from: NO_REPLY_EMAIL, to: instructeur_email, subject: @subject)
end
def notify_new_dossier_depose_to_instructeur(dossier, instructeur_email)
@dossier = dossier
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
mail(from: NO_REPLY_EMAIL, to: instructeur_email, subject: @subject)
end
def notify_revert_to_instruction(dossier)
@dossier = dossier
@service = dossier.procedure.service
@logo_url = attach_logo(dossier.procedure)
subject = "Votre dossier nº #{@dossier.id} est en train d'être réexaminé"
mail(from: NO_REPLY_EMAIL, to: dossier.user.email, subject: subject) do |format|
format.html { render layout: 'mailers/notifications_layout' }
end
end
2020-03-19 09:49:25 +01:00
def notify_brouillon_near_deletion(dossiers, to_email)
2019-12-03 15:51:16 +01:00
@subject = default_i18n_subject(count: dossiers.count)
@dossiers = dossiers
2020-03-19 09:49:25 +01:00
mail(to: to_email, subject: @subject)
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)
2019-11-28 18:03:23 +01:00
@subject = default_i18n_subject(count: dossier_hashes.count)
@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-03-19 09:49:25 +01:00
def notify_deletion_to_user(deleted_dossier, to_email)
@subject = default_i18n_subject(dossier_id: deleted_dossier.dossier_id)
@deleted_dossier = deleted_dossier
2020-03-19 09:49:25 +01:00
mail(to: to_email, subject: @subject)
end
def notify_instructeur_deletion_to_user(deleted_dossier, to_email)
2020-12-07 15:10:26 +01:00
@subject = default_i18n_subject(libelle_demarche: deleted_dossier.procedure.libelle)
@deleted_dossier = deleted_dossier
mail(to: to_email, subject: @subject)
end
def notify_instructeur(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
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)
2020-04-01 17:08:50 +02:00
@state = deleted_dossiers.first.state
2020-03-19 09:49:25 +01:00
@subject = default_i18n_subject(count: deleted_dossiers.count)
@deleted_dossiers = deleted_dossiers
mail(to: to_email, subject: @subject)
end
def notify_automatic_deletion_to_administration(deleted_dossiers, to_email)
@subject = default_i18n_subject(count: deleted_dossiers.count)
@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)
@state = dossiers.first.state
@subject = default_i18n_subject(count: dossiers.count, state: @state)
2020-03-19 09:49:25 +01:00
@dossiers = dossiers
2020-03-19 09:49:25 +01:00
mail(to: to_email, subject: @subject)
end
2020-04-01 17:08:50 +02:00
def notify_near_deletion_to_administration(dossiers, to_email)
@state = dossiers.first.state
@subject = default_i18n_subject(count: dossiers.count, state: @state)
@dossiers = dossiers
2020-03-19 09:49:25 +01:00
mail(to: to_email, subject: @subject)
end
def notify_groupe_instructeur_changed(instructeur, dossier)
@subject = "Un dossier a changé de groupe instructeur"
@dossier_id = dossier.id
@demarche = dossier.procedure.libelle
mail(from: NO_REPLY_EMAIL, to: instructeur.email, subject: @subject)
end
2020-03-19 03:46:12 +01:00
def notify_brouillon_not_submitted(dossier)
@subject = "Attention : votre dossier n'est pas déposé."
@dossier = dossier
mail(to: dossier.user.email, subject: @subject)
end
2020-04-01 17:08:50 +02:00
protected
# 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
def default_i18n_subject(interpolations = {})
if interpolations[:state]
mailer_scope = self.class.mailer_name.tr('/', '.')
state = interpolations[:state].in?(Dossier::TERMINE) ? 'termine' : interpolations[:state]
I18n.t("subject_#{state}", **interpolations.merge(scope: [mailer_scope, action_name]))
2020-04-01 17:08:50 +02:00
else
super
end
end
end