Merge pull request #8613 from colinux/email-template-subject-length

Email: limite le sujet généré à 100 caractères et utilise le sujet par défaut si le modèle est vide
This commit is contained in:
mfo 2023-02-13 17:31:04 +01:00 committed by GitHub
commit 76ef4ae96e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 2 deletions

View file

@ -7,6 +7,7 @@
#
class NotificationMailer < ApplicationMailer
include ActionView::Helpers::SanitizeHelper
include ActionView::Helpers::TextHelper
before_action :set_dossier
before_action :set_services_publics_plus, only: :send_notification
@ -67,7 +68,7 @@ class NotificationMailer < ApplicationMailer
mail_template = @dossier.procedure.mail_template_for(params[:state])
@email = @dossier.user_email_for(:notification)
@subject = mail_template.subject_for_dossier(@dossier)
@subject = truncate(mail_template.subject_for_dossier(@dossier), length: 100)
@body = mail_template.body_for_dossier(@dossier)
@actions = mail_template.actions_for_dossier(@dossier)
@attachment = mail_template.attachment_for_dossier(@dossier)

View file

@ -10,7 +10,7 @@ module MailTemplateConcern
end
def subject_for_dossier(dossier)
replace_tags(subject, dossier)
replace_tags(subject, dossier).presence || replace_tags(self.class::DEFAULT_SUBJECT, dossier)
end
def body_for_dossier(dossier)

View file

@ -395,6 +395,19 @@ en:
zone: This procedure is run by
champs:
value: Value
default_mail_attributes: &default_mail_attributes
hints:
subject: The generated subject will be truncated if it exceeds 100 characters.
mails/closed_mail:
<< : *default_mail_attributes
mails/initiated_mail:
<< : *default_mail_attributes
mails/received_mail:
<< : *default_mail_attributes
mails/refused_mail:
<< : *default_mail_attributes
mails/without_continuation_mail:
<< : *default_mail_attributes
errors:
messages:

View file

@ -392,6 +392,19 @@ fr:
zone: La démarche est mise en œuvre par
champs:
value: Valeur du champ
default_mail_attributes: &default_mail_attributes
hints:
subject: "Lobjet généré sera tronqué sil dépasse 100 caractères."
mails/closed_mail:
<< : *default_mail_attributes
mails/initiated_mail:
<< : *default_mail_attributes
mails/received_mail:
<< : *default_mail_attributes
mails/refused_mail:
<< : *default_mail_attributes
mails/without_continuation_mail:
<< : *default_mail_attributes
errors:
messages:

View file

@ -101,4 +101,27 @@ RSpec.describe NotificationMailer, type: :mailer do
end
end
end
describe 'subject length' do
let(:procedure) { create(:simple_procedure, libelle: "My super long title " + ("xo " * 100)) }
let(:dossier) { create(:dossier, :en_instruction, :with_individual, :with_service, user: user, procedure: procedure) }
let(:email_template) { create(:closed_mail, subject:, body: 'Your dossier was accepted. Thanks.') }
before do
dossier.procedure.closed_mail = email_template
end
subject(:mail) { described_class.send_accepte_notification(dossier) }
context "subject is too long" do
let(:subject) { 'Un long libellé --libellé démarche--' }
it { expect(mail.subject.length).to be <= 100 }
end
context "subject should fallback to default" do
let(:subject) { "" }
it { expect(mail.subject).to match(/^Votre dossier .+ a été accepté \(My super long title/) }
it { expect(mail.subject.length).to be <= 100 }
end
end
end