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)
|
|
|
|
service = new(dossier, state)
|
2023-07-07 14:06:10 +02:00
|
|
|
body = ["<p>[#{service.safe_subject}]</p>", service.safe_body].join('')
|
|
|
|
CommentaireService.create!(CONTACT_EMAIL, dossier, body: body)
|
|
|
|
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
|