diff --git a/app/components/attachment/gallery_item_component.rb b/app/components/attachment/gallery_item_component.rb index 0aa3e766f..3319ad3d9 100644 --- a/app/components/attachment/gallery_item_component.rb +++ b/app/components/attachment/gallery_item_component.rb @@ -30,6 +30,8 @@ class Attachment::GalleryItemComponent < ApplicationComponent case when from_dossier? 'Dossier usager' + when from_messagerie_expert? + 'Messagerie (expert)' when from_messagerie_instructeur? 'Messagerie (instructeur)' when from_messagerie_usager? @@ -90,8 +92,12 @@ class Attachment::GalleryItemComponent < ApplicationComponent from_messagerie? && attachment.record.instructeur.present? end + def from_messagerie_expert? + from_messagerie? && attachment.record.expert.present? + end + def from_messagerie_usager? - from_messagerie? && attachment.record.instructeur.nil? + from_messagerie? && attachment.record.instructeur.nil? && attachment.record.expert.nil? end def from_avis_externe? diff --git a/app/controllers/experts/avis_controller.rb b/app/controllers/experts/avis_controller.rb index 6d9d737e8..f994f0e50 100644 --- a/app/controllers/experts/avis_controller.rb +++ b/app/controllers/experts/avis_controller.rb @@ -167,7 +167,11 @@ module Experts @commentaire = CommentaireService.create(current_expert, avis.dossier, commentaire_params) if @commentaire.errors.empty? - @commentaire.dossier.update!(last_commentaire_updated_at: Time.zone.now) + timestamps = [:last_commentaire_updated_at, :updated_at] + timestamps << :last_commentaire_piece_jointe_updated_at if @commentaire.piece_jointe.attached? + + @commentaire.dossier.touch(*timestamps) + flash.notice = "Message envoyé" redirect_to messagerie_expert_avis_path(avis.procedure, avis) else diff --git a/spec/components/attachment/gallery_item_component_spec.rb b/spec/components/attachment/gallery_item_component_spec.rb index 172ed0574..e9fda3802 100644 --- a/spec/components/attachment/gallery_item_component_spec.rb +++ b/spec/components/attachment/gallery_item_component_spec.rb @@ -100,6 +100,14 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do expect(subject).to have_text('Messagerie (instructeur)') end end + + context 'from an expert' do + let(:expert) { create(:expert) } + before { commentaire.update!(expert:) } + it "displays the right tag" do + expect(subject).to have_text('Messagerie (expert)') + end + end end context "when attachment is from an avis" do