[Fix #813] When a brouillon is created, send an email to user
This commit is contained in:
parent
1055c96c4d
commit
a8ec374252
6 changed files with 63 additions and 1 deletions
|
@ -21,6 +21,14 @@ class NotificationMailer < ApplicationMailer
|
|||
mail(subject: @object) { |format| format.html { @body } }
|
||||
end
|
||||
|
||||
def send_draft_notification(dossier)
|
||||
vars_mailer(dossier)
|
||||
|
||||
@object = "Retrouvez votre brouillon pour la démarche : #{dossier.procedure.libelle}"
|
||||
|
||||
mail(subject: @object)
|
||||
end
|
||||
|
||||
def new_answer(dossier)
|
||||
send_mail dossier, "Nouveau message pour votre dossier TPS nº #{dossier.id}"
|
||||
end
|
||||
|
|
|
@ -76,6 +76,7 @@ class Dossier < ActiveRecord::Base
|
|||
after_save :build_default_champs, if: Proc.new { procedure_id_changed? }
|
||||
after_save :build_default_individual, if: Proc.new { procedure.for_individual? }
|
||||
after_save :send_dossier_received
|
||||
after_create :send_draft_notification_email
|
||||
|
||||
validates :user, presence: true
|
||||
|
||||
|
@ -380,4 +381,10 @@ class Dossier < ActiveRecord::Base
|
|||
NotificationMailer.send_dossier_received(id).deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
def send_draft_notification_email
|
||||
if brouillon?
|
||||
NotificationMailer.send_draft_notification(self).deliver_now!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
Bonjour,
|
||||
%br
|
||||
%br
|
||||
Vous pouvez retrouver et compléter le brouillon que vous avez créé pour la démarche
|
||||
%strong= @dossier.procedure.libelle
|
||||
à l'adresse suivante :
|
||||
= link_to users_dossiers_url(liste: 'brouillon'), users_dossiers_url(liste: 'brouillon'), target: '_blank'
|
||||
%br
|
||||
%br
|
||||
Bonne journée,
|
||||
%br
|
||||
%br
|
||||
L'équipe Téléprocédures Simplifiées
|
||||
%br
|
||||
%br
|
||||
—
|
||||
%br
|
||||
%br
|
||||
Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme.
|
|
@ -2,4 +2,8 @@ class NotificationMailerPreview < ActionMailer::Preview
|
|||
def send_notification
|
||||
NotificationMailer.send_notification(Dossier.last, Dossier.last.procedure.initiated_mail_template)
|
||||
end
|
||||
|
||||
def send_draft_notification
|
||||
NotificationMailer.send_draft_notification(Dossier.last)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -102,7 +102,7 @@ describe AttestationTemplate, type: :model do
|
|||
let(:entreprise) { create(:entreprise, etablissement: etablissement) }
|
||||
let(:types_de_champ) { [] }
|
||||
let(:types_de_champ_private) { [] }
|
||||
let(:dossier) { create(:dossier, procedure: procedure, individual: individual, entreprise: entreprise) }
|
||||
let!(:dossier) { create(:dossier, procedure: procedure, individual: individual, entreprise: entreprise) }
|
||||
let(:template_title) { 'title' }
|
||||
let(:template_body) { 'body' }
|
||||
let(:attestation_template) do
|
||||
|
|
|
@ -792,6 +792,30 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#send_draft_notification_email" do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
end
|
||||
|
||||
it "send an email when the dossier is created for the very first time" do
|
||||
expect { Dossier.create(procedure: procedure, state: "draft", user: user) }.to change(ActionMailer::Base.deliveries, :size).from(0).to(1)
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
expect(mail.subject).to eq("Retrouvez votre brouillon pour la démarche : #{procedure.libelle}")
|
||||
end
|
||||
|
||||
it "does not send an email when the dossier is created with a non draft state" do
|
||||
expect { Dossier.create(procedure: procedure, state: "initiated", user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
|
||||
expect { Dossier.create(procedure: procedure, state: "received", user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
|
||||
expect { Dossier.create(procedure: procedure, state: "closed", user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
|
||||
expect { Dossier.create(procedure: procedure, state: "refused", user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
|
||||
expect { Dossier.create(procedure: procedure, state: "without_continuation", user: user) }.not_to change(ActionMailer::Base.deliveries, :size)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.build_attestation' do
|
||||
let(:attestation_template) { nil }
|
||||
let(:procedure) { create(:procedure, attestation_template: attestation_template) }
|
||||
|
|
Loading…
Reference in a new issue