Merge pull request #6078 from betagouv/feat/5815

ETQ instructeur, lorsque je termine un dossier, les experts notifiable recoivent un mail leur indiquant qu'une nouveauté est présente
This commit is contained in:
Kara Diaby 2021-04-15 11:42:29 +02:00 committed by GitHub
commit 22a14701a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 0 deletions

View file

@ -0,0 +1,24 @@
class ExpertMailer < ApplicationMailer
helper MailerHelper
layout 'mailers/layout'
def send_dossier_decision(avis_id)
@avis = Avis.eager_load(:dossier).find(avis_id)
@dossier = @avis.dossier
email = @avis.expert.email
@decision = decision_dossier(@dossier)
subject = "Dossier n° #{@dossier.id} a été #{@decision} - #{@dossier.procedure.libelle}"
mail(to: email, subject: subject)
end
end
def decision_dossier(dossier)
if dossier.accepte?
'accepté'
elsif dossier.sans_suite?
'classé sans suite'
elsif dossier.refuse?
'refusé'
end
end

View file

@ -647,6 +647,7 @@ class Dossier < ApplicationRecord
save!
remove_titres_identite!
NotificationMailer.send_closed_notification(self).deliver_later
send_dossier_decision_to_experts(self)
log_dossier_operation(instructeur, :accepter, self)
end
@ -674,6 +675,7 @@ class Dossier < ApplicationRecord
save!
remove_titres_identite!
NotificationMailer.send_refused_notification(self).deliver_later
send_dossier_decision_to_experts(self)
log_dossier_operation(instructeur, :refuser, self)
end
@ -687,6 +689,7 @@ class Dossier < ApplicationRecord
save!
remove_titres_identite!
NotificationMailer.send_without_continuation_notification(self).deliver_later
send_dossier_decision_to_experts(self)
log_dossier_operation(instructeur, :classer_sans_suite, self)
end
@ -941,4 +944,21 @@ class Dossier < ApplicationRecord
DossierMailer.notify_brouillon_not_submitted(dossier).deliver_later
end
end
def send_dossier_decision_to_experts(dossier)
avis_experts_procedures_ids = Avis
.joins(:experts_procedure)
.where(dossier: dossier, experts_procedures: { allow_decision_access: true })
.with_answer
.distinct
.pluck('avis.id, experts_procedures.id')
# rubocop:disable Lint/UnusedBlockArgument
avis_ids = avis_experts_procedures_ids
.uniq { |(avis_id, experts_procedures_id)| experts_procedures_id }
.map { |(avis_id, _)| avis_id }
# rubocop:enable Lint/UnusedBlockArgument
avis_ids.each { |avis_id| ExpertMailer.send_dossier_decision(avis_id).deliver_later }
end
end

View file

@ -0,0 +1,20 @@
- avis_link = expert_avis_url(@dossier.procedure, @avis)
%p
Bonjour,
%p
Une décision a été rendue sur le dossier n°
%strong= @dossier.id
et ce dossier a préalablement reçu votre avis.
%p
Le dossier a été
= succeed '.' do
%strong= @decision
%p
Pour plus d'informations, cliquez sur le lien ci-dessous :
%p
= round_button("Voir le dossier", avis_link, :primary)
= render partial: "layouts/mailers/signature"

View file

@ -0,0 +1,11 @@
class AvisMailerPreview < ActionMailer::Preview
def send_dossier_decision
procedure = Procedure.new(libelle: 'Démarche pour faire des marches')
dossier = Dossier.new(id: 1, procedure: procedure)
instructeur = Instructeur.new(id: 1, user: User.new(email: 'jeanmichel.de-chauvigny@exemple.fr'))
expert = Expert.new(id: 1, user: User.new('moussa.kanga@exemple.fr'))
experts_procedure = ExpertsProcedure.new(expert: expert, procedure: procedure, allow_decision_access: true)
avis = Avis.new(id: 1, email: 'test@exemple.fr', dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure)
ExpertMailer.send_dossier_decision(avis.id)
end
end