pj_service take a dossier collection !

This commit is contained in:
simon lehericey 2022-04-04 22:53:06 +02:00
parent 51a6145d96
commit 7ac1288905
4 changed files with 14 additions and 17 deletions

View file

@ -1,13 +1,8 @@
class ActiveStorage::DownloadableFile
def self.create_list_from_dossiers(dossiers, for_expert = false)
pj_and_paths = dossiers.map { |d| pj_and_path(d, PiecesJustificativesService.generate_dossier_export(d)) }
pj_and_paths += dossiers.flat_map do |dossier|
pjs = PiecesJustificativesService.liste_documents(dossier, for_expert)
pjs.map { |piece_justificative| pj_and_path(dossier, piece_justificative) }
end
pj_and_paths
dossiers
.map { |d| pj_and_path(d, PiecesJustificativesService.generate_dossier_export(d)) } +
PiecesJustificativesService.liste_documents(dossiers, for_expert)
end
private

View file

@ -1,10 +1,12 @@
class PiecesJustificativesService
def self.liste_documents(dossier, for_expert)
pjs_champs = pjs_for_champs(dossier, for_expert)
pjs_commentaires = pjs_for_commentaires(dossier)
pjs_dossier = pjs_for_dossier(dossier, for_expert)
def self.liste_documents(dossiers, for_expert)
dossiers.flat_map do |dossier|
pjs = pjs_for_champs(dossier, for_expert) +
pjs_for_commentaires(dossier) +
pjs_for_dossier(dossier, for_expert)
pjs_champs + pjs_commentaires + pjs_dossier
pjs.map { |piece_justificative| ActiveStorage::DownloadableFile.pj_and_path(dossier, piece_justificative) }
end
end
def self.serialize_types_de_champ_as_type_pj(revision)

View file

@ -16,15 +16,15 @@ describe PiecesJustificativesService do
end
describe '.liste_documents' do
subject { PiecesJustificativesService.liste_documents(dossier, false) }
subject { PiecesJustificativesService.liste_documents(Dossier.where(id: dossier.id), false) }
it "doesn't return sensitive documents like titre_identite" do
expect(champ_identite.piece_justificative_file).to be_attached
expect(subject.any? { |piece| piece.name == 'piece_justificative_file' }).to be_falsy
expect(subject.any? { |piece, _| piece.name == 'piece_justificative_file' }).to be_falsy
end
it "returns operation logs of the dossier" do
expect(subject.any? { |piece| piece.name == 'serialized' }).to be_truthy
expect(subject.any? { |piece, _| piece.name == 'serialized' }).to be_truthy
end
end

View file

@ -106,7 +106,7 @@ describe ProcedureArchiveService do
)
end
let(:documents) { [pj, bad_pj] }
let(:documents) { [pj, bad_pj].map { |p| ActiveStorage::DownloadableFile.pj_and_path(dossier, p) } }
before do
allow(PiecesJustificativesService).to receive(:liste_documents).and_return(documents)
end