feat(gallery): add attachments from justificatif motivation

This commit is contained in:
Eric Leroy-Terquem 2024-10-10 11:17:02 +02:00
parent 17aaa7b32c
commit efef61c34c
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
5 changed files with 35 additions and 4 deletions

View file

@ -23,6 +23,8 @@ class Attachment::GalleryItemComponent < ApplicationComponent
'Pièce jointe au message' 'Pièce jointe au message'
elsif from_avis_externe? elsif from_avis_externe?
'Pièce jointe à lavis' 'Pièce jointe à lavis'
elsif from_justificatif_motivation?
'Pièce jointe à la décision'
end end
end end
@ -42,6 +44,8 @@ class Attachment::GalleryItemComponent < ApplicationComponent
'Avis externe (instructeur)' 'Avis externe (instructeur)'
when from_avis_externe_expert? when from_avis_externe_expert?
'Avis externe (expert)' 'Avis externe (expert)'
when from_justificatif_motivation?
'Justificatif de décision'
end end
end end
@ -121,4 +125,8 @@ class Attachment::GalleryItemComponent < ApplicationComponent
def from_avis_externe_expert? def from_avis_externe_expert?
from_avis_externe? && attachment.name == 'piece_justificative_file' from_avis_externe? && attachment.name == 'piece_justificative_file'
end end
def from_justificatif_motivation?
attachment.name == 'justificatif_motivation'
end
end end

View file

@ -9,7 +9,7 @@
Visualiser Visualiser
- if !gallery_demande? - if !gallery_demande?
.fr-text--sm.fr-mt-2v.fr-mb-1v .fr-text--sm.fr-mt-2v.fr-mb-1v
= libelle.truncate(25) = libelle.truncate(30)
= render Attachment::ShowComponent.new(attachment:, truncate: true, new_tab: gallery_demande?) = render Attachment::ShowComponent.new(attachment:, truncate: true, new_tab: gallery_demande?)
- if !gallery_demande? - if !gallery_demande?
.fr-mt-2v.fr-mb-2v{ class: badge_updated_class } .fr-mt-2v.fr-mb-2v{ class: badge_updated_class }
@ -19,7 +19,7 @@
= image_tag('apercu-indisponible.png') = image_tag('apercu-indisponible.png')
- if !gallery_demande? - if !gallery_demande?
.fr-text--sm.fr-mt-2v.fr-mb-1v .fr-text--sm.fr-mt-2v.fr-mb-1v
= libelle.truncate(25) = libelle.truncate(30)
= render Attachment::ShowComponent.new(attachment:, truncate: true, new_tab: gallery_demande?) = render Attachment::ShowComponent.new(attachment:, truncate: true, new_tab: gallery_demande?)
- if !gallery_demande? - if !gallery_demande?
.fr-mt-2v.fr-mb-2v{ class: badge_updated_class } .fr-mt-2v.fr-mb-2v{ class: badge_updated_class }

View file

@ -522,7 +522,12 @@ module Instructeurs
.compact .compact
.map(&:id) .map(&:id)
champs_attachments_ids + commentaires_attachments_ids + avis_attachments_ids justificatif_motivation_id = dossier
.justificatif_motivation
&.attachment
&.id
champs_attachments_ids + commentaires_attachments_ids + avis_attachments_ids + [justificatif_motivation_id]
end end
@gallery_attachments = ActiveStorage::Attachment.where(id: gallery_attachments_ids) @gallery_attachments = ActiveStorage::Attachment.where(id: gallery_attachments_ids)
end end

View file

@ -10,7 +10,7 @@ module BlobImageProcessorConcern
end end
def representation_required? def representation_required?
from_champ? || from_messagerie? || logo? || from_action_text? || from_avis? from_champ? || from_messagerie? || logo? || from_action_text? || from_avis? || from_justificatif_motivation?
end end
private private
@ -38,4 +38,8 @@ module BlobImageProcessorConcern
def watermark_required? def watermark_required?
attachments.any? { _1.record.class == Champs::TitreIdentiteChamp } attachments.any? { _1.record.class == Champs::TitreIdentiteChamp }
end end
def from_justificatif_motivation?
attachments.any? { _1.name == 'justificatif_motivation' }
end
end end

View file

@ -145,6 +145,20 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do
end end
end end
context "when attachment is from a justificatif motivation" do
let(:fake_justificatif) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
let(:attachment) { dossier.justificatif_motivation.attachment }
before { dossier.update!(justificatif_motivation: fake_justificatif) }
it "displays a generic libelle, link, tag and renders title" do
expect(subject).to have_text('Justificatif de décision')
expect(subject).to have_link(filename)
expect(subject).to have_text('Pièce jointe à la décision')
expect(component.title).to eq("Pièce jointe à la décision -- #{filename}")
end
end
context "when attachment is from an avis" do context "when attachment is from an avis" do
context 'from an instructeur' do context 'from an instructeur' do
let(:avis) { create(:avis, :with_introduction, dossier: dossier) } let(:avis) { create(:avis, :with_introduction, dossier: dossier) }