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]
|
||||
|
||||
if create_avis_params[:invite_linked_dossiers].present?
|
||||
allowed_dossiers += dossier.linked_dossiers
|
||||
allowed_dossiers += dossier.linked_dossiers_for(current_instructeur)
|
||||
end
|
||||
|
||||
create_results = Avis.create(
|
||||
|
|
|
@ -588,6 +588,10 @@ class Dossier < ApplicationRecord
|
|||
Dossier.where(id: champs.filter(&:dossier_link?).map(&:value).compact)
|
||||
end
|
||||
|
||||
def linked_dossiers_for(instructeur)
|
||||
instructeur.dossiers.where(id: champs.filter(&:dossier_link?).map(&:value).compact)
|
||||
end
|
||||
|
||||
def hash_for_deletion_mail
|
||||
{ id: self.id, procedure_libelle: self.procedure.libelle }
|
||||
end
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
= f.submit 'Envoyer votre avis', class: 'button send'
|
||||
|
||||
- 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?
|
||||
= render partial: 'instructeurs/shared/avis/list', locals: { avis: @dossier.avis_for(current_instructeur), avis_seen_at: nil }
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
.container
|
||||
- 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?
|
||||
= render partial: 'instructeurs/shared/avis/list', locals: { avis: @dossier.avis, avis_seen_at: @avis_seen_at }
|
||||
|
|
|
@ -196,11 +196,17 @@ describe Instructeurs::AvisController, type: :controller do
|
|||
|
||||
context 'checked' do
|
||||
let(:invite_linked_dossiers) { true }
|
||||
|
||||
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 do
|
||||
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")
|
||||
|
@ -208,6 +214,14 @@ describe Instructeurs::AvisController, type: :controller do
|
|||
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(Avis.count).to eq(old_avis_count + 1)
|
||||
expect(created_avis.email).to eq("a@b.com")
|
||||
expect(created_avis.dossier).to eq(dossier)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -68,7 +68,7 @@ FactoryBot.define do
|
|||
trait :with_dossier_link do
|
||||
after(:create) do |dossier, _evaluator|
|
||||
# create linked dossier
|
||||
linked_dossier = create(:dossier)
|
||||
linked_dossier = create(:dossier, :en_construction)
|
||||
|
||||
# find first type de champ dossier_link
|
||||
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
|
||||
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
|
||||
visit instructeur_dossier_path(procedure, dossier)
|
||||
|
||||
|
|
Loading…
Reference in a new issue