Merge pull request #6213 from betagouv/fix-confidential-avis

Corrige un bug sur l'affichage d'avis confidentiel
This commit is contained in:
LeSim 2021-05-20 11:21:44 +02:00 committed by GitHub
commit 8e32e52fc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 18 deletions

View file

@ -535,14 +535,10 @@ class Dossier < ApplicationRecord
end
def avis_for_expert(expert)
if expert.dossiers.include?(self)
avis.order(created_at: :asc)
else
avis
.where(confidentiel: false)
.or(avis.where(claimant: expert))
.order(created_at: :asc)
end
Avis
.where(dossier_id: id, confidentiel: false)
.or(Avis.where(id: expert.avis))
.order(created_at: :asc)
end
def owner_name

View file

@ -337,20 +337,22 @@ describe Dossier do
it { expect(dossier.avis_for_expert(expert_2)).not_to match([avis]) }
end
context 'when there is a public advice asked from one expert to another' do
let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure_2, confidentiel: false) }
context 'when there is a public advice asked from one instructeur to an expert' do
let!(:avis_1) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: false) }
let!(:avis_2) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure_2, confidentiel: false) }
it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis]) }
it { expect(dossier.avis_for_expert(expert_1)).to match([avis]) }
it { expect(dossier.avis_for_expert(expert_2)).to match([avis]) }
it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis_1, avis_2]) }
it { expect(dossier.avis_for_expert(expert_1)).to match([avis_1, avis_2]) }
it { expect(dossier.avis_for_expert(expert_2)).to match([avis_1, avis_2]) }
end
context 'when there is a private advice asked from one expert to another' do
let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure_2, confidentiel: true) }
context 'when there is a private advice asked from one instructeur to an expert' do
let!(:avis_1) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure, confidentiel: true) }
let!(:avis_2) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure_2, confidentiel: true) }
it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis]) }
it { expect(dossier.avis_for_expert(expert_1)).not_to match([avis]) }
it { expect(dossier.avis_for_expert(expert_2)).to match([avis]) }
it { expect(dossier.avis_for_instructeur(instructeur)).to match([avis_1, avis_2]) }
it { expect(dossier.avis_for_expert(expert_1)).to match([avis_1]) }
it { expect(dossier.avis_for_expert(expert_2)).to match([avis_2]) }
end
context 'when they are a lot of advice' do