mailers: streamline the NotificationMailer
Notifications are now only for demarche-templated emails.
This commit is contained in:
parent
1d1a15bf70
commit
e5303fd986
10 changed files with 49 additions and 33 deletions
|
@ -1,6 +1,20 @@
|
||||||
class DossierMailer < ApplicationMailer
|
class DossierMailer < ApplicationMailer
|
||||||
layout 'mailers/layout'
|
layout 'mailers/layout'
|
||||||
|
|
||||||
|
def notify_new_draft(dossier)
|
||||||
|
@dossier = dossier
|
||||||
|
subject = "Retrouvez votre brouillon pour la démarche \"#{dossier.procedure.libelle}\""
|
||||||
|
|
||||||
|
mail(to: dossier.user.email, subject: subject)
|
||||||
|
end
|
||||||
|
|
||||||
|
def notify_new_answer(dossier)
|
||||||
|
@dossier = dossier
|
||||||
|
subject = "Nouveau message pour votre dossier nº #{dossier.id}"
|
||||||
|
|
||||||
|
mail(to: dossier.user.email, subject: subject)
|
||||||
|
end
|
||||||
|
|
||||||
def notify_deletion_to_user(deleted_dossier, to_email)
|
def notify_deletion_to_user(deleted_dossier, to_email)
|
||||||
@deleted_dossier = deleted_dossier
|
@deleted_dossier = deleted_dossier
|
||||||
subject = "Votre dossier n° #{@deleted_dossier.dossier_id} a bien été supprimé"
|
subject = "Votre dossier n° #{@deleted_dossier.dossier_id} a bien été supprimé"
|
||||||
|
|
|
@ -1,16 +1,8 @@
|
||||||
|
# A Notification is attached as a Comment to the relevant discussion,
|
||||||
|
# then sent by email to the user.
|
||||||
|
#
|
||||||
|
# The subject and body of a Notification can be customized by each demarche.
|
||||||
class NotificationMailer < ApplicationMailer
|
class NotificationMailer < ApplicationMailer
|
||||||
def new_answer(dossier)
|
|
||||||
subject = "Nouveau message pour votre dossier nº #{dossier.id}"
|
|
||||||
|
|
||||||
send_mail(dossier, subject)
|
|
||||||
end
|
|
||||||
|
|
||||||
def send_draft_notification(dossier)
|
|
||||||
subject = "Retrouvez votre brouillon pour la démarche \"#{dossier.procedure.libelle}\""
|
|
||||||
|
|
||||||
send_mail(dossier, subject)
|
|
||||||
end
|
|
||||||
|
|
||||||
def send_dossier_received(dossier)
|
def send_dossier_received(dossier)
|
||||||
send_notification(dossier, dossier.procedure.received_mail_template)
|
send_notification(dossier, dossier.procedure.received_mail_template)
|
||||||
end
|
end
|
||||||
|
@ -33,13 +25,6 @@ class NotificationMailer < ApplicationMailer
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def send_mail(dossier, subject)
|
|
||||||
@dossier = dossier
|
|
||||||
email = dossier.user.email
|
|
||||||
|
|
||||||
mail(subject: subject, to: email)
|
|
||||||
end
|
|
||||||
|
|
||||||
def send_notification(dossier, mail_template)
|
def send_notification(dossier, mail_template)
|
||||||
email = dossier.user.email
|
email = dossier.user.email
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class Commentaire < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_user
|
def notify_user
|
||||||
NotificationMailer.new_answer(dossier).deliver_later
|
DossierMailer.notify_new_answer(dossier).deliver_later
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_virus_free?
|
def is_virus_free?
|
||||||
|
|
|
@ -356,7 +356,7 @@ class Dossier < ApplicationRecord
|
||||||
|
|
||||||
def send_draft_notification_email
|
def send_draft_notification_email
|
||||||
if brouillon?
|
if brouillon?
|
||||||
NotificationMailer.send_draft_notification(self).deliver_later
|
DossierMailer.notify_new_draft(self).deliver_later
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,27 @@ require "rails_helper"
|
||||||
RSpec.describe DossierMailer, type: :mailer do
|
RSpec.describe DossierMailer, type: :mailer do
|
||||||
let(:to_email) { 'gestionnaire@exemple.gouv.fr' }
|
let(:to_email) { 'gestionnaire@exemple.gouv.fr' }
|
||||||
|
|
||||||
|
describe '.notify_new_draft' do
|
||||||
|
let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) }
|
||||||
|
|
||||||
|
subject { described_class.notify_new_draft(dossier) }
|
||||||
|
|
||||||
|
it { expect(subject.subject).to include("brouillon") }
|
||||||
|
it { expect(subject.subject).to include(dossier.id.to_s) }
|
||||||
|
it { expect(subject.body).to include(dossier.procedure.libelle) }
|
||||||
|
it { expect(subject.body).to include(dossier_url(dossier)) }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.notify_new_answer' do
|
||||||
|
let(:dossier) { create(:dossier, procedure: build(:simple_procedure)) }
|
||||||
|
|
||||||
|
subject { described_class.notify_new_answer(dossier) }
|
||||||
|
|
||||||
|
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)) }
|
||||||
|
end
|
||||||
|
|
||||||
describe '.notify_deletion_to_user' do
|
describe '.notify_deletion_to_user' do
|
||||||
let(:deleted_dossier) { build(:deleted_dossier) }
|
let(:deleted_dossier) { build(:deleted_dossier) }
|
||||||
|
|
||||||
|
|
|
@ -55,12 +55,4 @@ RSpec.describe NotificationMailer, type: :mailer do
|
||||||
|
|
||||||
it_behaves_like "create a commentaire not notified"
|
it_behaves_like "create a commentaire not notified"
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".new_answer" do
|
|
||||||
subject(:subject) { described_class.new_answer(dossier) }
|
|
||||||
|
|
||||||
it { expect(subject.body).to match('Un nouveau message est disponible dans votre espace demarches-simplifiees.fr.') }
|
|
||||||
it { expect(subject.body).to include(messagerie_dossier_url(dossier)) }
|
|
||||||
it { expect(subject.subject).to eq("Nouveau message pour votre dossier nº #{dossier.id}") }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
# Preview all emails at http://localhost:3000/rails/mailers/dossier_mailer
|
# Preview all emails at http://localhost:3000/rails/mailers/dossier_mailer
|
||||||
class DossierMailerPreview < ActionMailer::Preview
|
class DossierMailerPreview < ActionMailer::Preview
|
||||||
|
def notify_new_draft
|
||||||
|
DossierMailer.notify_new_draft(Dossier.last)
|
||||||
|
end
|
||||||
|
|
||||||
|
def notify_new_answer
|
||||||
|
DossierMailer.notify_new_answer(Dossier.last)
|
||||||
|
end
|
||||||
|
|
||||||
def notify_deletion_to_user
|
def notify_deletion_to_user
|
||||||
DossierMailer.notify_deletion_to_user(DeletedDossier.last, "user@ds.fr")
|
DossierMailer.notify_deletion_to_user(DeletedDossier.last, "user@ds.fr")
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,8 +2,4 @@ class NotificationMailerPreview < ActionMailer::Preview
|
||||||
def send_notification
|
def send_notification
|
||||||
NotificationMailer.send_initiated_notification(Dossier.last)
|
NotificationMailer.send_initiated_notification(Dossier.last)
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_draft_notification
|
|
||||||
NotificationMailer.send_draft_notification(Dossier.last)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue