Merge pull request #10014 from mfo/US/better-expert-exports
ETQ expert: je retrouve mes avis confidentiel dans les exports. ETQ instructeur, je retrouve les fichiers joint a une demande d'avis expert
This commit is contained in:
commit
41a27fbad2
2 changed files with 44 additions and 12 deletions
|
@ -84,11 +84,23 @@ class PiecesJustificativesService
|
|||
def acl_for_dossier_export
|
||||
case @user_profile
|
||||
when Expert
|
||||
{ include_infos_administration: true, include_avis_for_expert: true, only_for_expert: @user_profile }
|
||||
{
|
||||
include_infos_administration: true,
|
||||
include_avis_for_expert: true,
|
||||
only_for_expert: @user_profile
|
||||
}
|
||||
when Instructeur, Administrateur
|
||||
{ include_infos_administration: true, include_avis_for_expert: true, only_for_export: false }
|
||||
{
|
||||
include_infos_administration: true,
|
||||
include_avis_for_expert: true,
|
||||
only_for_export: false
|
||||
}
|
||||
when User
|
||||
{ include_infos_administration: false, include_avis_for_expert: false, only_for_expert: false }
|
||||
{
|
||||
include_infos_administration: false,
|
||||
include_avis_for_expert: false, # should be true, expert can use the messagerie, why not provide avis ?
|
||||
only_for_expert: false
|
||||
}
|
||||
else
|
||||
raise 'not supported'
|
||||
end
|
||||
|
@ -211,12 +223,21 @@ 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
|
||||
.includes(:blob)
|
||||
.where(record_type: "Avis", name: "piece_justificative_file", record_id: avis_ids_dossier_id.keys)
|
||||
.where(record_type: "Avis", record_id: avis_ids_dossier_id.keys)
|
||||
.filter { |a| safe_attachment(a) }
|
||||
.map do |a|
|
||||
dossier_id = avis_ids_dossier_id[a.record_id]
|
||||
|
|
|
@ -224,26 +224,36 @@ describe PiecesJustificativesService do
|
|||
}
|
||||
|
||||
avis.piece_justificative_file.attach(to_be_attached)
|
||||
avis.introduction_file.attach(avis.piece_justificative_file.blob)
|
||||
end
|
||||
|
||||
context 'given an administrateur' do
|
||||
let(:user_profile) { build(:administrateur) }
|
||||
it "doesn't return confidentiel avis.piece_justificative_file" do
|
||||
expect(subject).not_to be_empty
|
||||
expect(subject.size).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'given an instructeur' do
|
||||
let(:user_profile) { create(:instructeur) }
|
||||
it "doesn't return confidentiel avis.piece_justificative_file" do
|
||||
expect(subject).not_to be_empty
|
||||
expect(subject.size).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
@ -251,7 +261,7 @@ describe PiecesJustificativesService do
|
|||
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(:avis) { create(:avis, dossier: dossier, confidentiel: false) }
|
||||
before do
|
||||
to_be_attached = {
|
||||
io: StringIO.new("toto"),
|
||||
|
@ -261,26 +271,27 @@ describe PiecesJustificativesService do
|
|||
}
|
||||
|
||||
avis.piece_justificative_file.attach(to_be_attached)
|
||||
avis.introduction_file.attach(avis.piece_justificative_file.blob)
|
||||
end
|
||||
|
||||
context 'given an administrateur' do
|
||||
let(:user_profile) { build(:administrateur) }
|
||||
it "doesn't return confidentiel avis.piece_justificative_file" do
|
||||
expect(subject).not_to be_empty
|
||||
expect(subject.size).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'given an instructeur' do
|
||||
let(:user_profile) { create(:instructeur) }
|
||||
it "doesn't return confidentiel avis.piece_justificative_file" do
|
||||
expect(subject).not_to be_empty
|
||||
expect(subject.size).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context 'given an expert' do
|
||||
let(:user_profile) { create(:expert) }
|
||||
it "doesn't return confidentiel avis.piece_justificative_file" do
|
||||
expect(subject).not_to be_empty
|
||||
expect(subject.size).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue