[#1946] Monthly expiring dossiers summary mail
This commit is contained in:
parent
43d8db88d9
commit
ac82a72dcc
5 changed files with 94 additions and 0 deletions
12
app/jobs/warn_expiring_dossiers_job.rb
Normal file
12
app/jobs/warn_expiring_dossiers_job.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
class WarnExpiringDossiersJob < ApplicationJob
|
||||
queue_as :cron
|
||||
|
||||
def perform(*args)
|
||||
expiring, expired = Dossier
|
||||
.includes(:procedure)
|
||||
.nearing_end_of_retention
|
||||
.partition(&:retention_expired?)
|
||||
|
||||
AdministrationMailer.dossier_expiration_summary(expiring, expired).deliver_later
|
||||
end
|
||||
end
|
|
@ -36,4 +36,22 @@ class AdministrationMailer < ApplicationMailer
|
|||
mail(to: EQUIPE_EMAIL,
|
||||
subject: subject)
|
||||
end
|
||||
|
||||
def dossier_expiration_summary(expiring_dossiers, expired_dossiers)
|
||||
subject =
|
||||
if expired_dossiers.present? && expiring_dossiers.present?
|
||||
"Des dossiers ont dépassé leur délai de conservation, et d’autres en approchent"
|
||||
elsif expired_dossiers.present?
|
||||
"Des dossiers ont dépassé leur délai de conservation"
|
||||
elsif expiring_dossiers.present?
|
||||
"Des dossiers approchent de la fin de leur délai de conservation"
|
||||
else
|
||||
"Aucun dossier en fin de délai de conservation"
|
||||
end
|
||||
|
||||
@expiring_dossiers = expiring_dossiers
|
||||
@expired_dossiers = expired_dossiers
|
||||
|
||||
mail(to: TECH_EMAIL, subject: subject)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
- content_for(:title, 'Expiration du délai de conservation des dossiers')
|
||||
|
||||
- if @expired_dossiers.present?
|
||||
%h1= t('mail.administration.dossier_expiration_summary.expired_dossiers', count: @expired_dossiers.count)
|
||||
- @expired_dossiers.group_by(&:procedure).each do |procedure, dossiers|
|
||||
%dl
|
||||
%dt
|
||||
#{procedure.libelle} (#{link_to(procedure.id, manager_procedure_url(procedure))}) :
|
||||
%dd
|
||||
= dossiers.map { |d| link_to(d.id, manager_dossier_url(d)) }.join(', ').html_safe
|
||||
|
||||
- if @expiring_dossiers.present?
|
||||
%h1= t('mail.administration.dossier_expiration_summary.expiring_dossiers', count: @expiring_dossiers.count)
|
||||
- @expiring_dossiers.group_by(&:procedure).each do |procedure, dossiers|
|
||||
%dl
|
||||
%dt
|
||||
#{procedure.libelle} (#{link_to(procedure.id, manager_procedure_url(procedure))}) :
|
||||
%dd
|
||||
= dossiers.map { |d| link_to(d.id, manager_dossier_url(d)) }.join(', ').html_safe
|
||||
|
||||
- if @expired_dossiers.empty? && @expiring_dossiers.empty?
|
||||
Il n’y a pas de dossier expiré ou sur le point d’expirer.
|
|
@ -36,6 +36,16 @@ fr:
|
|||
apipie:
|
||||
api_documentation: "Documentation de l'API demarches-simplifiees.fr"
|
||||
|
||||
mail:
|
||||
administration:
|
||||
dossier_expiration_summary:
|
||||
expired_dossiers:
|
||||
one: "Un dossier a passé sa date limite de conservation"
|
||||
other: "%{count} dossiers ont passé leur date limite de conservation"
|
||||
expiring_dossiers:
|
||||
one: "Un dossier est sur le point de passer sa date limite de conservation"
|
||||
other: "%{count} dossiers sont sur le point de passer leur date limite de conservation"
|
||||
|
||||
modal:
|
||||
publish:
|
||||
title:
|
||||
|
|
|
@ -33,4 +33,36 @@ RSpec.describe AdministrationMailer, type: :mailer do
|
|||
|
||||
it { expect(subject.subject).not_to be_empty }
|
||||
end
|
||||
|
||||
describe '#dossier_expiration_summary' do
|
||||
subject { described_class.dossier_expiration_summary(expiring, expired) }
|
||||
|
||||
context 'with expiring dossiers only' do
|
||||
let(:expiring) { [create(:dossier)] }
|
||||
let(:expired) { [] }
|
||||
|
||||
it { expect(subject.subject).to eq("Des dossiers approchent de la fin de leur délai de conservation") }
|
||||
end
|
||||
|
||||
context 'with expired dossiers only' do
|
||||
let(:expiring) { [] }
|
||||
let(:expired) { [create(:dossier)] }
|
||||
|
||||
it { expect(subject.subject).to eq("Des dossiers ont dépassé leur délai de conservation") }
|
||||
end
|
||||
|
||||
context 'with both expiring and expired dossiers' do
|
||||
let(:expiring) { [create(:dossier)] }
|
||||
let(:expired) { [create(:dossier)] }
|
||||
|
||||
it { expect(subject.subject).to eq("Des dossiers ont dépassé leur délai de conservation, et d’autres en approchent") }
|
||||
end
|
||||
|
||||
context 'with neither expiring nor expired dossiers' do
|
||||
let(:expiring) { [] }
|
||||
let(:expired) { [] }
|
||||
|
||||
it { expect(subject.subject).to eq("Aucun dossier en fin de délai de conservation") }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue