Merge pull request #7283 from betagouv/email-deposit-receipt

Usager : l'attestation de dépôt est envoyée en pièce jointe dans l'email de notification de dépôt
This commit is contained in:
Pierre de La Morinerie 2022-05-17 10:30:13 +02:00 committed by GitHub
commit 526c270d58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 3 deletions

View file

@ -21,6 +21,7 @@ class NotificationMailer < ApplicationMailer
@service = @dossier.procedure.service
@logo_url = attach_logo(@dossier.procedure)
@rendered_template = sanitize(@body)
attachments[@attachment[:filename]] = @attachment[:content] if @attachment.present?
I18n.with_locale(@dossier.user_locale) do
mail(subject: @subject, to: @email, template_name: 'send_notification')
@ -62,6 +63,7 @@ class NotificationMailer < ApplicationMailer
@subject = mail_template.subject_for_dossier(@dossier)
@body = mail_template.body_for_dossier(@dossier)
@actions = mail_template.actions_for_dossier(@dossier)
@attachment = mail_template.attachment_for_dossier(@dossier)
end
end
end

View file

@ -21,6 +21,10 @@ module MailTemplateConcern
[MailTemplateConcern::Actions::SHOW, MailTemplateConcern::Actions::ASK_QUESTION]
end
def attachment_for_dossier(dossier)
nil
end
def update_rich_body
self.rich_body = self.body
end

View file

@ -20,5 +20,24 @@ module Mails
DISPLAYED_NAME = I18n.t('activerecord.models.mail.initiated_mail.proof_of_receipt')
DEFAULT_SUBJECT = I18n.t('activerecord.models.mail.initiated_mail.default_subject', dossier_number: '--numéro du dossier--', procedure_libelle: '--libellé démarche--')
DOSSIER_STATE = Dossier.states.fetch(:en_construction)
def attachment_for_dossier(dossier)
if procedure.feature_enabled?(:procedure_dossier_papertrail)
{
filename: I18n.t('users.dossiers.show.papertrail.filename'),
content: deposit_receipt_for_dossier(dossier)
}
end
end
private
def deposit_receipt_for_dossier(dossier)
ApplicationController.render(
template: 'users/dossiers/papertrail',
formats: [:pdf],
assigns: { dossier: dossier }
)
end
end
end

View file

@ -469,7 +469,7 @@ fr:
attestation:
no_longer_available: "Lattestation n'est plus disponible sur ce dossier."
papertrail:
receipt: "Accusé de dépôt"
receipt: "Attestation de dépôt"
description: "Ce document atteste que %{user_name} a déposé le %{date} un dossier sur la démarche « %{procedure} »."
file_submitted_at: "Dossier déposé le"
dossier_state: "État du dossier"

View file

@ -3,6 +3,31 @@ RSpec.describe NotificationMailer, type: :mailer do
let(:user) { create(:user) }
let(:procedure) { create(:simple_procedure) }
describe 'send_en_construction_notification' do
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_service, user: user, procedure: procedure) }
let(:email_template) { create(:initiated_mail, subject: 'Email subject', body: 'Your dossier was received. Thanks.') }
before do
dossier.procedure.initiated_mail = email_template
end
subject(:mail) { described_class.send_en_construction_notification(dossier) }
it 'renders the template' do
expect(mail.subject).to eq('Email subject')
expect((mail.html_part || mail).body).to include('Your dossier was received')
end
context 'when the deposit receipt feature is enabled' do
before { Flipper.enable(:procedure_dossier_papertrail, procedure) }
after { Flipper.disable(:procedure_dossier_papertrail, procedure) }
it 'attaches the deposit receipt' do
expect(mail.attachments.first.filename).to eq("attestation-de-depot.pdf")
end
end
end
describe 'send_en_instruction_notification' do
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_service, user: user, procedure: procedure) }
let(:email_template) { create(:received_mail, subject: 'Email subject', body: 'Your dossier was processed. Thanks.') }

View file

@ -26,8 +26,7 @@ class NotificationMailerPreview < ActionMailer::Preview
end
def dossier_with_image
procedure = Procedure.where(id: Mails::InitiatedMail.where("body like ?", "%<img%").pluck(:procedure_id).uniq).order("RANDOM()").first
procedure.dossiers.last
Dossier.joins(procedure: [:initiated_mail]).where("initiated_mails.body like ?", "%<img%").order('RANDOM()').first
end
def dossier_with_motivation