Merge pull request #8817 from mfo/US/fix-expert-export

correctif(export.pdf): ETQ expert, lorsque j'exporte un dossier au format PDF, celui ci contenient les avis non confidentiels ainsi que mes avis
This commit is contained in:
mfo 2023-03-29 12:00:14 +00:00 committed by GitHub
commit 60d41029de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 41 additions and 6 deletions

View file

@ -148,7 +148,7 @@ module Experts
end end
def telecharger_pjs 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) cleaned_files = ActiveStorage::DownloadableFile.cleanup_list_from_dossier(files)
zipline(cleaned_files, "dossier-#{@dossier.id}.zip") zipline(cleaned_files, "dossier-#{@dossier.id}.zip")

View file

@ -1,6 +1,12 @@
class ActiveStorage::DownloadableFile class ActiveStorage::DownloadableFile
def self.create_list_from_dossiers(dossiers, with_bills: false, with_champs_private: false, include_infos_administration: false) def self.create_list_from_dossiers(
PiecesJustificativesService.generate_dossier_export(dossiers, include_infos_administration:) + 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:) PiecesJustificativesService.liste_documents(dossiers, with_bills:, with_champs_private:)
end end

View file

@ -83,7 +83,7 @@ class PiecesJustificativesService
end end
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? return [] if dossiers.empty?
pdfs = [] pdfs = []
@ -98,6 +98,7 @@ class PiecesJustificativesService
.render(template: 'dossiers/show', formats: [:pdf], .render(template: 'dossiers/show', formats: [:pdf],
assigns: { assigns: {
include_infos_administration:, include_infos_administration:,
include_avis_for_expert:,
dossier: dossier dossier: dossier
}) })

View file

@ -287,6 +287,13 @@ prawn_document(page_size: "A4") do |pdf|
end end
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? if @dossier.commentaires.present?
add_title(pdf, 'Messagerie') add_title(pdf, 'Messagerie')
@dossier.commentaires.each do |commentaire| @dossier.commentaires.each do |commentaire|

View file

@ -97,7 +97,7 @@ describe Experts::AvisController, type: :controller do
subject { get :telecharger_pjs, params: { id: avis.id, procedure_id: } } subject { get :telecharger_pjs, params: { id: avis.id, procedure_id: } }
before do 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 end
context 'with a valid avis' do context 'with a valid avis' do

View file

@ -873,7 +873,7 @@ describe Instructeurs::DossiersController, type: :controller do
end end
before do 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 end
it 'includes an attachment' do it 'includes an attachment' do

View file

@ -13,6 +13,14 @@ FactoryBot.define do
avis.experts_procedure ||= build(:experts_procedure, procedure: avis.dossier.procedure) avis.experts_procedure ||= build(:experts_procedure, procedure: avis.dossier.procedure)
end end
trait :confidentiel do
confidentiel { true }
end
trait :not_confidentiel do
confidentiel { false }
end
trait :with_instructeur do trait :with_instructeur do
email { nil } email { nil }
instructeur { association :instructeur, email: generate(:expert_email) } instructeur { association :instructeur, email: generate(:expert_email) }

View file

@ -210,6 +210,19 @@ describe PiecesJustificativesService do
it "doesn't update dossier" do it "doesn't update dossier" do
expect { subject }.not_to change { dossier.updated_at } expect { subject }.not_to change { dossier.updated_at }
end 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 end
def attach_file_to_champ(champ, safe = true) def attach_file_to_champ(champ, safe = true)