From 6391f7ff9ce271d7ff05707b33cf086c5a492f0f Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 3 Dec 2019 15:51:16 +0100 Subject: [PATCH] Work on notify_near_deletion mailer --- app/mailers/dossier_mailer.rb | 4 ++++ .../notify_brouillon_near_deletion.html.haml | 16 ++++++++++++++++ .../notify_brouillon_near_deletion/fr.yml | 12 ++++++++++++ spec/mailers/dossier_mailer_spec.rb | 14 ++++++++++++++ spec/mailers/previews/dossier_mailer_preview.rb | 7 +++++++ 5 files changed, 53 insertions(+) create mode 100644 app/views/dossier_mailer/notify_brouillon_near_deletion.html.haml create mode 100644 config/locales/views/dossier_mailer/notify_brouillon_near_deletion/fr.yml diff --git a/app/mailers/dossier_mailer.rb b/app/mailers/dossier_mailer.rb index 4e8362622..2dfeff363 100644 --- a/app/mailers/dossier_mailer.rb +++ b/app/mailers/dossier_mailer.rb @@ -71,5 +71,9 @@ class DossierMailer < ApplicationMailer end def notify_brouillon_near_deletion(user, dossiers) + @subject = default_i18n_subject(count: dossiers.count) + @dossiers = dossiers + + mail(to: user.email, subject: @subject) end end diff --git a/app/views/dossier_mailer/notify_brouillon_near_deletion.html.haml b/app/views/dossier_mailer/notify_brouillon_near_deletion.html.haml new file mode 100644 index 000000000..fc972ddd0 --- /dev/null +++ b/app/views/dossier_mailer/notify_brouillon_near_deletion.html.haml @@ -0,0 +1,16 @@ +- content_for(:title, "#{@subject}") + +%p + Bonjour, + +%p + Afin de limiter la conservation de vos données personnelles, + = t('.automatic_dossier_deletion', count: @dossiers.count) + %ul + - @dossiers.each do |d| + %li= link_to("n° #{d.id} (#{d.procedure.libelle})", dossier_url(d)) + +%p + #{sanitize(t('.send_your_draft', count: @dossiers.count))}. Et sinon, vous n'avez rien à faire. + += render partial: "layouts/mailers/signature" diff --git a/config/locales/views/dossier_mailer/notify_brouillon_near_deletion/fr.yml b/config/locales/views/dossier_mailer/notify_brouillon_near_deletion/fr.yml new file mode 100644 index 000000000..a3cbf01dc --- /dev/null +++ b/config/locales/views/dossier_mailer/notify_brouillon_near_deletion/fr.yml @@ -0,0 +1,12 @@ +fr: + dossier_mailer: + notify_brouillon_near_deletion: + subject: + one: Un dossier en brouillon va bientôt être supprimé + other: Des dossiers en brouillon vont bientôt être supprimés + automatic_dossier_deletion: + one: "le dossier en brouillon suivant sera bientôt automatiquement supprimé :" + other: "les dossiers en brouillon suivant seront bientôt automatiquement supprimés :" + send_your_draft: + one: "Si vous souhaitez toujours déposer ce dossier, vous pouvez retrouver votre brouillon pendant encore un mois" + other: "Si vous souhaitez toujours déposer ces dossiers, vous pouvez retrouver vos brouillons pendant encore un mois" diff --git a/spec/mailers/dossier_mailer_spec.rb b/spec/mailers/dossier_mailer_spec.rb index d8c1b07f4..98baa357c 100644 --- a/spec/mailers/dossier_mailer_spec.rb +++ b/spec/mailers/dossier_mailer_spec.rb @@ -83,4 +83,18 @@ RSpec.describe DossierMailer, type: :mailer do it_behaves_like 'a dossier notification' end + + describe '.notify_brouillon_near_deletion' do + let(:dossier) { create(:dossier) } + + before do + duree = dossier.procedure.duree_conservation_dossiers_dans_ds + @date_suppression = dossier.created_at + duree.months + end + + subject { described_class.notify_brouillon_near_deletion(dossier.user, [dossier]) } + + it { expect(subject.body).to include("n° #{dossier.id} ") } + it { expect(subject.body).to include(dossier.procedure.libelle) } + end end diff --git a/spec/mailers/previews/dossier_mailer_preview.rb b/spec/mailers/previews/dossier_mailer_preview.rb index 8ac4eab87..6a6ec731a 100644 --- a/spec/mailers/previews/dossier_mailer_preview.rb +++ b/spec/mailers/previews/dossier_mailer_preview.rb @@ -20,6 +20,13 @@ class DossierMailerPreview < ActionMailer::Preview DossierMailer.notify_revert_to_instruction(dossier) end + def notify_brouillon_near_deletion + DossierMailer.notify_brouillon_near_deletion(User.new(email: "usager@example.com"), [dossier]) + end + + def notify_brouillons_near_deletion + DossierMailer.notify_brouillon_near_deletion(User.new(email: "usager@example.com"), [dossier, dossier]) + end private def deleted_dossier