Merge pull request #4547 from Keirua/4378-pjs-messagerie-durant-telechargement
Ajout des fichiers de la messagerie dans l'export zip du dossier
This commit is contained in:
commit
77abd65bab
4 changed files with 25 additions and 6 deletions
|
@ -13,10 +13,10 @@ class ActiveStorage::DownloadableFile
|
|||
|
||||
def self.create_list_from_dossier(dossier)
|
||||
pjs = PiecesJustificativesService.liste_pieces_justificatives(dossier)
|
||||
pjs.map do |pj|
|
||||
pjs.map do |piece_justificative|
|
||||
[
|
||||
ActiveStorage::DownloadableFile.new(pj.piece_justificative_file),
|
||||
pj.piece_justificative_file.filename.to_s
|
||||
ActiveStorage::DownloadableFile.new(piece_justificative),
|
||||
piece_justificative.filename.to_s
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
class PiecesJustificativesService
|
||||
def self.liste_pieces_justificatives(dossier)
|
||||
pjs_commentaires = dossier.commentaires
|
||||
.map(&:piece_jointe)
|
||||
.filter(&:attached?)
|
||||
|
||||
champs_blocs_repetables = dossier.champs
|
||||
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
|
||||
.flat_map(&:champs)
|
||||
|
||||
champs_pieces_justificatives_with_attachments(
|
||||
pjs_commentaires + champs_pieces_justificatives_with_attachments(
|
||||
champs_blocs_repetables + dossier.champs
|
||||
)
|
||||
end
|
||||
|
||||
def self.pieces_justificatives_total_size(dossier)
|
||||
liste_pieces_justificatives(dossier)
|
||||
.sum { |pj| pj.piece_justificative_file.byte_size }
|
||||
.sum(&:byte_size)
|
||||
end
|
||||
|
||||
def self.serialize_types_de_champ_as_type_pj(procedure)
|
||||
|
@ -48,5 +52,6 @@ class PiecesJustificativesService
|
|||
champs
|
||||
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
|
||||
.filter { |pj| pj.piece_justificative_file.attached? }
|
||||
.map(&:piece_justificative_file)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ FactoryBot.define do
|
|||
end
|
||||
|
||||
trait :with_file do
|
||||
file { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') }
|
||||
piece_jointe { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,5 +24,19 @@ describe ActiveStorage::DownloadableFile do
|
|||
expect(list.size).to eq(4)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there is a message with no attachment' do
|
||||
let(:commentaire) { create(:commentaire) }
|
||||
let(:dossier) { commentaire.dossier }
|
||||
|
||||
it { expect(list.length).to be 0 }
|
||||
end
|
||||
|
||||
context 'when there is a message with an attachment' do
|
||||
let(:commentaire) { create(:commentaire, :with_file) }
|
||||
let(:dossier) { commentaire.dossier }
|
||||
|
||||
it { expect(list.length).to be 1 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue