feat(gallery): add attachments from commentaires from experts

This commit is contained in:
Eric Leroy-Terquem 2024-10-10 10:20:47 +02:00
parent ad98bafeca
commit 2e2d2afecb
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
3 changed files with 20 additions and 2 deletions

View file

@ -30,6 +30,8 @@ class Attachment::GalleryItemComponent < ApplicationComponent
case case
when from_dossier? when from_dossier?
'Dossier usager' 'Dossier usager'
when from_messagerie_expert?
'Messagerie (expert)'
when from_messagerie_instructeur? when from_messagerie_instructeur?
'Messagerie (instructeur)' 'Messagerie (instructeur)'
when from_messagerie_usager? when from_messagerie_usager?
@ -90,8 +92,12 @@ class Attachment::GalleryItemComponent < ApplicationComponent
from_messagerie? && attachment.record.instructeur.present? from_messagerie? && attachment.record.instructeur.present?
end end
def from_messagerie_expert?
from_messagerie? && attachment.record.expert.present?
end
def from_messagerie_usager? def from_messagerie_usager?
from_messagerie? && attachment.record.instructeur.nil? from_messagerie? && attachment.record.instructeur.nil? && attachment.record.expert.nil?
end end
def from_avis_externe? def from_avis_externe?

View file

@ -167,7 +167,11 @@ module Experts
@commentaire = CommentaireService.create(current_expert, avis.dossier, commentaire_params) @commentaire = CommentaireService.create(current_expert, avis.dossier, commentaire_params)
if @commentaire.errors.empty? 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é" flash.notice = "Message envoyé"
redirect_to messagerie_expert_avis_path(avis.procedure, avis) redirect_to messagerie_expert_avis_path(avis.procedure, avis)
else else

View file

@ -100,6 +100,14 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do
expect(subject).to have_text('Messagerie (instructeur)') expect(subject).to have_text('Messagerie (instructeur)')
end end
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 end
context "when attachment is from an avis" do context "when attachment is from an avis" do