feat(pj_service): add introduction_file to exports
This commit is contained in:
parent
284ecf864b
commit
dd39ac313b
2 changed files with 24 additions and 10 deletions
|
@ -84,11 +84,23 @@ class PiecesJustificativesService
|
||||||
def acl_for_dossier_export
|
def acl_for_dossier_export
|
||||||
case @user_profile
|
case @user_profile
|
||||||
when Expert
|
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
|
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
|
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
|
else
|
||||||
raise 'not supported'
|
raise 'not supported'
|
||||||
end
|
end
|
||||||
|
@ -216,7 +228,7 @@ class PiecesJustificativesService
|
||||||
|
|
||||||
ActiveStorage::Attachment
|
ActiveStorage::Attachment
|
||||||
.includes(:blob)
|
.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) }
|
.filter { |a| safe_attachment(a) }
|
||||||
.map do |a|
|
.map do |a|
|
||||||
dossier_id = avis_ids_dossier_id[a.record_id]
|
dossier_id = avis_ids_dossier_id[a.record_id]
|
||||||
|
|
|
@ -224,19 +224,20 @@ describe PiecesJustificativesService do
|
||||||
}
|
}
|
||||||
|
|
||||||
avis.piece_justificative_file.attach(to_be_attached)
|
avis.piece_justificative_file.attach(to_be_attached)
|
||||||
|
avis.introduction_file.attach(avis.piece_justificative_file.blob)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'given an administrateur' do
|
context 'given an administrateur' do
|
||||||
let(:user_profile) { build(:administrateur) }
|
let(:user_profile) { build(:administrateur) }
|
||||||
it "doesn't return confidentiel avis.piece_justificative_file" do
|
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
|
end
|
||||||
|
|
||||||
context 'given an instructeur' do
|
context 'given an instructeur' do
|
||||||
let(:user_profile) { create(:instructeur) }
|
let(:user_profile) { create(:instructeur) }
|
||||||
it "doesn't return confidentiel avis.piece_justificative_file" do
|
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
|
end
|
||||||
|
|
||||||
|
@ -251,7 +252,7 @@ describe PiecesJustificativesService do
|
||||||
context 'with avis.piece_justificative being public' do
|
context 'with avis.piece_justificative being public' do
|
||||||
let(:procedure) { create(:procedure) }
|
let(:procedure) { create(:procedure) }
|
||||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
let(:avis) { create(:avis, dossier: dossier) }
|
let(:avis) { create(:avis, dossier: dossier, confidentiel: false) }
|
||||||
before do
|
before do
|
||||||
to_be_attached = {
|
to_be_attached = {
|
||||||
io: StringIO.new("toto"),
|
io: StringIO.new("toto"),
|
||||||
|
@ -261,26 +262,27 @@ describe PiecesJustificativesService do
|
||||||
}
|
}
|
||||||
|
|
||||||
avis.piece_justificative_file.attach(to_be_attached)
|
avis.piece_justificative_file.attach(to_be_attached)
|
||||||
|
avis.introduction_file.attach(avis.piece_justificative_file.blob)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'given an administrateur' do
|
context 'given an administrateur' do
|
||||||
let(:user_profile) { build(:administrateur) }
|
let(:user_profile) { build(:administrateur) }
|
||||||
it "doesn't return confidentiel avis.piece_justificative_file" do
|
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
|
end
|
||||||
|
|
||||||
context 'given an instructeur' do
|
context 'given an instructeur' do
|
||||||
let(:user_profile) { create(:instructeur) }
|
let(:user_profile) { create(:instructeur) }
|
||||||
it "doesn't return confidentiel avis.piece_justificative_file" do
|
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
|
end
|
||||||
|
|
||||||
context 'given an expert' do
|
context 'given an expert' do
|
||||||
let(:user_profile) { create(:expert) }
|
let(:user_profile) { create(:expert) }
|
||||||
it "doesn't return confidentiel avis.piece_justificative_file" do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue