From 4e116f06a6504ded258af327f7cea3885db98e6e Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 18 Feb 2020 17:15:32 +0100 Subject: [PATCH] Add notify_automatic_deletion_to_user mailer --- app/mailers/dossier_mailer.rb | 7 +++++++ .../notify_automatic_deletion_to_user.html.haml | 14 ++++++++++++++ .../notify_automatic_deletion_to_user/fr.yml | 12 ++++++++++++ spec/mailers/dossier_mailer_spec.rb | 16 ++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 app/views/dossier_mailer/notify_automatic_deletion_to_user.html.haml create mode 100644 config/locales/views/dossier_mailer/notify_automatic_deletion_to_user/fr.yml diff --git a/app/mailers/dossier_mailer.rb b/app/mailers/dossier_mailer.rb index 8813730fe..5a8fbb00e 100644 --- a/app/mailers/dossier_mailer.rb +++ b/app/mailers/dossier_mailer.rb @@ -83,4 +83,11 @@ class DossierMailer < ApplicationMailer mail(to: user.email, subject: @subject) end + + def notify_automatic_deletion_to_user(user, dossier_hashes) + @subject = default_i18n_subject(count: dossier_hashes.count) + @dossier_hashes = dossier_hashes + + mail(to: user.email, subject: @subject) + end end diff --git a/app/views/dossier_mailer/notify_automatic_deletion_to_user.html.haml b/app/views/dossier_mailer/notify_automatic_deletion_to_user.html.haml new file mode 100644 index 000000000..337151682 --- /dev/null +++ b/app/views/dossier_mailer/notify_automatic_deletion_to_user.html.haml @@ -0,0 +1,14 @@ +- content_for(:title, "#{@subject}") + +%p + Bonjour, + +%p= t('.automatic_dossier_deletion', count: @dossier_hashes.count) + +%ul + - @dossier_hashes.each do |d| + %li= link_to("n° #{d[:id]} (#{d[:procedure_libelle]})", dossier_url(d)) + +%p= t('.dossier_will_not_be_processed', count: @dossier_hashes.count) + += render partial: "layouts/mailers/signature" diff --git a/config/locales/views/dossier_mailer/notify_automatic_deletion_to_user/fr.yml b/config/locales/views/dossier_mailer/notify_automatic_deletion_to_user/fr.yml new file mode 100644 index 000000000..7f5aef939 --- /dev/null +++ b/config/locales/views/dossier_mailer/notify_automatic_deletion_to_user/fr.yml @@ -0,0 +1,12 @@ +fr: + dossier_mailer: + notify_automatic_deletion_to_user: + subject: + one: "Un dossier a été supprimé automatiquement" + other: "Des dossiers ont été supprimés automatiquement" + automatic_dossier_deletion: + one: "Le délai maximum de conservation du dossier suivant a été atteint, il a donc été supprimé :" + other: "Le délai maximum de conservation des dossiers suivants a été atteint, ils ont donc été supprimés :" + dossier_will_not_be_processed: + one: "Le dossier ne sera pas traité, nous nous excusons de la gène occasionnée." + other: "Les dossiers ne seront pas traités, nous nous excusons de la gène occasionnée." diff --git a/spec/mailers/dossier_mailer_spec.rb b/spec/mailers/dossier_mailer_spec.rb index 38c121a51..071498fad 100644 --- a/spec/mailers/dossier_mailer_spec.rb +++ b/spec/mailers/dossier_mailer_spec.rb @@ -106,4 +106,20 @@ RSpec.describe DossierMailer, type: :mailer do it { expect(subject.subject).to eq("Un dossier en brouillon a été supprimé automatiquement") } it { expect(subject.body).to include("n° #{dossier.id} (#{dossier.procedure.libelle})") } end + + describe '.notify_automatic_deletion_to_user' 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_automatic_deletion_to_user(dossier.user, [dossier.hash_for_deletion_mail]) } + + it { expect(subject.subject).to eq("Un dossier a été supprimé automatiquement") } + it { expect(subject.body).to include("n° #{dossier.id} ") } + it { expect(subject.body).to include(dossier.procedure.libelle) } + it { expect(subject.body).to include("nous nous excusons de la gène occasionnée") } + end end