diff --git a/app/controllers/champs/piece_justificative_controller.rb b/app/controllers/champs/piece_justificative_controller.rb index 587ef6f4e..45cc6a848 100644 --- a/app/controllers/champs/piece_justificative_controller.rb +++ b/app/controllers/champs/piece_justificative_controller.rb @@ -30,8 +30,14 @@ class Champs::PieceJustificativeController < Champs::ChampController save_succeed = @champ.save end - @champ.dossier.update(last_champ_updated_at: Time.zone.now.utc) if save_succeed + if save_succeed && dossier.brouillon? + dossier.touch(:last_champ_updated_at, :last_champ_piece_jointe_updated_at) + end save_succeed end + + def dossier + @champ.dossier + end end diff --git a/app/controllers/concerns/create_avis_concern.rb b/app/controllers/concerns/create_avis_concern.rb index 4c35668f3..a39fe52e0 100644 --- a/app/controllers/concerns/create_avis_concern.rb +++ b/app/controllers/concerns/create_avis_concern.rb @@ -57,7 +57,7 @@ module CreateAvisConcern persisted, failed = create_results.partition(&:persisted?) if persisted.any? - dossier.update!(last_avis_updated_at: Time.zone.now) + dossier.touch(:last_avis_updated_at) sent_emails_addresses = [] persisted.each do |avis| avis.dossier.demander_un_avis!(avis) diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index ef1304a36..fb581ccbc 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -250,7 +250,7 @@ module Instructeurs if commentaire.valid? dossier.flag_as_pending_correction!(commentaire, params[:reason].presence) - dossier.update!(last_commentaire_updated_at: Time.zone.now) + dossier.touch(:last_commentaire_updated_at) current_instructeur.follow(dossier) flash.notice = "Dossier marqué comme en attente de correction." @@ -275,7 +275,7 @@ module Instructeurs @commentaire = CommentaireService.create(current_instructeur, dossier, commentaire_params) if @commentaire.errors.empty? - @commentaire.dossier.update!(last_commentaire_updated_at: Time.zone.now) + @commentaire.dossier.touch(:last_commentaire_updated_at) current_instructeur.follow(dossier) flash.notice = "Message envoyé" redirect_to messagerie_instructeur_dossier_path(procedure, dossier) @@ -300,7 +300,7 @@ module Instructeurs def update_annotations dossier_with_champs.update_champs_attributes(champs_private_attributes_params, :private, updated_by: current_user.email) if dossier.champs.any?(&:changed_for_autosave?) - dossier.last_champ_private_updated_at = Time.zone.now + dossier.touch(:last_champ_private_updated_at) end dossier.save(context: :champs_private_value) diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index c563d87c7..5c7e2011e 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -237,7 +237,7 @@ module Instructeurs dossiers.each do |dossier| commentaire = CommentaireService.create(current_instructeur, dossier, bulk_message_params.except(:targets)) if commentaire.errors.empty? - commentaire.dossier.update!(last_commentaire_updated_at: Time.zone.now) + commentaire.dossier.touch(:last_commentaire_updated_at) else errors << dossier.id end