feat(gallery): add attachments from avis
This commit is contained in:
parent
e95e86faae
commit
d10df6e17c
5 changed files with 99 additions and 8 deletions
|
@ -17,7 +17,13 @@ class Attachment::GalleryItemComponent < ApplicationComponent
|
|||
def gallery_demande? = @gallery_demande
|
||||
|
||||
def libelle
|
||||
from_dossier? ? attachment.record.libelle : 'Pièce jointe au message'
|
||||
if from_dossier?
|
||||
attachment.record.libelle
|
||||
elsif from_messagerie?
|
||||
'Pièce jointe au message'
|
||||
elsif from_avis_externe?
|
||||
'Pièce jointe à l’avis'
|
||||
end
|
||||
end
|
||||
|
||||
def origin
|
||||
|
@ -28,6 +34,10 @@ class Attachment::GalleryItemComponent < ApplicationComponent
|
|||
'Messagerie (instructeur)'
|
||||
when from_messagerie_usager?
|
||||
'Messagerie (usager)'
|
||||
when from_avis_externe_instructeur?
|
||||
'Avis externe (instructeur)'
|
||||
when from_avis_externe_expert?
|
||||
'Avis externe (expert)'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -83,4 +93,16 @@ class Attachment::GalleryItemComponent < ApplicationComponent
|
|||
def from_messagerie_usager?
|
||||
from_messagerie? && attachment.record.instructeur.nil?
|
||||
end
|
||||
|
||||
def from_avis_externe?
|
||||
attachment.record.is_a?(Avis)
|
||||
end
|
||||
|
||||
def from_avis_externe_instructeur?
|
||||
from_avis_externe? && attachment.name == 'introduction_file'
|
||||
end
|
||||
|
||||
def from_avis_externe_expert?
|
||||
from_avis_externe? && attachment.name == 'piece_justificative_file'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -513,11 +513,16 @@ module Instructeurs
|
|||
.commentaires
|
||||
.includes(piece_jointe_attachments: :blob)
|
||||
.map(&:piece_jointe)
|
||||
.map(&:attachments)
|
||||
.flatten
|
||||
.flat_map(&:attachments)
|
||||
.map(&:id)
|
||||
|
||||
champs_attachments_ids + commentaires_attachments_ids
|
||||
avis_attachments_ids = dossier
|
||||
.avis.flat_map { [_1.introduction_file, _1.piece_justificative_file] }
|
||||
.flat_map(&:attachments)
|
||||
.compact
|
||||
.map(&:id)
|
||||
|
||||
champs_attachments_ids + commentaires_attachments_ids + avis_attachments_ids
|
||||
end
|
||||
@gallery_attachments = ActiveStorage::Attachment.where(id: gallery_attachments_ids)
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ module BlobImageProcessorConcern
|
|||
end
|
||||
|
||||
def representation_required?
|
||||
from_champ? || from_messagerie? || logo? || from_action_text?
|
||||
from_champ? || from_messagerie? || logo? || from_action_text? || from_avis?
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -31,6 +31,10 @@ module BlobImageProcessorConcern
|
|||
attachments.any? { _1.record.class == ActionText::RichText }
|
||||
end
|
||||
|
||||
def from_avis?
|
||||
attachments.any? { _1.record.class == Avis }
|
||||
end
|
||||
|
||||
def watermark_required?
|
||||
attachments.any? { _1.record.class == Champs::TitreIdentiteChamp }
|
||||
end
|
||||
|
|
|
@ -101,4 +101,52 @@ RSpec.describe Attachment::GalleryItemComponent, type: :component do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when attachment is from an avis" do
|
||||
context 'from an instructeur' do
|
||||
let(:avis) { create(:avis, :with_introduction, dossier: dossier) }
|
||||
let(:attachment) { avis.introduction_file.attachment }
|
||||
|
||||
it "displays a generic libelle, link, tag and renders title" do
|
||||
expect(subject).to have_text('Pièce jointe à l’avis')
|
||||
expect(subject).to have_link(filename)
|
||||
expect(subject).to have_text('Avis externe (instructeur)')
|
||||
expect(component.title).to eq("Pièce jointe à l’avis -- #{filename}")
|
||||
end
|
||||
|
||||
context "when instructeur has not seen it yet" do
|
||||
let(:seen_at) { now - 1.day }
|
||||
|
||||
before do
|
||||
attachment.blob.update(created_at: now)
|
||||
end
|
||||
|
||||
it 'displays datetime in the right style' do
|
||||
expect(subject).to have_css('.highlighted')
|
||||
end
|
||||
end
|
||||
|
||||
context "when instructeur has already seen it" do
|
||||
let!(:seen_at) { now }
|
||||
|
||||
before do
|
||||
freeze_time
|
||||
attachment.blob.touch(:created_at)
|
||||
end
|
||||
|
||||
it 'displays datetime in the right style' do
|
||||
expect(subject).not_to have_css('.highlighted')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'from an expert' do
|
||||
let(:avis) { create(:avis, :with_piece_justificative, dossier: dossier) }
|
||||
let(:attachment) { avis.piece_justificative_file.attachment }
|
||||
|
||||
it "displays the right tag" do
|
||||
expect(subject).to have_text('Avis externe (expert)')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1486,6 +1486,9 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
let(:logo_path) { 'spec/fixtures/files/logo_test_procedure.png' }
|
||||
let(:rib_path) { 'spec/fixtures/files/RIB.pdf' }
|
||||
let(:commentaire) { create(:commentaire, dossier: dossier) }
|
||||
let(:expert) { create(:expert) }
|
||||
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
|
||||
let(:avis) { create(:avis, :with_answer, :with_piece_justificative, dossier: dossier, claimant: expert, experts_procedure: experts_procedure) }
|
||||
|
||||
before do
|
||||
dossier.champs.first.piece_justificative_file.attach(
|
||||
|
@ -1502,20 +1505,29 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE }
|
||||
)
|
||||
|
||||
avis.piece_justificative_file.attach(
|
||||
io: File.open(rib_path),
|
||||
filename: "RIB.pdf",
|
||||
content_type: "application/pdf",
|
||||
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE }
|
||||
)
|
||||
|
||||
get :pieces_jointes, params: {
|
||||
procedure_id: procedure.id,
|
||||
dossier_id: dossier.id
|
||||
}
|
||||
end
|
||||
|
||||
it 'returns pieces jointes from champs and from messagerie' do
|
||||
it 'returns pieces jointes from champs, messagerie and avis' do
|
||||
expect(response.body).to include('Télécharger le fichier toto.txt')
|
||||
expect(response.body).to include('Télécharger le fichier logo_test_procedure.png')
|
||||
expect(response.body).to include('Télécharger le fichier RIB.pdf')
|
||||
expect(response.body).to include('Visualiser')
|
||||
expect(assigns(:gallery_attachments).count).to eq 3
|
||||
expect(response.body).to include('Pièce jointe au message')
|
||||
expect(response.body).to include('Pièce jointe à l’avis')
|
||||
expect(assigns(:gallery_attachments).count).to eq 4
|
||||
expect(assigns(:gallery_attachments)).to all(be_a(ActiveStorage::Attachment))
|
||||
expect([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp, Commentaire]).to include(*assigns(:gallery_attachments).map { _1.record.class })
|
||||
expect([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp, Commentaire, Avis]).to include(*assigns(:gallery_attachments).map { _1.record.class })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue