From ad98bafecacba2e8ca7c6ee2e795459b391a9f88 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 10 Oct 2024 09:41:28 +0200 Subject: [PATCH] feat(gallery): notify instructeur if pieces jointes added in avis --- app/controllers/experts/avis_controller.rb | 7 ++++++- app/models/dossier.rb | 3 ++- app/models/instructeur.rb | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/experts/avis_controller.rb b/app/controllers/experts/avis_controller.rb index f05d6d411..6d9d737e8 100644 --- a/app/controllers/experts/avis_controller.rb +++ b/app/controllers/experts/avis_controller.rb @@ -104,7 +104,12 @@ module Experts updated_recently = @avis.updated_recently? if @avis.update(avis_params) flash.notice = 'Votre réponse est enregistrée.' - @avis.dossier.update!(last_avis_updated_at: Time.zone.now) + + timestamps = [:last_avis_updated_at, :updated_at] + timestamps << :last_avis_piece_jointe_updated_at if @avis.piece_justificative_file.attached? + + @avis.dossier.touch(*timestamps) + if !updated_recently @avis.dossier.followers_instructeurs .with_instant_expert_avis_email_notifications_enabled diff --git a/app/models/dossier.rb b/app/models/dossier.rb index d27b7e9ad..d4586e55d 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -378,7 +378,8 @@ class Dossier < ApplicationRecord ' OR last_avis_updated_at > follows.avis_seen_at' \ ' OR last_commentaire_updated_at > follows.messagerie_seen_at' \ ' OR last_commentaire_piece_jointe_updated_at > follows.pieces_jointes_seen_at' \ - ' OR last_champ_piece_jointe_updated_at > follows.pieces_jointes_seen_at') + ' OR last_champ_piece_jointe_updated_at > follows.pieces_jointes_seen_at' \ + ' OR last_avis_piece_jointe_updated_at > follows.pieces_jointes_seen_at') .distinct end diff --git a/app/models/instructeur.rb b/app/models/instructeur.rb index 6c9f388af..b84e2c3b7 100644 --- a/app/models/instructeur.rb +++ b/app/models/instructeur.rb @@ -125,7 +125,7 @@ class Instructeur < ApplicationRecord annotations_privees = dossier.last_champ_private_updated_at&.>(follow.annotations_privees_seen_at) || false avis_notif = dossier.last_avis_updated_at&.>(follow.avis_seen_at) || false messagerie = dossier.last_commentaire_updated_at&.>(follow.messagerie_seen_at) || false - pieces_jointes = dossier.last_champ_piece_jointe_updated_at&.>(follow.pieces_jointes_seen_at) || dossier.last_commentaire_piece_jointe_updated_at&.>(follow.pieces_jointes_seen_at) || false + pieces_jointes = dossier.last_champ_piece_jointe_updated_at&.>(follow.pieces_jointes_seen_at) || dossier.last_commentaire_piece_jointe_updated_at&.>(follow.pieces_jointes_seen_at) || dossier.last_avis_piece_jointe_updated_at&.>(follow.pieces_jointes_seen_at) || false annotations_hash(demande, annotations_privees, avis_notif, messagerie, pieces_jointes) else