Only invite experts to dossiers instructeur have access to
This commit is contained in:
parent
8a514e0713
commit
f0ea96772d
7 changed files with 31 additions and 10 deletions
|
@ -14,7 +14,7 @@ module CreateAvisConcern
|
||||||
allowed_dossiers = [dossier]
|
allowed_dossiers = [dossier]
|
||||||
|
|
||||||
if create_avis_params[:invite_linked_dossiers].present?
|
if create_avis_params[:invite_linked_dossiers].present?
|
||||||
allowed_dossiers += dossier.linked_dossiers
|
allowed_dossiers += dossier.linked_dossiers_for(current_instructeur)
|
||||||
end
|
end
|
||||||
|
|
||||||
create_results = Avis.create(
|
create_results = Avis.create(
|
||||||
|
|
|
@ -588,6 +588,10 @@ class Dossier < ApplicationRecord
|
||||||
Dossier.where(id: champs.filter(&:dossier_link?).map(&:value).compact)
|
Dossier.where(id: champs.filter(&:dossier_link?).map(&:value).compact)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def linked_dossiers_for(instructeur)
|
||||||
|
instructeur.dossiers.where(id: champs.filter(&:dossier_link?).map(&:value).compact)
|
||||||
|
end
|
||||||
|
|
||||||
def hash_for_deletion_mail
|
def hash_for_deletion_mail
|
||||||
{ id: self.id, procedure_libelle: self.procedure.libelle }
|
{ id: self.id, procedure_libelle: self.procedure.libelle }
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
= f.submit 'Envoyer votre avis', class: 'button send'
|
= f.submit 'Envoyer votre avis', class: 'button send'
|
||||||
|
|
||||||
- if !@dossier.termine?
|
- if !@dossier.termine?
|
||||||
= render partial: "instructeurs/shared/avis/form", locals: { url: avis_instructeur_avis_path(@avis), linked_dossiers: @dossier.linked_dossiers, must_be_confidentiel: @avis.confidentiel?, avis: @new_avis }
|
= render partial: "instructeurs/shared/avis/form", locals: { url: avis_instructeur_avis_path(@avis), linked_dossiers: @dossier.linked_dossiers_for(current_instructeur), must_be_confidentiel: @avis.confidentiel?, avis: @new_avis }
|
||||||
|
|
||||||
- if @dossier.avis_for(current_instructeur).present?
|
- if @dossier.avis_for(current_instructeur).present?
|
||||||
= render partial: 'instructeurs/shared/avis/list', locals: { avis: @dossier.avis_for(current_instructeur), avis_seen_at: nil }
|
= render partial: 'instructeurs/shared/avis/list', locals: { avis: @dossier.avis_for(current_instructeur), avis_seen_at: nil }
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
.container
|
.container
|
||||||
- if !@dossier.termine?
|
- if !@dossier.termine?
|
||||||
= render partial: "instructeurs/shared/avis/form", locals: { url: avis_instructeur_dossier_path(@dossier.procedure, @dossier), linked_dossiers: @dossier.linked_dossiers, must_be_confidentiel: false, avis: @avis }
|
= render partial: "instructeurs/shared/avis/form", locals: { url: avis_instructeur_dossier_path(@dossier.procedure, @dossier), linked_dossiers: @dossier.linked_dossiers_for(current_instructeur), must_be_confidentiel: false, avis: @avis }
|
||||||
|
|
||||||
- if @dossier.avis.present?
|
- if @dossier.avis.present?
|
||||||
= render partial: 'instructeurs/shared/avis/list', locals: { avis: @dossier.avis, avis_seen_at: @avis_seen_at }
|
= render partial: 'instructeurs/shared/avis/list', locals: { avis: @dossier.avis, avis_seen_at: @avis_seen_at }
|
||||||
|
|
|
@ -196,16 +196,30 @@ describe Instructeurs::AvisController, type: :controller do
|
||||||
|
|
||||||
context 'checked' do
|
context 'checked' do
|
||||||
let(:invite_linked_dossiers) { true }
|
let(:invite_linked_dossiers) { true }
|
||||||
let(:created_avis) { Avis.last(2).first }
|
|
||||||
let(:linked_avis) { Avis.last }
|
|
||||||
let(:linked_dossier) { dossier.reload.linked_dossiers.first }
|
|
||||||
|
|
||||||
it do
|
context 'and can access linked dossiers' do
|
||||||
|
let(:created_avis) { Avis.last(2).first }
|
||||||
|
let(:linked_avis) { Avis.last }
|
||||||
|
let(:linked_dossier) { dossier.reload.linked_dossiers.first }
|
||||||
|
let(:invite_linked_dossiers) do
|
||||||
|
instructeur.assign_to_procedure(linked_dossier.procedure)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'sends two avis invitations' do
|
||||||
|
expect(flash.notice).to eq("Une demande d'avis a été envoyée à a@b.com")
|
||||||
|
expect(Avis.count).to eq(old_avis_count + 2)
|
||||||
|
expect(created_avis.email).to eq("a@b.com")
|
||||||
|
expect(created_avis.dossier).to eq(dossier)
|
||||||
|
expect(linked_avis.dossier).to eq(linked_dossier)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'and can not access linked dossiers' do
|
||||||
expect(flash.notice).to eq("Une demande d'avis a été envoyée à a@b.com")
|
expect(flash.notice).to eq("Une demande d'avis a été envoyée à a@b.com")
|
||||||
expect(Avis.count).to eq(old_avis_count + 2)
|
expect(Avis.count).to eq(old_avis_count + 1)
|
||||||
expect(created_avis.email).to eq("a@b.com")
|
expect(created_avis.email).to eq("a@b.com")
|
||||||
expect(created_avis.dossier).to eq(dossier)
|
expect(created_avis.dossier).to eq(dossier)
|
||||||
expect(linked_avis.dossier).to eq(linked_dossier)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -68,7 +68,7 @@ FactoryBot.define do
|
||||||
trait :with_dossier_link do
|
trait :with_dossier_link do
|
||||||
after(:create) do |dossier, _evaluator|
|
after(:create) do |dossier, _evaluator|
|
||||||
# create linked dossier
|
# create linked dossier
|
||||||
linked_dossier = create(:dossier)
|
linked_dossier = create(:dossier, :en_construction)
|
||||||
|
|
||||||
# find first type de champ dossier_link
|
# find first type de champ dossier_link
|
||||||
type_de_champ = dossier.procedure.types_de_champ.find do |t|
|
type_de_champ = dossier.procedure.types_de_champ.find do |t|
|
||||||
|
|
|
@ -12,6 +12,9 @@ feature 'Inviting an expert:' do
|
||||||
|
|
||||||
context 'as an Instructeur' do
|
context 'as an Instructeur' do
|
||||||
scenario 'I can invite an expert' do
|
scenario 'I can invite an expert' do
|
||||||
|
# assign instructeur to linked dossier
|
||||||
|
instructeur.assign_to_procedure(dossier.reload.linked_dossiers.first.procedure)
|
||||||
|
|
||||||
login_as instructeur.user, scope: :user
|
login_as instructeur.user, scope: :user
|
||||||
visit instructeur_dossier_path(procedure, dossier)
|
visit instructeur_dossier_path(procedure, dossier)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue