From 4e116f06a6504ded258af327f7cea3885db98e6e Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 18 Feb 2020 17:15:32 +0100 Subject: [PATCH 1/3] 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 From 8c77d91e9f79e0eeeda1ed9a3edbe67f8fe686c5 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 18 Feb 2020 17:18:06 +0100 Subject: [PATCH 2/3] Add notify_automatic_deletion_to_administration mailer --- app/mailers/dossier_mailer.rb | 7 +++++++ ...fy_automatic_deletion_to_administration.html.haml | 12 ++++++++++++ .../fr.yml | 9 +++++++++ spec/mailers/dossier_mailer_spec.rb | 9 +++++++++ 4 files changed, 37 insertions(+) create mode 100644 app/views/dossier_mailer/notify_automatic_deletion_to_administration.html.haml create mode 100644 config/locales/views/dossier_mailer/notify_automatic_deletion_to_administration/fr.yml 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 From 318baf316ee06921ea5a2a2b3f31ddbef5bcfcd3 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 18 Feb 2020 17:18:14 +0100 Subject: [PATCH 3/3] Add notify_en_construction_near_deletion mailer --- app/mailers/dossier_mailer.rb | 8 +++++ ...fy_en_construction_near_deletion.html.haml | 27 +++++++++++++++ .../fr.yml | 15 ++++++++ spec/mailers/dossier_mailer_spec.rb | 34 +++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 app/views/dossier_mailer/notify_en_construction_near_deletion.html.haml create mode 100644 config/locales/views/dossier_mailer/notify_en_construction_near_deletion/fr.yml diff --git a/app/mailers/dossier_mailer.rb b/app/mailers/dossier_mailer.rb index ea6edd58c..b2065b26d 100644 --- a/app/mailers/dossier_mailer.rb +++ b/app/mailers/dossier_mailer.rb @@ -97,4 +97,12 @@ class DossierMailer < ApplicationMailer mail(to: user.email, subject: @subject) end + + def notify_en_construction_near_deletion(user, dossiers, for_user) + @subject = default_i18n_subject(count: dossiers.count) + @dossiers = dossiers + @for_user = for_user + + mail(to: user.email, subject: @subject) + end end diff --git a/app/views/dossier_mailer/notify_en_construction_near_deletion.html.haml b/app/views/dossier_mailer/notify_en_construction_near_deletion.html.haml new file mode 100644 index 000000000..896138408 --- /dev/null +++ b/app/views/dossier_mailer/notify_en_construction_near_deletion.html.haml @@ -0,0 +1,27 @@ +- content_for(:title, "#{@subject}") + +%p + Bonjour, + +%p + - if !@for_user + Afin de limiter la conservation de vos données personnelles, + + = t('.automatic_dossier_deletion', count: @dossiers.count) + + %ul + - @dossiers.each do |d| + - if !@for_user + %li + #{link_to("n° #{d.id} (#{d.procedure.libelle})", dossier_url(d))}. Retrouvez le dossier au format #{link_to("PDF", instructeur_dossier_url(d.procedure, d, format: :pdf))} + - else + %li + #{link_to("n° #{d.id} (#{d.procedure.libelle})", dossier_url(d))}. Retrouvez le dossier au format #{link_to("PDF", dossier_url(d, format: :pdf))} + +%p + - if @for_user + = sanitize(t('.send_user_draft', count: @dossiers.count)) + - else + = sanitize(t('.send_other_draft', count: @dossiers.count)) + += render partial: "layouts/mailers/signature" diff --git a/config/locales/views/dossier_mailer/notify_en_construction_near_deletion/fr.yml b/config/locales/views/dossier_mailer/notify_en_construction_near_deletion/fr.yml new file mode 100644 index 000000000..6a4955e0b --- /dev/null +++ b/config/locales/views/dossier_mailer/notify_en_construction_near_deletion/fr.yml @@ -0,0 +1,15 @@ +fr: + dossier_mailer: + notify_en_construction_near_deletion: + subject: + one: Un dossier en construction va bientôt être supprimé + other: Des dossiers en construction vont bientôt être supprimés + automatic_dossier_deletion: + one: "le dossier en construction suivant sera bientôt automatiquement supprimé :" + other: "les dossiers en construction suivant seront bientôt automatiquement supprimés :" + send_user_draft: + one: "Vous pouvez retrouver votre dossier pendant encore un mois. Vous n'avez rien à faire." + other: "Vous pouvez retrouver vos dossiers pendant encore un mois. Vous n'avez rien à faire." + send_other_draft: + one: "Vous avez un mois pour traiter le dossier." + other: "Vous avez un mois pour traiter les dossiers." diff --git a/spec/mailers/dossier_mailer_spec.rb b/spec/mailers/dossier_mailer_spec.rb index d1984d616..00a76d4e6 100644 --- a/spec/mailers/dossier_mailer_spec.rb +++ b/spec/mailers/dossier_mailer_spec.rb @@ -131,4 +131,38 @@ RSpec.describe DossierMailer, type: :mailer do 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 + + describe '.notify_en_construction_near_deletion_to_administration' 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_en_construction_near_deletion(dossier.user, [dossier], true) } + + it { expect(subject.subject).to eq("Un dossier en construction va bientôt être supprimé") } + it { expect(subject.body).to include("n° #{dossier.id} ") } + it { expect(subject.body).to include(dossier.procedure.libelle) } + it { expect(subject.body).to include("PDF") } + it { expect(subject.body).to include("Vous pouvez retrouver votre dossier pendant encore un mois. Vous n'avez rien à faire.") } + end + + describe '.notify_en_construction_near_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_en_construction_near_deletion(dossier.user, [dossier], false) } + + it { expect(subject.subject).to eq("Un dossier en construction va bientôt être supprimé") } + it { expect(subject.body).to include("n° #{dossier.id} ") } + it { expect(subject.body).to include(dossier.procedure.libelle) } + it { expect(subject.body).to include("PDF") } + it { expect(subject.body).to include("Vous avez un mois pour traiter le dossier.") } + end end