mailers: use the standard view mechanism to render notifications
Instead of rendering a view as a template, consider the view as a normal view.
This commit is contained in:
parent
5bbcd600fb
commit
858b093314
7 changed files with 36 additions and 12 deletions
|
@ -8,8 +8,9 @@ module NewAdministrateur
|
|||
@service = procedure.service
|
||||
|
||||
mail_template = find_mail_template_by_slug(params[:id])
|
||||
@rendered_template = sanitize(mail_template.body)
|
||||
|
||||
render(html: sanitize(mail_template.body), layout: 'mailers/notification')
|
||||
render(template: 'notification_mailer/send_notification', layout: 'mailers/notifications_layout')
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -13,7 +13,7 @@ class DossierMailer < ApplicationMailer
|
|||
subject = "Retrouvez votre brouillon pour la démarche « #{dossier.procedure.libelle} »"
|
||||
|
||||
mail(to: dossier.user.email, subject: subject) do |format|
|
||||
format.html { render layout: 'mailers/notification' }
|
||||
format.html { render layout: 'mailers/notifications_layout' }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -25,7 +25,7 @@ class DossierMailer < ApplicationMailer
|
|||
subject = "Nouveau message pour votre dossier nº #{dossier.id} (#{dossier.procedure.libelle})"
|
||||
|
||||
mail(to: dossier.user.email, subject: subject) do |format|
|
||||
format.html { render layout: 'mailers/notification' }
|
||||
format.html { render layout: 'mailers/notifications_layout' }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,8 +6,12 @@
|
|||
# The subject and body of a Notification can be customized by each demarche.
|
||||
#
|
||||
class NotificationMailer < ApplicationMailer
|
||||
include ActionView::Helpers::SanitizeHelper
|
||||
|
||||
helper ServiceHelper
|
||||
|
||||
layout 'mailers/notifications_layout'
|
||||
|
||||
def send_dossier_received(dossier)
|
||||
send_notification(dossier, dossier.procedure.received_mail_template)
|
||||
end
|
||||
|
@ -41,12 +45,9 @@ class NotificationMailer < ApplicationMailer
|
|||
@dossier = dossier
|
||||
@service = dossier.procedure.service
|
||||
@logo_url = attach_logo(dossier.procedure)
|
||||
@rendered_template = sanitize(body)
|
||||
|
||||
mail(subject: subject, to: email) do |format|
|
||||
# rubocop:disable Rails/OutputSafety
|
||||
format.html { render(html: body.html_safe, layout: 'mailers/notification') }
|
||||
# rubocop:enable Rails/OutputSafety
|
||||
end
|
||||
mail(subject: subject, to: email, template_name: 'send_notification')
|
||||
end
|
||||
|
||||
def create_commentaire_for_notification(dossier, subject, body)
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
- content_for :procedure_logo do
|
||||
= render 'layouts/mailers/logo', url: @logo_url
|
||||
|
||||
%p
|
||||
Bonjour,
|
||||
|
||||
|
@ -10,4 +13,7 @@
|
|||
|
||||
= round_button('Lire le message', messagerie_dossier_url(@dossier))
|
||||
|
||||
= render partial: "layouts/mailers/signature", locals: { service: @service }
|
||||
= render 'layouts/mailers/signature', service: @service
|
||||
|
||||
- content_for :footer do
|
||||
= render 'layouts/mailers/service_footer', service: @service, dossier: @dossier
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
- content_for :procedure_logo do
|
||||
= render 'layouts/mailers/logo', url: @logo_url
|
||||
|
||||
%p
|
||||
Bonjour,
|
||||
|
||||
|
@ -10,4 +13,7 @@
|
|||
à l’adresse suivante :
|
||||
= link_to dossier_url(@dossier), dossier_url(@dossier), target: '_blank', rel: 'noopener'
|
||||
|
||||
= render partial: "layouts/mailers/signature"
|
||||
= render 'layouts/mailers/signature'
|
||||
|
||||
- content_for :footer do
|
||||
= render 'layouts/mailers/service_footer', service: @service, dossier: @dossier
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
- content_for :procedure_logo do
|
||||
= render 'layouts/mailers/logo', url: @logo_url
|
||||
|
||||
= @rendered_template
|
||||
|
||||
- content_for :footer do
|
||||
= render 'layouts/mailers/service_footer', service: @service, dossier: @dossier
|
||||
|
||||
= render template: 'layouts/mailers/notifications_layout'
|
|
@ -3,6 +3,12 @@ require "rails_helper"
|
|||
RSpec.describe DossierMailer, type: :mailer do
|
||||
let(:to_email) { 'gestionnaire@exemple.gouv.fr' }
|
||||
|
||||
shared_examples 'a dossier notification' do
|
||||
it 'includes the contact informations in the footer' do
|
||||
expect(subject.body).to include('ne pas répondre')
|
||||
end
|
||||
end
|
||||
|
||||
describe '.notify_new_draft' do
|
||||
let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) }
|
||||
|
||||
|
@ -12,6 +18,8 @@ RSpec.describe DossierMailer, type: :mailer do
|
|||
it { expect(subject.subject).to include(dossier.procedure.libelle) }
|
||||
it { expect(subject.body).to include(dossier.procedure.libelle) }
|
||||
it { expect(subject.body).to include(dossier_url(dossier)) }
|
||||
|
||||
it_behaves_like 'a dossier notification'
|
||||
end
|
||||
|
||||
describe '.notify_new_answer' do
|
||||
|
@ -22,6 +30,8 @@ RSpec.describe DossierMailer, type: :mailer do
|
|||
it { expect(subject.subject).to include("Nouveau message") }
|
||||
it { expect(subject.subject).to include(dossier.id.to_s) }
|
||||
it { expect(subject.body).to include(messagerie_dossier_url(dossier)) }
|
||||
|
||||
it_behaves_like 'a dossier notification'
|
||||
end
|
||||
|
||||
describe '.notify_deletion_to_user' do
|
||||
|
|
Loading…
Reference in a new issue