diff --git a/app/mailers/dossier_mailer.rb b/app/mailers/dossier_mailer.rb index 5a8fbb00e..ea6edd58c 100644 --- a/app/mailers/dossier_mailer.rb +++ b/app/mailers/dossier_mailer.rb @@ -90,4 +90,11 @@ class DossierMailer < ApplicationMailer mail(to: user.email, subject: @subject) end + + def notify_automatic_deletion_to_administration(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_administration.html.haml b/app/views/dossier_mailer/notify_automatic_deletion_to_administration.html.haml new file mode 100644 index 000000000..e466b459b --- /dev/null +++ b/app/views/dossier_mailer/notify_automatic_deletion_to_administration.html.haml @@ -0,0 +1,12 @@ +- content_for(:title, "#{@subject}") + +%p + Bonjour, + +%p= t('.automatic_dossier_deletion', count: @dossier_hashes.count) + +%ul + - @dossier_hashes.each do |d| + %li= "n° #{d[:id]} (#{d[:procedure_libelle]})" + += render partial: "layouts/mailers/signature" diff --git a/config/locales/views/dossier_mailer/notify_automatic_deletion_to_administration/fr.yml b/config/locales/views/dossier_mailer/notify_automatic_deletion_to_administration/fr.yml new file mode 100644 index 000000000..c0f77813f --- /dev/null +++ b/config/locales/views/dossier_mailer/notify_automatic_deletion_to_administration/fr.yml @@ -0,0 +1,9 @@ +fr: + dossier_mailer: + notify_automatic_deletion_to_administration: + 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 :" diff --git a/spec/mailers/dossier_mailer_spec.rb b/spec/mailers/dossier_mailer_spec.rb index 071498fad..d1984d616 100644 --- a/spec/mailers/dossier_mailer_spec.rb +++ b/spec/mailers/dossier_mailer_spec.rb @@ -122,4 +122,13 @@ RSpec.describe DossierMailer, type: :mailer do 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 + + describe '.notify_automatic_deletion_to_administration' do + let(:dossier) { create(:dossier) } + + subject { described_class.notify_automatic_deletion_to_administration(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} (#{dossier.procedure.libelle})") } + end end