feat(pj_service): add expert's avis (even when confidential) to exports asked by same expert
This commit is contained in:
parent
dd39ac313b
commit
a151a304e2
2 changed files with 20 additions and 2 deletions
|
@ -223,7 +223,16 @@ class PiecesJustificativesService
|
|||
|
||||
def pjs_for_avis(dossiers)
|
||||
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 !liste_documents_allows?(:with_avis_piece_justificative)
|
||||
if !liste_documents_allows?(:with_avis_piece_justificative)
|
||||
avis_ids_dossier_id_query = avis_ids_dossier_id_query.where(confidentiel: false)
|
||||
end
|
||||
if @user_profile.is_a?(Expert)
|
||||
avis_ids = Avis.joins(:dossier, experts_procedure: :expert)
|
||||
.where(experts_procedure: { expert: @user_profile })
|
||||
.where(dossier: dossiers)
|
||||
.pluck(:id)
|
||||
avis_ids_dossier_id_query = avis_ids_dossier_id_query.or(Avis.where(id: avis_ids))
|
||||
end
|
||||
avis_ids_dossier_id = avis_ids_dossier_id_query.pluck(:id, :dossier_id).to_h
|
||||
|
||||
ActiveStorage::Attachment
|
||||
|
|
|
@ -244,7 +244,16 @@ describe PiecesJustificativesService do
|
|||
context 'given an expert' do
|
||||
let(:user_profile) { create(:expert) }
|
||||
it "doesn't return confidentiel avis.piece_justificative_file" do
|
||||
expect(subject).to be_empty
|
||||
expect(subject.size).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the expert has given the avis' do
|
||||
let(:experts_procedure) { create(:experts_procedure, expert: user_profile, procedure:) }
|
||||
let(:avis) { create(:avis, experts_procedure:, dossier: dossier, confidentiel: true) }
|
||||
let(:user_profile) { create(:expert) }
|
||||
it "doesn't return confidentiel avis.piece_justificative_file" do
|
||||
expect(subject.size).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue