create AR email and send it at the right time
This commit is contained in:
parent
ee91f47c5a
commit
ae08044ff2
|
@ -6,7 +6,7 @@
|
|||
# The subject and body of a Notification can be customized by each demarche.
|
||||
#
|
||||
class NotificationMailer < ApplicationMailer
|
||||
before_action :set_dossier, except: [:send_notification_for_tiers]
|
||||
before_action :set_dossier, except: [:send_notification_for_tiers, :send_accuse_lecture_notification]
|
||||
before_action :set_services_publics_plus, only: :send_notification
|
||||
|
||||
helper ServiceHelper
|
||||
|
@ -42,6 +42,16 @@ class NotificationMailer < ApplicationMailer
|
|||
mail(subject: @subject, to: @email, template_name: 'send_notification_for_tiers')
|
||||
end
|
||||
|
||||
def send_accuse_lecture_notification(dossier)
|
||||
@dossier = dossier
|
||||
@subject = "La décision a été rendue pour votre démarche #{@dossier.procedure.libelle.truncate_words(50)}"
|
||||
@email = @dossier.user_email_for(:notification)
|
||||
|
||||
@logo_url = procedure_logo_url(@dossier.procedure)
|
||||
|
||||
mail(subject: @subject, to: @email, template_name: 'send_accuse_lecture_notification')
|
||||
end
|
||||
|
||||
def self.send_en_construction_notification(dossier)
|
||||
with(dossier: dossier, state: Dossier.states.fetch(:en_construction)).send_notification
|
||||
end
|
||||
|
|
|
@ -120,8 +120,12 @@ module DossierStateConcern
|
|||
disable_notification = h.fetch(:disable_notification, false)
|
||||
|
||||
if !disable_notification
|
||||
NotificationMailer.send_accepte_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
if procedure.accuse_lecture?
|
||||
NotificationMailer.send_accuse_lecture_notification(self).deliver_later
|
||||
else
|
||||
NotificationMailer.send_accepte_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
end
|
||||
end
|
||||
|
||||
send_dossier_decision_to_experts(self)
|
||||
|
@ -152,8 +156,12 @@ module DossierStateConcern
|
|||
end
|
||||
|
||||
def after_commit_accepter_automatiquement
|
||||
NotificationMailer.send_accepte_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
if procedure.accuse_lecture?
|
||||
NotificationMailer.send_accuse_lecture_notification(self).deliver_later
|
||||
else
|
||||
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)
|
||||
remove_titres_identite!
|
||||
|
@ -184,8 +192,12 @@ module DossierStateConcern
|
|||
disable_notification = h.fetch(:disable_notification, false)
|
||||
|
||||
if !disable_notification
|
||||
NotificationMailer.send_refuse_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
if procedure.accuse_lecture?
|
||||
NotificationMailer.send_accuse_lecture_notification(self).deliver_later
|
||||
else
|
||||
NotificationMailer.send_refuse_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
end
|
||||
end
|
||||
|
||||
send_dossier_decision_to_experts(self)
|
||||
|
@ -209,8 +221,12 @@ module DossierStateConcern
|
|||
end
|
||||
|
||||
def after_commit_refuser_automatiquement
|
||||
NotificationMailer.send_refuse_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
if procedure.accuse_lecture?
|
||||
NotificationMailer.send_accuse_lecture_notification(self).deliver_later
|
||||
else
|
||||
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)
|
||||
remove_titres_identite!
|
||||
|
@ -241,8 +257,12 @@ module DossierStateConcern
|
|||
disable_notification = h.fetch(:disable_notification, false)
|
||||
|
||||
if !disable_notification
|
||||
NotificationMailer.send_sans_suite_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
if procedure.accuse_lecture?
|
||||
NotificationMailer.send_accuse_lecture_notification(self).deliver_later
|
||||
else
|
||||
NotificationMailer.send_sans_suite_notification(self).deliver_later
|
||||
NotificationMailer.send_notification_for_tiers(self).deliver_later if self.for_tiers?
|
||||
end
|
||||
end
|
||||
|
||||
send_dossier_decision_to_experts(self)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
- content_for :procedure_logo do
|
||||
= render 'layouts/mailers/logo', url: @logo_url
|
||||
|
||||
%p
|
||||
= t("layouts.mailers.accuse_lecture.good_morning")
|
||||
|
||||
%p
|
||||
= t("layouts.mailers.accuse_lecture.first_part",
|
||||
dossier_id: number_with_delimiter(@dossier.id))
|
||||
|
||||
%span{ :style => "font-weight: bold;" }
|
||||
= @dossier.procedure.libelle
|
||||
|
||||
= t("layouts.mailers.accuse_lecture.second_part")
|
||||
%p
|
||||
= t("layouts.mailers.accuse_lecture.third_part")
|
||||
= link_to 'Démarches Simplifiées.', dossier_url(@dossier)
|
||||
|
||||
%p
|
||||
= t(:best_regards, scope: [:views, :shared, :greetings])
|
||||
%br
|
||||
= t('layouts.mailers.signature.team')
|
||||
#{APPLICATION_NAME.gsub(".","⁠.").html_safe}
|
|
@ -25,5 +25,11 @@ fr:
|
|||
accepte: a été accepté le %{processed_at}.
|
||||
refuse: a été refusé le %{processed_at}.
|
||||
sans_suite: a été classé sans suite le %{processed_at}.
|
||||
accuse_lecture:
|
||||
good_morning: Bonjour,
|
||||
first_part: Nous vous informons qu'une décision sur le dossier nº %{dossier_id} de la démarche
|
||||
second_part: a été rendue.
|
||||
third_part: Pour en connaitre la nature, veuillez vous connecter à votre compte
|
||||
|
||||
commentaire_groupe_gestionnaire_footer:
|
||||
do_not_reply_html: Merci de ne pas répondre à cet email. Consultez votre message sur %{application_name} ou contactez votre expéditeur par <a href="mailto:%{sender_email}">mail</a>
|
||||
|
|
|
@ -6,7 +6,9 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
let(:administration) { create(:administration) }
|
||||
let(:instructeurs) { [instructeur] }
|
||||
let(:procedure) { create(:procedure, :published, :for_individual, instructeurs: instructeurs) }
|
||||
let(:procedure_accuse_lecture) { create(:procedure, :published, :for_individual, :accuse_lecture, instructeurs: instructeurs) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
|
||||
let(:dossier_accuse_lecture) { create(:dossier, :en_construction, :with_individual, procedure: procedure_accuse_lecture) }
|
||||
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') }
|
||||
|
@ -376,6 +378,29 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context "with accuse de lecture procedure" do
|
||||
before do
|
||||
dossier_accuse_lecture.passer_en_instruction!(instructeur: instructeur)
|
||||
sign_in(instructeur.user)
|
||||
end
|
||||
context 'with classer_sans_suite' do
|
||||
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure_accuse_lecture.id, dossier_id: dossier_accuse_lecture.id }, format: :turbo_stream }
|
||||
|
||||
it 'Notification accuse de lecture email is sent and not the others' do
|
||||
expect(NotificationMailer).to receive(:send_accuse_lecture_notification)
|
||||
.with(dossier_accuse_lecture).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_later)
|
||||
|
||||
expect(NotificationMailer).not_to receive(:send_sans_suite_notification)
|
||||
.with(dossier_accuse_lecture)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(subject.body).to include('header-top') }
|
||||
end
|
||||
end
|
||||
|
||||
context "with classer_sans_suite" do
|
||||
before do
|
||||
dossier.passer_en_instruction!(instructeur: instructeur)
|
||||
|
|
|
@ -283,6 +283,10 @@ FactoryBot.define do
|
|||
referentiel_de_programmation: { c: 3 })
|
||||
end
|
||||
end
|
||||
|
||||
trait :accuse_lecture do
|
||||
accuse_lecture { true }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -29,6 +29,15 @@ RSpec.describe NotificationMailer, type: :mailer do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'send_accuse_lecture_notification' do
|
||||
let(:dossier) { create(:dossier, :en_construction, procedure: create(:procedure, :accuse_lecture)) }
|
||||
|
||||
subject { described_class.send_accuse_lecture_notification(dossier) }
|
||||
|
||||
it { expect(subject.subject).to include("La décision a été rendue pour votre démarche #{dossier.procedure.libelle}") }
|
||||
it { expect(subject.body).to include("Pour en connaitre la nature, veuillez vous connecter à votre compte\r\n<a href=\"#{dossier_url(dossier)}\">demarches-simplifiees.fr</a>") }
|
||||
end
|
||||
|
||||
describe 'send_en_construction_notification' do
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, user: user, procedure:) }
|
||||
|
||||
|
|
|
@ -23,6 +23,10 @@ class NotificationMailerPreview < ActionMailer::Preview
|
|||
NotificationMailer.send_notification_for_tiers(dossier)
|
||||
end
|
||||
|
||||
def send_accuse_lecture_notification
|
||||
NotificationMailer.send_accuse_lecture_notification(dossier)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossier
|
||||
|
|
Loading…
Reference in a new issue