Merge pull request #9558 from mfo/US/avis-in-exports

amelioration(dossier.export): ajoute les piece justificative des avis dans les exports
This commit is contained in:
mfo 2023-10-09 13:12:22 +00:00 committed by GitHub
commit def659e599
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 4 deletions

View file

@ -9,7 +9,7 @@ class ActiveStorage::DownloadableFile
include_avis_for_expert: false
)
PiecesJustificativesService.generate_dossier_export(dossiers, include_infos_administration:, include_avis_for_expert:) +
PiecesJustificativesService.liste_documents(dossiers, with_bills:, with_champs_private:)
PiecesJustificativesService.liste_documents(dossiers, with_bills:, with_champs_private:, with_avis_piece_justificative: include_infos_administration)
end
def self.cleanup_list_from_dossier(files)
@ -79,6 +79,8 @@ class ActiveStorage::DownloadableFile
'horodatage/'
when 'Commentaire'
'messagerie/'
when 'Avis'
'avis/'
else
'pieces_justificatives/'
end

View file

@ -1,11 +1,15 @@
class PiecesJustificativesService
def self.liste_documents(dossiers, with_bills:, with_champs_private:)
def self.liste_documents(dossiers,
with_bills:,
with_champs_private:,
with_avis_piece_justificative:)
bill_ids = []
docs = dossiers.in_batches.flat_map do |batch|
pjs = pjs_for_champs(batch, with_champs_private:) +
pjs_for_commentaires(batch) +
pjs_for_dossier(batch)
pjs_for_dossier(batch) +
pjs_for_avis(batch, with_avis_piece_justificative:)
if with_bills
# some bills are shared among operations
@ -206,6 +210,22 @@ class PiecesJustificativesService
end
end
def self.pjs_for_avis(dossiers, with_avis_piece_justificative:)
avis_ids_dossier_id_query = Avis.joins(:dossier)
.where(dossier: dossiers)
avis_ids_dossier_id_query = avis_ids_dossier_id_query.where(confidentiel: false) if !with_avis_piece_justificative
avis_ids_dossier_id = avis_ids_dossier_id_query.pluck(:id, :dossier_id).to_h
ActiveStorage::Attachment
.includes(:blob)
.where(record_type: "Avis", name: "piece_justificative_file", record_id: avis_ids_dossier_id.keys)
.filter { |a| safe_attachment(a) }
.map do |a|
dossier_id = avis_ids_dossier_id[a.record_id]
ActiveStorage::DownloadableFile.pj_and_path(dossier_id, a)
end
end
def self.operation_logs_and_signature_ids(dossiers)
dol_id_dossier_id_bill_id = DossierOperationLog
.where(dossier: dossiers, data: nil)

View file

@ -2,10 +2,11 @@ describe PiecesJustificativesService do
describe '.liste_documents' do
let(:with_champs_private) { true }
let(:with_bills) { true }
let(:with_avis_piece_justificative) { true }
subject do
PiecesJustificativesService
.liste_documents(Dossier.where(id: dossier.id), with_bills:, with_champs_private:)
.liste_documents(Dossier.where(id: dossier.id), with_bills:, with_champs_private:, with_avis_piece_justificative:)
.map(&:first)
end
@ -67,6 +68,50 @@ describe PiecesJustificativesService do
end
end
context 'with avis.piece_justificative being confidentiel' do
let(:procedure) { create(:procedure) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:avis) { create(:avis, dossier: dossier, confidentiel: true) }
let(:with_avis_piece_justificative) { false }
before do
to_be_attached = {
io: StringIO.new("toto"),
filename: "toto.png",
content_type: "image/png",
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE }
}
avis.piece_justificative_file.attach(to_be_attached)
end
it "doesn't return confidentiel avis.piece_justificative_file" do
expect(subject).to be_empty
end
end
context 'with avis.piece_justificative being public' do
let(:procedure) { create(:procedure) }
let(:dossier) { create(:dossier, procedure: procedure) }
let(:avis) { create(:avis, dossier: dossier) }
let(:with_avis_piece_justificative) { false }
before do
to_be_attached = {
io: StringIO.new("toto"),
filename: "toto.png",
content_type: "image/png",
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE }
}
avis.piece_justificative_file.attach(to_be_attached)
end
it "return avis.piece_justificative_file not confidentiel" do
expect(subject).not_to be_empty
end
end
context 'with a identite champ pj' do
let(:procedure) { create(:procedure, :with_titre_identite) }
let(:dossier) { create(:dossier, procedure: procedure) }