From 4f9c45c489bb751122e1c563b7426dd4d2621386 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 28 Mar 2023 16:51:35 +0200 Subject: [PATCH 1/2] bug(export.pdf): ETQ expert, lorsque j'exporte un dossier, celui ci devrait contenir les avis non confidentiels ainsi que mes avis --- app/views/dossiers/show.pdf.prawn | 7 +++++++ spec/controllers/experts/avis_controller_spec.rb | 2 +- spec/factories/avis.rb | 8 ++++++++ spec/services/pieces_justificatives_service_spec.rb | 13 +++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/views/dossiers/show.pdf.prawn b/app/views/dossiers/show.pdf.prawn index bf1396868..570789716 100644 --- a/app/views/dossiers/show.pdf.prawn +++ b/app/views/dossiers/show.pdf.prawn @@ -287,6 +287,13 @@ prawn_document(page_size: "A4") do |pdf| end end + if @include_avis_for_expert && @dossier.avis.present? + add_title(pdf, "Avis") + @dossier.avis_for_expert(@include_avis_for_expert).each do |avis| + add_avis(pdf, avis) + end + end + if @dossier.commentaires.present? add_title(pdf, 'Messagerie') @dossier.commentaires.each do |commentaire| diff --git a/spec/controllers/experts/avis_controller_spec.rb b/spec/controllers/experts/avis_controller_spec.rb index eae41ab32..c676f58f2 100644 --- a/spec/controllers/experts/avis_controller_spec.rb +++ b/spec/controllers/experts/avis_controller_spec.rb @@ -97,7 +97,7 @@ describe Experts::AvisController, type: :controller do subject { get :telecharger_pjs, params: { id: avis.id, procedure_id: } } before do - allow(PiecesJustificativesService).to receive(:generate_dossier_export).and_return([]).with([dossier], include_infos_administration: false) + allow(PiecesJustificativesService).to receive(:generate_dossier_export).and_return([]).with([dossier], include_infos_administration: false, include_avis_for_expert: expert) end context 'with a valid avis' do diff --git a/spec/factories/avis.rb b/spec/factories/avis.rb index 21e5ee81b..0a16c7528 100644 --- a/spec/factories/avis.rb +++ b/spec/factories/avis.rb @@ -13,6 +13,14 @@ FactoryBot.define do avis.experts_procedure ||= build(:experts_procedure, procedure: avis.dossier.procedure) end + trait :confidentiel do + confidentiel { true } + end + + trait :not_confidentiel do + confidentiel { false } + end + trait :with_instructeur do email { nil } instructeur { association :instructeur, email: generate(:expert_email) } diff --git a/spec/services/pieces_justificatives_service_spec.rb b/spec/services/pieces_justificatives_service_spec.rb index bdfbda7a3..ea6de277f 100644 --- a/spec/services/pieces_justificatives_service_spec.rb +++ b/spec/services/pieces_justificatives_service_spec.rb @@ -210,6 +210,19 @@ describe PiecesJustificativesService do it "doesn't update dossier" do expect { subject }.not_to change { dossier.updated_at } end + + context 'when given an expert' do + let!(:expert) { create(:expert) } + let!(:confidentiel_avis) { create(:avis, :confidentiel, dossier: dossier) } + let!(:not_confidentiel_avis) { create(:avis, :not_confidentiel, dossier: dossier) } + let!(:expert_avis) { create(:avis, :confidentiel, dossier: dossier, expert: expert) } + + subject { PiecesJustificativesService.generate_dossier_export(Dossier.where(id: dossier.id), include_avis_for_expert: expert) } + it "includes avis not confidentiel as well as expert's avis" do + expect_any_instance_of(Dossier).to receive(:avis_for_expert).with(expert).and_return([]) + subject + end + end end def attach_file_to_champ(champ, safe = true) From c6e9674de2a1af91ab8fe6f564523ae53180b2fb Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 28 Mar 2023 16:56:02 +0200 Subject: [PATCH 2/2] correctif(export.pdf): ETQ expert, lorsque j'exporte un dossier au format PDF, celui ci contenient les avis non confidentiels ainsi que mes avis --- app/controllers/experts/avis_controller.rb | 2 +- app/lib/active_storage/downloadable_file.rb | 10 ++++++++-- app/services/pieces_justificatives_service.rb | 3 ++- app/views/dossiers/show.pdf.prawn | 8 ++++---- .../instructeurs/dossiers_controller_spec.rb | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/controllers/experts/avis_controller.rb b/app/controllers/experts/avis_controller.rb index f96dfd09f..699cb2646 100644 --- a/app/controllers/experts/avis_controller.rb +++ b/app/controllers/experts/avis_controller.rb @@ -147,7 +147,7 @@ module Experts end def telecharger_pjs - files = ActiveStorage::DownloadableFile.create_list_from_dossiers(Dossier.where(id: @dossier.id)) + files = ActiveStorage::DownloadableFile.create_list_from_dossiers(Dossier.where(id: @dossier.id), include_avis_for_expert: current_expert) cleaned_files = ActiveStorage::DownloadableFile.cleanup_list_from_dossier(files) zipline(cleaned_files, "dossier-#{@dossier.id}.zip") diff --git a/app/lib/active_storage/downloadable_file.rb b/app/lib/active_storage/downloadable_file.rb index 09713dadb..c403495f1 100644 --- a/app/lib/active_storage/downloadable_file.rb +++ b/app/lib/active_storage/downloadable_file.rb @@ -1,6 +1,12 @@ class ActiveStorage::DownloadableFile - def self.create_list_from_dossiers(dossiers, with_bills: false, with_champs_private: false, include_infos_administration: false) - PiecesJustificativesService.generate_dossier_export(dossiers, include_infos_administration:) + + def self.create_list_from_dossiers( + dossiers, + with_bills: false, + with_champs_private: false, + include_infos_administration: false, + 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:) end diff --git a/app/services/pieces_justificatives_service.rb b/app/services/pieces_justificatives_service.rb index 1b18ea4ca..cff6d8548 100644 --- a/app/services/pieces_justificatives_service.rb +++ b/app/services/pieces_justificatives_service.rb @@ -83,7 +83,7 @@ class PiecesJustificativesService end end - def self.generate_dossier_export(dossiers, include_infos_administration: false) + def self.generate_dossier_export(dossiers, include_infos_administration: false, include_avis_for_expert: false) return [] if dossiers.empty? pdfs = [] @@ -98,6 +98,7 @@ class PiecesJustificativesService .render(template: 'dossiers/show', formats: [:pdf], assigns: { include_infos_administration:, + include_avis_for_expert:, dossier: dossier }) diff --git a/app/views/dossiers/show.pdf.prawn b/app/views/dossiers/show.pdf.prawn index 570789716..5e08edf8b 100644 --- a/app/views/dossiers/show.pdf.prawn +++ b/app/views/dossiers/show.pdf.prawn @@ -288,10 +288,10 @@ prawn_document(page_size: "A4") do |pdf| end if @include_avis_for_expert && @dossier.avis.present? - add_title(pdf, "Avis") - @dossier.avis_for_expert(@include_avis_for_expert).each do |avis| - add_avis(pdf, avis) - end + add_title(pdf, "Avis") + @dossier.avis_for_expert(@include_avis_for_expert).each do |avis| + add_avis(pdf, avis) + end end if @dossier.commentaires.present? diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index 971262fa9..c8c47de78 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -873,7 +873,7 @@ describe Instructeurs::DossiersController, type: :controller do end before do - allow(PiecesJustificativesService).to receive(:generate_dossier_export).with([dossier], include_infos_administration: true).and_call_original + allow(PiecesJustificativesService).to receive(:generate_dossier_export).with([dossier], include_infos_administration: true, include_avis_for_expert: false).and_call_original end it 'includes an attachment' do