Envoie un email à l'expert en cas de nouveau commentaire de l'usager dans la messagerie

This commit is contained in:
Kara Diaby 2024-01-03 12:23:48 +00:00
parent 6253188a77
commit ac29cfbfdb
7 changed files with 71 additions and 5 deletions

View file

@ -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

View file

@ -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

View file

@ -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?

View file

@ -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"