send email to tiers if notification by email is set
This commit is contained in:
parent
2ac9c13c4a
commit
f6f18e9c86
7 changed files with 145 additions and 1 deletions
|
@ -6,7 +6,7 @@
|
|||
# The subject and body of a Notification can be customized by each demarche.
|
||||
#
|
||||
class NotificationMailer < ApplicationMailer
|
||||
before_action :set_dossier
|
||||
before_action :set_dossier, except: [:send_notification_for_tiers]
|
||||
before_action :set_services_publics_plus, only: :send_notification
|
||||
|
||||
helper ServiceHelper
|
||||
|
@ -24,6 +24,21 @@ class NotificationMailer < ApplicationMailer
|
|||
end
|
||||
end
|
||||
|
||||
def send_notification_for_tiers(dossier)
|
||||
@dossier = dossier
|
||||
|
||||
if @dossier.individual.no_notification?
|
||||
mail.perform_deliveries = false
|
||||
return
|
||||
end
|
||||
|
||||
@subject = "Votre dossier rempli par le mandataire #{@dossier.mandataire_first_name} #{@dossier.mandataire_last_name} a été mis à jour"
|
||||
@email = @dossier.individual.email
|
||||
@logo_url = procedure_logo_url(@dossier.procedure)
|
||||
|
||||
mail(subject: @subject, to: @email, template_name: 'send_notification_for_tiers')
|
||||
end
|
||||
|
||||
def self.send_en_construction_notification(dossier)
|
||||
with(dossier: dossier, state: Dossier.states.fetch(:en_construction)).send_notification
|
||||
end
|
||||
|
|
|
@ -895,6 +895,7 @@ class Dossier < ApplicationRecord
|
|||
save!
|
||||
MailTemplatePresenterService.create_commentaire_for_state(self, Dossier.states.fetch(:en_construction))
|
||||
NotificationMailer.send_en_construction_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
procedure.compute_dossiers_count
|
||||
RoutingEngine.compute(self)
|
||||
end
|
||||
|
@ -927,6 +928,7 @@ class Dossier < ApplicationRecord
|
|||
MailTemplatePresenterService.create_commentaire_for_state(self, Dossier.states.fetch(:en_instruction))
|
||||
if !disable_notification
|
||||
NotificationMailer.send_en_instruction_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
end
|
||||
log_dossier_operation(instructeur, :passer_en_instruction)
|
||||
end
|
||||
|
@ -943,6 +945,7 @@ class Dossier < ApplicationRecord
|
|||
save!
|
||||
MailTemplatePresenterService.create_commentaire_for_state(self, Dossier.states.fetch(:en_instruction))
|
||||
NotificationMailer.send_en_instruction_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
|
||||
if procedure.sva_svr_enabled?
|
||||
# TODO: handle serialization errors when SIRET demandeur was not completed
|
||||
|
@ -1020,6 +1023,7 @@ class Dossier < ApplicationRecord
|
|||
MailTemplatePresenterService.create_commentaire_for_state(self, Dossier.states.fetch(:accepte))
|
||||
if !disable_notification
|
||||
NotificationMailer.send_accepte_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
end
|
||||
send_dossier_decision_to_experts(self)
|
||||
log_dossier_operation(instructeur, :accepter, self)
|
||||
|
@ -1045,6 +1049,7 @@ class Dossier < ApplicationRecord
|
|||
remove_titres_identite!
|
||||
MailTemplatePresenterService.create_commentaire_for_state(self, Dossier.states.fetch(:accepte))
|
||||
NotificationMailer.send_accepte_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
log_automatic_dossier_operation(:accepter, self)
|
||||
end
|
||||
|
||||
|
@ -1070,6 +1075,7 @@ class Dossier < ApplicationRecord
|
|||
|
||||
if !disable_notification
|
||||
NotificationMailer.send_refuse_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
end
|
||||
send_dossier_decision_to_experts(self)
|
||||
log_dossier_operation(instructeur, :refuser, self)
|
||||
|
@ -1089,6 +1095,7 @@ class Dossier < ApplicationRecord
|
|||
remove_titres_identite!
|
||||
MailTemplatePresenterService.create_commentaire_for_state(self, Dossier.states.fetch(:refuse))
|
||||
NotificationMailer.send_refuse_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
log_automatic_dossier_operation(:refuser, self)
|
||||
end
|
||||
|
||||
|
@ -1114,6 +1121,7 @@ class Dossier < ApplicationRecord
|
|||
|
||||
if !disable_notification
|
||||
NotificationMailer.send_sans_suite_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
end
|
||||
send_dossier_decision_to_experts(self)
|
||||
log_dossier_operation(instructeur, :classer_sans_suite, self)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
- content_for :procedure_logo do
|
||||
= render 'layouts/mailers/logo', url: @logo_url
|
||||
|
||||
%p
|
||||
Bonjour,
|
||||
|
||||
%p= "#{ t("instructeurs.dossiers.decisions_rendues_block.without_email.#{@dossier.state}", processed_at: l(@dossier.updated_at.to_date))}."
|
||||
|
||||
%p= "Le dossier nº #{@dossier.id} est rempli en votre nom par #{@dossier.mandataire_first_name} #{@dossier.mandataire_last_name} sur la procédure #{@dossier.procedure.libelle}."
|
||||
|
||||
%p= "Pour en savoir plus, veuillez vous rapprocher #{mail_to(@dossier.user.email)}."
|
||||
|
||||
%p
|
||||
= t(:best_regards, scope: [:views, :shared, :greetings])
|
||||
%br
|
||||
= t('layouts.mailers.signature.team')
|
||||
#{APPLICATION_NAME.gsub(".","⁠.").html_safe}
|
|
@ -7,6 +7,8 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
let(:instructeurs) { [instructeur] }
|
||||
let(:procedure) { create(:procedure, :published, :for_individual, instructeurs: instructeurs) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
|
||||
let(:dossier_for_tiers) { create(:dossier, :en_construction, :for_tiers_with_notification, procedure: procedure) }
|
||||
let(:dossier_for_tiers_without_notif) { create(:dossier, :en_construction, :for_tiers_without_notification, procedure: procedure) }
|
||||
let(:fake_justificatif) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
|
||||
|
||||
before { sign_in(instructeur.user) }
|
||||
|
@ -333,6 +335,58 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context "with for_tiers" do
|
||||
before do
|
||||
dossier_for_tiers.passer_en_instruction!(instructeur: instructeur)
|
||||
sign_in(instructeur.user)
|
||||
end
|
||||
context 'without continuation' do
|
||||
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier_for_tiers.id }, format: :turbo_stream }
|
||||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:send_sans_suite_notification)
|
||||
.with(dossier_for_tiers).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_later)
|
||||
|
||||
expect(NotificationMailer).to receive(:send_notification_for_tiers)
|
||||
.with(dossier_for_tiers).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_later)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it '2 emails are sent' do
|
||||
expect { perform_enqueued_jobs { subject } }.to change { ActionMailer::Base.deliveries.count }.by(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with for_tiers_without_notif" do
|
||||
before do
|
||||
dossier_for_tiers_without_notif.passer_en_instruction!(instructeur: instructeur)
|
||||
sign_in(instructeur.user)
|
||||
end
|
||||
context 'without continuation' do
|
||||
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier_for_tiers_without_notif.id }, format: :turbo_stream }
|
||||
|
||||
it 'Notification email is sent' do
|
||||
expect(NotificationMailer).to receive(:send_sans_suite_notification)
|
||||
.with(dossier_for_tiers_without_notif).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_later)
|
||||
|
||||
expect(NotificationMailer).to receive(:send_notification_for_tiers)
|
||||
.with(dossier_for_tiers_without_notif).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_later)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it 'only one email is sent' do
|
||||
expect { perform_enqueued_jobs { subject } }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with classer_sans_suite" do
|
||||
before do
|
||||
dossier.passer_en_instruction!(instructeur: instructeur)
|
||||
|
@ -354,6 +408,9 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
.with(dossier).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_later)
|
||||
|
||||
expect(NotificationMailer).not_to receive(:send_notification_for_tiers)
|
||||
.with(dossier)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
|
|
|
@ -43,6 +43,40 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :for_tiers_with_notification do
|
||||
for_tiers { true }
|
||||
mandataire_first_name { 'John' }
|
||||
mandataire_last_name { 'Doe' }
|
||||
|
||||
transient do
|
||||
for_individual? { true }
|
||||
end
|
||||
|
||||
after(:build) do |dossier, _evaluator|
|
||||
if !dossier.procedure.for_individual?
|
||||
raise 'Inconsistent factory: attempting to create a dossier :with_individual on a procedure that is not `for_individual?`'
|
||||
end
|
||||
dossier.individual = build(:individual, :with_notification, dossier: dossier)
|
||||
end
|
||||
end
|
||||
|
||||
trait :for_tiers_without_notification do
|
||||
for_tiers { true }
|
||||
mandataire_first_name { 'John' }
|
||||
mandataire_last_name { 'Doe' }
|
||||
|
||||
transient do
|
||||
for_individual? { true }
|
||||
end
|
||||
|
||||
after(:build) do |dossier, _evaluator|
|
||||
if !dossier.procedure.for_individual?
|
||||
raise 'Inconsistent factory: attempting to create a dossier :with_individual on a procedure that is not `for_individual?`'
|
||||
end
|
||||
dossier.individual = build(:individual, :without_notification, dossier: dossier)
|
||||
end
|
||||
end
|
||||
|
||||
trait :with_individual do
|
||||
transient do
|
||||
for_individual? { true }
|
||||
|
|
|
@ -12,5 +12,14 @@ FactoryBot.define do
|
|||
prenom { nil }
|
||||
birthdate { nil }
|
||||
end
|
||||
|
||||
trait :with_notification do
|
||||
notification_method { :email }
|
||||
email { 'julien.xavier@test.com' }
|
||||
end
|
||||
|
||||
trait :without_notification do
|
||||
notification_method { :no_notification }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,6 +19,10 @@ class NotificationMailerPreview < ActionMailer::Preview
|
|||
NotificationMailer.send_sans_suite_notification(dossier)
|
||||
end
|
||||
|
||||
def send_notification_for_tiers
|
||||
NotificationMailer.send_notification_for_tiers(dossier)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossier
|
||||
|
|
Loading…
Reference in a new issue