Work on deletion mail
This commit is contained in:
parent
79bfb8b143
commit
006e426a11
7 changed files with 53 additions and 4 deletions
|
@ -77,6 +77,10 @@ class DossierMailer < ApplicationMailer
|
|||
mail(to: user.email, subject: @subject)
|
||||
end
|
||||
|
||||
def notify_brouillon_deletion(user, dossiers)
|
||||
def notify_brouillon_deletion(user, dossier_hashes)
|
||||
@subject = default_i18n_subject(count: dossier_hashes.count)
|
||||
@dossier_hashes = dossier_hashes
|
||||
|
||||
mail(to: user.email, subject: @subject)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -587,6 +587,10 @@ class Dossier < ApplicationRecord
|
|||
Dossier.where(id: champs.filter(&:dossier_link?).map(&:value).compact)
|
||||
end
|
||||
|
||||
def hash_for_deletion_mail
|
||||
{ id: self.id, procedure_libelle: self.procedure.libelle }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def log_dossier_operation(author, operation, subject = nil)
|
||||
|
@ -657,11 +661,12 @@ class Dossier < ApplicationRecord
|
|||
expired_brouillons = Dossier.expired_brouillon
|
||||
|
||||
expired_brouillons
|
||||
.includes(:user)
|
||||
.includes(:procedure, :user)
|
||||
.group_by(&:user)
|
||||
.each do |(user, dossiers)|
|
||||
|
||||
DossierMailer.notify_brouillon_deletion(user, dossiers).deliver_later
|
||||
dossier_hashes = dossiers.map(&:hash_for_deletion_mail)
|
||||
DossierMailer.notify_brouillon_deletion(user, dossier_hashes).deliver_later
|
||||
|
||||
dossiers.each do |dossier|
|
||||
DeletedDossier.create_from_dossier(dossier)
|
||||
|
|
12
app/views/dossier_mailer/notify_brouillon_deletion.html.haml
Normal file
12
app/views/dossier_mailer/notify_brouillon_deletion.html.haml
Normal file
|
@ -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"
|
|
@ -0,0 +1,9 @@
|
|||
fr:
|
||||
dossier_mailer:
|
||||
notify_brouillon_deletion:
|
||||
subject:
|
||||
one: "Un dossier en brouillon a été supprimé automatiquement"
|
||||
other: "Des dossiers en brouillon ont été supprimés automatiquement"
|
||||
automatic_dossier_deletion:
|
||||
one: "Le délai maximum de conservation du dossier en brouillon suivant a été atteint, il a donc été supprimé :"
|
||||
other: "Le délai maximum de conservation des dossiers en brouillon suivants a été atteint, ils ont donc été supprimés :"
|
|
@ -97,4 +97,13 @@ RSpec.describe DossierMailer, type: :mailer do
|
|||
it { expect(subject.body).to include("n° #{dossier.id} ") }
|
||||
it { expect(subject.body).to include(dossier.procedure.libelle) }
|
||||
end
|
||||
|
||||
describe '.notify_brouillon_deletion' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
||||
subject { described_class.notify_brouillon_deletion(dossier.user, [dossier.hash_for_deletion_mail]) }
|
||||
|
||||
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
|
||||
end
|
||||
|
|
|
@ -27,6 +27,16 @@ class DossierMailerPreview < ActionMailer::Preview
|
|||
def notify_brouillons_near_deletion
|
||||
DossierMailer.notify_brouillon_near_deletion(User.new(email: "usager@example.com"), [dossier, dossier])
|
||||
end
|
||||
|
||||
def notify_brouillon_deletion
|
||||
DossierMailer.notify_brouillon_deletion(User.new(email: "usager@example.com"), [dossier.hash_for_deletion_mail])
|
||||
end
|
||||
|
||||
def notify_brouillons_deletion
|
||||
dossier_hashes = [dossier, dossier].map(&:hash_for_deletion_mail)
|
||||
DossierMailer.notify_brouillon_deletion(User.new(email: "usager@example.com"), dossier_hashes)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def deleted_dossier
|
||||
|
|
|
@ -1092,7 +1092,7 @@ describe Dossier do
|
|||
|
||||
it 'notifies deletion' do
|
||||
expect(DossierMailer).to have_received(:notify_brouillon_deletion).once
|
||||
expect(DossierMailer).to have_received(:notify_brouillon_deletion).with(expired_brouillon.user, [expired_brouillon])
|
||||
expect(DossierMailer).to have_received(:notify_brouillon_deletion).with(expired_brouillon.user, [expired_brouillon.hash_for_deletion_mail])
|
||||
end
|
||||
|
||||
it 'deletes the expired brouillon' do
|
||||
|
|
Loading…
Reference in a new issue