Merge pull request #2049 from betagouv/attestation-resend
Resend attestation for a procedure whose attestation template changed
This commit is contained in:
commit
72a2576122
2 changed files with 47 additions and 0 deletions
29
app/mailers/resend_attestation_mailer.rb
Normal file
29
app/mailers/resend_attestation_mailer.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Mailers
|
||||
class ResendAttestationMailer < ApplicationMailer
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
def resend_attestation(dossier)
|
||||
to = dossier.user.email
|
||||
subject = "Nouvelle attestation pour votre dossier nº #{dossier.id}"
|
||||
|
||||
mail(to: to, subject: subject, body: body(dossier))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def body(dossier)
|
||||
<<~HEREDOC
|
||||
Bonjour,
|
||||
|
||||
L'attestation de votre dossier nº #{dossier.id} (procédure "#{dossier.procedure.libelle}") a été modifiée.
|
||||
|
||||
Votre nouvelle attestation est disponible à l'adresse suivante :
|
||||
#{dossier_attestation_url(dossier)}
|
||||
|
||||
Cordialement,
|
||||
|
||||
L’équipe demarches-simplifiees.fr
|
||||
HEREDOC
|
||||
end
|
||||
end
|
||||
end
|
18
lib/tasks/2018_06_05_resend_attestations.rb
Normal file
18
lib/tasks/2018_06_05_resend_attestations.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
namespace :'2018_06_05_resend_attestation' do
|
||||
task set: :environment do
|
||||
procedure = Procedure.find(4247)
|
||||
dossiers = procedure.dossiers.includes(:attestation).where(state: 'accepte').select do |d|
|
||||
d.processed_at < procedure.attestation_template.updated_at
|
||||
end
|
||||
|
||||
dossiers.each do |dossier|
|
||||
attestation = dossier.attestation
|
||||
attestation.destroy
|
||||
|
||||
dossier.attestation = dossier.build_attestation
|
||||
|
||||
Mailers::ResendAttestationMailer.resend_attestation(dossier).deliver_later
|
||||
puts "Email envoyé à #{email} pour le dossier #{dossier.id}"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue