Merge pull request #2049 from betagouv/attestation-resend

Resend attestation for a procedure whose attestation template changed
This commit is contained in:
gregoirenovel 2018-06-05 17:43:43 +02:00 committed by GitHub
commit 72a2576122
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View 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  #{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

View 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