amelioration(dossier.export): intègre les avis dans les exports [n'inclu pas les pieces justificatives des avis confidentiels pour les expert, inclu les piece justificatives des avis confidentiel pour les instructeurs ]
This commit is contained in:
parent
6abd0f8db0
commit
1d8a1617d7
3 changed files with 71 additions and 4 deletions
|
@ -9,7 +9,7 @@ class ActiveStorage::DownloadableFile
|
||||||
include_avis_for_expert: false
|
include_avis_for_expert: false
|
||||||
)
|
)
|
||||||
PiecesJustificativesService.generate_dossier_export(dossiers, include_infos_administration:, include_avis_for_expert:) +
|
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
|
end
|
||||||
|
|
||||||
def self.cleanup_list_from_dossier(files)
|
def self.cleanup_list_from_dossier(files)
|
||||||
|
@ -79,6 +79,8 @@ class ActiveStorage::DownloadableFile
|
||||||
'horodatage/'
|
'horodatage/'
|
||||||
when 'Commentaire'
|
when 'Commentaire'
|
||||||
'messagerie/'
|
'messagerie/'
|
||||||
|
when 'Avis'
|
||||||
|
'avis/'
|
||||||
else
|
else
|
||||||
'pieces_justificatives/'
|
'pieces_justificatives/'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
class PiecesJustificativesService
|
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 = []
|
bill_ids = []
|
||||||
|
|
||||||
docs = dossiers.in_batches.flat_map do |batch|
|
docs = dossiers.in_batches.flat_map do |batch|
|
||||||
pjs = pjs_for_champs(batch, with_champs_private:) +
|
pjs = pjs_for_champs(batch, with_champs_private:) +
|
||||||
pjs_for_commentaires(batch) +
|
pjs_for_commentaires(batch) +
|
||||||
pjs_for_dossier(batch)
|
pjs_for_dossier(batch) +
|
||||||
|
pjs_for_avis(batch, with_avis_piece_justificative:)
|
||||||
|
|
||||||
if with_bills
|
if with_bills
|
||||||
# some bills are shared among operations
|
# some bills are shared among operations
|
||||||
|
@ -206,6 +210,22 @@ class PiecesJustificativesService
|
||||||
end
|
end
|
||||||
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)
|
def self.operation_logs_and_signature_ids(dossiers)
|
||||||
dol_id_dossier_id_bill_id = DossierOperationLog
|
dol_id_dossier_id_bill_id = DossierOperationLog
|
||||||
.where(dossier: dossiers, data: nil)
|
.where(dossier: dossiers, data: nil)
|
||||||
|
|
|
@ -2,10 +2,11 @@ describe PiecesJustificativesService do
|
||||||
describe '.liste_documents' do
|
describe '.liste_documents' do
|
||||||
let(:with_champs_private) { true }
|
let(:with_champs_private) { true }
|
||||||
let(:with_bills) { true }
|
let(:with_bills) { true }
|
||||||
|
let(:with_avis_piece_justificative) { true }
|
||||||
|
|
||||||
subject do
|
subject do
|
||||||
PiecesJustificativesService
|
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)
|
.map(&:first)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -67,6 +68,50 @@ describe PiecesJustificativesService do
|
||||||
end
|
end
|
||||||
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
|
context 'with a identite champ pj' do
|
||||||
let(:procedure) { create(:procedure, :with_titre_identite) }
|
let(:procedure) { create(:procedure, :with_titre_identite) }
|
||||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
|
|
Loading…
Reference in a new issue