2023-07-07 14:06:10 +02:00
|
|
|
class MailTemplatePresenterService
|
|
|
|
include ActionView::Helpers::SanitizeHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
|
2023-11-29 12:59:55 +01:00
|
|
|
def self.create_commentaire_for_state(dossier, state)
|
2024-03-27 17:28:54 +01:00
|
|
|
if dossier.procedure.accuse_lecture? && Dossier::TERMINE.include?(state)
|
|
|
|
CommentaireService.create!(CONTACT_EMAIL, dossier, body: I18n.t('layouts.mailers.accuse_lecture.commentaire_html', service: dossier.procedure.service.nom))
|
|
|
|
else
|
|
|
|
service = new(dossier, state)
|
|
|
|
body = ["<p>[#{service.safe_subject}]</p>", service.safe_body].join('')
|
|
|
|
CommentaireService.create!(CONTACT_EMAIL, dossier, body: body)
|
|
|
|
end
|
2023-07-07 14:06:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def safe_body
|
2023-11-29 12:59:55 +01:00
|
|
|
sanitize(@email_template.body_for_dossier(@dossier), scrubber: Sanitizers::MailScrubber.new)
|
2023-07-07 14:06:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def safe_subject
|
2023-11-29 12:59:55 +01:00
|
|
|
Nokogiri::HTML.parse(truncate(@email_template.subject_for_dossier(@dossier), length: 100)).text
|
2023-07-07 14:06:10 +02:00
|
|
|
end
|
|
|
|
|
2023-11-29 12:59:55 +01:00
|
|
|
def initialize(dossier, state)
|
2023-07-07 14:06:10 +02:00
|
|
|
@dossier = dossier
|
2023-11-29 12:59:55 +01:00
|
|
|
@email_template = dossier.email_template_for(state)
|
2023-07-07 14:06:10 +02:00
|
|
|
end
|
|
|
|
end
|