From efef61c34cbc4500ff2ea8fa700a8c0f01e58529 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 10 Oct 2024 11:17:02 +0200 Subject: [PATCH] feat(gallery): add attachments from justificatif motivation --- .../attachment/gallery_item_component.rb | 8 ++++++++ .../gallery_item_component.html.haml | 4 ++-- .../instructeurs/dossiers_controller.rb | 7 ++++++- .../concerns/blob_image_processor_concern.rb | 6 +++++- .../attachment/gallery_item_component_spec.rb | 14 ++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/app/components/attachment/gallery_item_component.rb b/app/components/attachment/gallery_item_component.rb index e3d4f86e3..5c4cb8233 100644 --- a/app/components/attachment/gallery_item_component.rb +++ b/app/components/attachment/gallery_item_component.rb @@ -23,6 +23,8 @@ class Attachment::GalleryItemComponent < ApplicationComponent 'Pièce jointe au message' elsif from_avis_externe? 'Pièce jointe à l’avis' + elsif from_justificatif_motivation? + 'Pièce jointe à la décision' end end @@ -42,6 +44,8 @@ class Attachment::GalleryItemComponent < ApplicationComponent 'Avis externe (instructeur)' when from_avis_externe_expert? 'Avis externe (expert)' + when from_justificatif_motivation? + 'Justificatif de décision' end end @@ -121,4 +125,8 @@ class Attachment::GalleryItemComponent < ApplicationComponent def from_avis_externe_expert? from_avis_externe? && attachment.name == 'piece_justificative_file' end + + def from_justificatif_motivation? + attachment.name == 'justificatif_motivation' + end end diff --git a/app/components/attachment/gallery_item_component/gallery_item_component.html.haml b/app/components/attachment/gallery_item_component/gallery_item_component.html.haml index 2428d5822..74fa9f176 100644 --- a/app/components/attachment/gallery_item_component/gallery_item_component.html.haml +++ b/app/components/attachment/gallery_item_component/gallery_item_component.html.haml @@ -9,7 +9,7 @@ Visualiser - if !gallery_demande? .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?) - if !gallery_demande? .fr-mt-2v.fr-mb-2v{ class: badge_updated_class } @@ -19,7 +19,7 @@ = image_tag('apercu-indisponible.png') - if !gallery_demande? .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?) - if !gallery_demande? .fr-mt-2v.fr-mb-2v{ class: badge_updated_class } diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index 58e911b29..ef1304a36 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -522,7 +522,12 @@ module Instructeurs .compact .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 @gallery_attachments = ActiveStorage::Attachment.where(id: gallery_attachments_ids) end diff --git a/app/models/concerns/blob_image_processor_concern.rb b/app/models/concerns/blob_image_processor_concern.rb index f42abeee8..7e07b17dc 100644 --- a/app/models/concerns/blob_image_processor_concern.rb +++ b/app/models/concerns/blob_image_processor_concern.rb @@ -10,7 +10,7 @@ module BlobImageProcessorConcern end 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 private @@ -38,4 +38,8 @@ module BlobImageProcessorConcern def watermark_required? attachments.any? { _1.record.class == Champs::TitreIdentiteChamp } end + + def from_justificatif_motivation? + attachments.any? { _1.name == 'justificatif_motivation' } + end end diff --git a/spec/components/attachment/gallery_item_component_spec.rb b/spec/components/attachment/gallery_item_component_spec.rb index df09db179..959c6a279 100644 --- a/spec/components/attachment/gallery_item_component_spec.rb +++ b/spec/components/attachment/gallery_item_component_spec.rb @@ -145,6 +145,20 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do 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 'from an instructeur' do let(:avis) { create(:avis, :with_introduction, dossier: dossier) }