Envoie un email à l'expert en cas de nouveau commentaire de l'usager dans la messagerie
This commit is contained in:
parent
6253188a77
commit
ac29cfbfdb
7 changed files with 71 additions and 5 deletions
|
@ -314,11 +314,7 @@ module Users
|
|||
|
||||
if @commentaire.errors.empty?
|
||||
@commentaire.dossier.update!(last_commentaire_updated_at: Time.zone.now)
|
||||
dossier.followers_instructeurs
|
||||
.with_instant_email_message_notifications
|
||||
.each do |instructeur|
|
||||
DossierMailer.notify_new_commentaire_to_instructeur(dossier, instructeur.email).deliver_later
|
||||
end
|
||||
|
||||
flash.notice = t('.message_send')
|
||||
redirect_to messagerie_dossier_path(dossier)
|
||||
else
|
||||
|
|
|
@ -20,6 +20,17 @@ class AvisMailer < ApplicationMailer
|
|||
end
|
||||
end
|
||||
|
||||
# i18n-tasks-use t("avis_mailer.#{action}.subject")
|
||||
def notify_new_commentaire_to_expert(dossier, avis, expert)
|
||||
I18n.with_locale(dossier.user_locale) do
|
||||
@dossier = dossier
|
||||
@avis = avis
|
||||
@subject = default_i18n_subject(dossier_id: dossier.id, libelle_demarche: dossier.procedure.libelle)
|
||||
|
||||
mail(to: expert.email, subject: @subject)
|
||||
end
|
||||
end
|
||||
|
||||
def self.critical_email?(action_name)
|
||||
false
|
||||
end
|
||||
|
|
|
@ -97,6 +97,8 @@ class Commentaire < ApplicationRecord
|
|||
# - Otherwise, a instructeur posted a commentaire, we need to notify the user
|
||||
if sent_by_instructeur? || sent_by_expert?
|
||||
notify_user(wait: 5.minutes)
|
||||
elsif !sent_by_system?
|
||||
notify_administration
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -108,6 +110,26 @@ class Commentaire < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def notify_administration
|
||||
dossier.followers_instructeurs
|
||||
.with_instant_email_message_notifications
|
||||
.find_each do |instructeur|
|
||||
DossierMailer.notify_new_commentaire_to_instructeur(dossier, instructeur.email).deliver_later
|
||||
end
|
||||
|
||||
experts_contactes = Set.new
|
||||
|
||||
dossier.avis.includes(:expert).find_each do |avis|
|
||||
if avis.expert.present?
|
||||
expert_id = avis.expert.id
|
||||
if !experts_contactes.include?(expert_id)
|
||||
AvisMailer.notify_new_commentaire_to_expert(dossier, avis, avis.expert).deliver_later
|
||||
experts_contactes.add(expert_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def messagerie_available?
|
||||
return if sent_by_system?
|
||||
if dossier.present? && !dossier.messagerie_available?
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
- content_for(:title, "#{@subject}")
|
||||
|
||||
%p= t(:hello, scope: [:views, :shared, :greetings])
|
||||
|
||||
%p
|
||||
= t('.body', dossier_id: @dossier.id, libelle_demarche: @dossier.procedure.libelle)
|
||||
%p= link_to("Messagerie du dossier n°#{@dossier.id}", messagerie_expert_avis_url(procedure_id: @dossier.procedure.id, id: @avis.id))
|
||||
|
||||
= render partial: "layouts/mailers/signature"
|
|
@ -0,0 +1,5 @@
|
|||
en:
|
||||
avis_mailer:
|
||||
notify_new_commentaire_to_expert:
|
||||
subject: New comment posted on the file n°%{dossier_id}
|
||||
body: A new comment has been submitted by the user on file number %{dossier_id} on the file %{libelle_demarche}
|
|
@ -0,0 +1,5 @@
|
|||
fr:
|
||||
avis_mailer:
|
||||
notify_new_commentaire_to_expert:
|
||||
subject: Nouveau commentaire déposé sur le dossier n°%{dossier_id}
|
||||
body: Un nouveau commentaire a été déposé par l’usager sur le dossier n° %{dossier_id} de la démarche %{libelle_demarche}
|
|
@ -1179,6 +1179,24 @@ describe Users::DossiersController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'email notification to experts' do
|
||||
let(:expert) { create(:expert) }
|
||||
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
|
||||
let(:avis) { create(:avis, dossier: dossier, claimant: instructeur_with_instant_message, experts_procedure: experts_procedure) }
|
||||
let(:avis2) { create(:avis, dossier: dossier, claimant: instructeur_with_instant_message, experts_procedure: experts_procedure) }
|
||||
|
||||
before do
|
||||
allow(AvisMailer).to receive(:notify_new_commentaire_to_expert).and_return(double(deliver_later: nil))
|
||||
avis
|
||||
avis2
|
||||
subject
|
||||
end
|
||||
|
||||
it 'sends just one email to the expert linked to several avis on the same dossier' do
|
||||
expect(AvisMailer).to have_received(:notify_new_commentaire_to_expert).with(dossier, avis, expert).once
|
||||
end
|
||||
end
|
||||
|
||||
context 'notification' do
|
||||
before 'instructeurs have no notification before the message' do
|
||||
expect(instructeur_with_instant_message.followed_dossiers.with_notifications).to eq([])
|
||||
|
|
Loading…
Reference in a new issue