diff --git a/app/models/concerns/mail_template_concern.rb b/app/models/concerns/mail_template_concern.rb index 387b515e2..107451969 100644 --- a/app/models/concerns/mail_template_concern.rb +++ b/app/models/concerns/mail_template_concern.rb @@ -13,8 +13,13 @@ module MailTemplateConcern module ClassMethods def default_for_procedure(procedure) - body = ActionController::Base.new.render_to_string(template: self.const_get(:TEMPLATE_NAME)) - self.new(subject: self.const_get(:DEFAULT_SUBJECT), body: body, procedure: procedure) + template_name = default_template_name_for_procedure(procedure) + body = ActionController::Base.new.render_to_string(template: template_name) + new(subject: const_get(:DEFAULT_SUBJECT), body: body, procedure: procedure) + end + + def default_template_name_for_procedure(procedure) + const_get(:DEFAULT_TEMPLATE_NAME) end end diff --git a/app/models/mails/closed_mail.rb b/app/models/mails/closed_mail.rb index be289584d..757593a3a 100644 --- a/app/models/mails/closed_mail.rb +++ b/app/models/mails/closed_mail.rb @@ -5,9 +5,17 @@ module Mails belongs_to :procedure SLUG = "closed_mail" - TEMPLATE_NAME = "mails/closed_mail" DISPLAYED_NAME = "Accusé d'acceptation" DEFAULT_SUBJECT = 'Votre dossier demarches-simplifiees.fr nº --numéro du dossier-- a été accepté' DOSSIER_STATE = 'accepte' + + def self.default_template_name_for_procedure(procedure) + attestation_template = procedure.attestation_template + if attestation_template.present? && attestation_template.activated? + "mails/closed_mail_with_attestation" + else + "mails/closed_mail" + end + end end end diff --git a/app/models/mails/initiated_mail.rb b/app/models/mails/initiated_mail.rb index 1cc4067ea..0bcac1da0 100644 --- a/app/models/mails/initiated_mail.rb +++ b/app/models/mails/initiated_mail.rb @@ -5,7 +5,7 @@ module Mails belongs_to :procedure SLUG = "initiated_mail" - TEMPLATE_NAME = "mails/initiated_mail" + DEFAULT_TEMPLATE_NAME = "mails/initiated_mail" DISPLAYED_NAME = 'Accusé de réception' DEFAULT_SUBJECT = 'Votre dossier demarches-simplifiees.fr nº --numéro du dossier-- a bien été reçu' DOSSIER_STATE = 'en_construction' diff --git a/app/models/mails/received_mail.rb b/app/models/mails/received_mail.rb index 6afda62b4..ca6163cbf 100644 --- a/app/models/mails/received_mail.rb +++ b/app/models/mails/received_mail.rb @@ -5,7 +5,7 @@ module Mails belongs_to :procedure SLUG = "received_mail" - TEMPLATE_NAME = "mails/received_mail" + DEFAULT_TEMPLATE_NAME = "mails/received_mail" DISPLAYED_NAME = 'Accusé de passage en instruction' DEFAULT_SUBJECT = 'Votre dossier demarches-simplifiees.fr nº --numéro du dossier-- va être instruit' DOSSIER_STATE = 'en_instruction' diff --git a/app/models/mails/refused_mail.rb b/app/models/mails/refused_mail.rb index f3446a4cc..aef42ee89 100644 --- a/app/models/mails/refused_mail.rb +++ b/app/models/mails/refused_mail.rb @@ -5,7 +5,7 @@ module Mails belongs_to :procedure SLUG = "refused_mail" - TEMPLATE_NAME = "mails/refused_mail" + DEFAULT_TEMPLATE_NAME = "mails/refused_mail" DISPLAYED_NAME = 'Accusé de rejet du dossier' DEFAULT_SUBJECT = 'Votre dossier demarches-simplifiees.fr nº --numéro du dossier-- a été refusé' DOSSIER_STATE = 'refuse' diff --git a/app/models/mails/without_continuation_mail.rb b/app/models/mails/without_continuation_mail.rb index 9d5e59de1..c7768d131 100644 --- a/app/models/mails/without_continuation_mail.rb +++ b/app/models/mails/without_continuation_mail.rb @@ -5,7 +5,7 @@ module Mails belongs_to :procedure SLUG = "without_continuation" - TEMPLATE_NAME = "mails/without_continuation_mail" + DEFAULT_TEMPLATE_NAME = "mails/without_continuation_mail" DISPLAYED_NAME = 'Accusé de classement sans suite' DEFAULT_SUBJECT = 'Votre dossier demarches-simplifiees.fr nº --numéro du dossier-- a été classé sans suite' DOSSIER_STATE = 'sans_suite' diff --git a/app/views/mails/closed_mail_with_attestation.html.haml b/app/views/mails/closed_mail_with_attestation.html.haml new file mode 100644 index 000000000..069fb6e77 --- /dev/null +++ b/app/views/mails/closed_mail_with_attestation.html.haml @@ -0,0 +1,22 @@ +Bonjour, +%br +%br +Votre dossier nº --numéro du dossier-- a été accepté le --date de décision--. +%br +%br +Vous pouvez télécharger votre attestation à l'adresse suivante : --lien attestation-- +%br +%br +A tout moment, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : --lien dossier-- +%br +%br +Bonne journée, +%br +%br +L'équipe demarches-simplifiees.fr (anciennement Téléprocédures Simplifiées) +%br +%br +— +%br +%br +Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 5dfb915b0..f513f0244 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -41,6 +41,32 @@ describe Procedure do end end + describe 'closed mail template body' do + let(:procedure) { create(:procedure) } + + subject { procedure.closed_mail_template.body } + + context 'for procedures without an attestation' do + it { is_expected.not_to include('lien attestation') } + end + + context 'for procedures with an attestation' do + before { create(:attestation_template, procedure: procedure, activated: activated) } + + context 'when the attestation is inactive' do + let(:activated) { false } + + it { is_expected.not_to include('lien attestation') } + end + + context 'when the attestation is inactive' do + let(:activated) { true } + + it { is_expected.to include('lien attestation') } + end + end + end + describe 'validation' do context 'libelle' do it { is_expected.not_to allow_value(nil).for(:libelle) }