Merge pull request #4748 from tchak/avis-invitations-fix
Instructeur : corrige le fonctionnement de la case "Inviter les experts aussi sur les dossiers liés"
This commit is contained in:
commit
7c60b9dfa8
9 changed files with 103 additions and 23 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(
|
||||
|
|
|
@ -584,8 +584,9 @@ class Dossier < ApplicationRecord
|
|||
!PiecesJustificativesService.liste_pieces_justificatives(self).empty? && PiecesJustificativesService.pieces_justificatives_total_size(self) < Dossier::TAILLE_MAX_ZIP
|
||||
end
|
||||
|
||||
def linked_dossiers
|
||||
Dossier.where(id: champs.filter(&:dossier_link?).map(&:value).compact)
|
||||
def linked_dossiers_for(instructeur)
|
||||
dossier_ids = champs.filter(&:dossier_link?).map(&:value).compact
|
||||
(instructeur.dossiers.where(id: dossier_ids) + instructeur.dossiers_from_avis.where(id: dossier_ids)).uniq
|
||||
end
|
||||
|
||||
def hash_for_deletion_mail
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
= f.text_area :introduction, rows: 3, value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true
|
||||
|
||||
- if linked_dossiers.present?
|
||||
= f.check_box :invite_linked_dossiers, value: false
|
||||
= f.check_box :invite_linked_dossiers, {}, true, false
|
||||
= f.label :invite_linked_dossiers, t('helpers.label.invite_linked_dossiers', count: linked_dossiers.length, ids: linked_dossiers.map(&:id).to_sentence)
|
||||
|
||||
.flex.justify-between.align-baseline
|
||||
|
|
|
@ -187,27 +187,50 @@ describe Instructeurs::AvisController, type: :controller do
|
|||
let(:previous_avis_confidentiel) { false }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) }
|
||||
|
||||
it do
|
||||
context 'when the expert doesn’t share linked dossiers' do
|
||||
let(:invite_linked_dossiers) { false }
|
||||
|
||||
it 'sends a single avis for the main dossier, but doesn’t give access to the 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
|
||||
|
||||
context 'checked' do
|
||||
context 'when the expert also shares the linked dossiers' do
|
||||
let(:invite_linked_dossiers) { true }
|
||||
|
||||
context 'and the expert can access the linked dossiers' do
|
||||
let(:created_avis) { Avis.last(2).first }
|
||||
let(:linked_avis) { Avis.last }
|
||||
let(:linked_dossier) { dossier.reload.linked_dossiers.first }
|
||||
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs.filter(&:dossier_link?).map(&:value).compact) }
|
||||
let(:invite_linked_dossiers) do
|
||||
instructeur.assign_to_procedure(linked_dossier.procedure)
|
||||
true
|
||||
end
|
||||
|
||||
it do
|
||||
it 'sends one avis for the main dossier' 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)
|
||||
end
|
||||
|
||||
it 'sends another avis for the linked dossiers' do
|
||||
expect(Avis.count).to eq(old_avis_count + 2)
|
||||
expect(linked_avis.dossier).to eq(linked_dossier)
|
||||
end
|
||||
end
|
||||
|
||||
context 'but the expert can’t access the linked dossier' do
|
||||
it 'sends a single avis for the main dossier, but doesn’t give access to the 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
|
||||
end
|
||||
|
|
|
@ -430,6 +430,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
describe "#create_avis" do
|
||||
let(:invite_linked_dossiers) { false }
|
||||
let(:saved_avis) { dossier.avis.first }
|
||||
let!(:old_avis_count) { Avis.count }
|
||||
|
||||
|
@ -437,7 +438,7 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
post :create_avis, params: {
|
||||
procedure_id: procedure.id,
|
||||
dossier_id: dossier.id,
|
||||
avis: { emails: emails, introduction: 'intro', confidentiel: true }
|
||||
avis: { emails: emails, introduction: 'intro', confidentiel: true, invite_linked_dossiers: invite_linked_dossiers }
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -471,6 +472,57 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
it { expect(Avis.count).to eq(old_avis_count + 1) }
|
||||
it { expect(saved_avis.email).to eq("titi@titimail.com") }
|
||||
end
|
||||
|
||||
context 'with linked dossiers' do
|
||||
let(:asked_confidentiel) { false }
|
||||
let(:previous_avis_confidentiel) { false }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) }
|
||||
|
||||
context 'when the expert doesn’t share linked dossiers' do
|
||||
let(:invite_linked_dossiers) { false }
|
||||
|
||||
it 'sends a single avis for the main dossier, but doesn’t give access to the linked dossiers' do
|
||||
expect(flash.notice).to eq("Une demande d'avis a été envoyée à email@a.com")
|
||||
expect(Avis.count).to eq(old_avis_count + 1)
|
||||
expect(saved_avis.email).to eq("email@a.com")
|
||||
expect(saved_avis.dossier).to eq(dossier)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the expert also shares the linked dossiers' do
|
||||
let(:invite_linked_dossiers) { true }
|
||||
|
||||
context 'and the expert can access the linked dossiers' do
|
||||
let(:saved_avis) { Avis.last(2).first }
|
||||
let(:linked_avis) { Avis.last }
|
||||
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs.filter(&:dossier_link?).map(&:value).compact) }
|
||||
let(:invite_linked_dossiers) do
|
||||
instructeur.assign_to_procedure(linked_dossier.procedure)
|
||||
true
|
||||
end
|
||||
|
||||
it 'sends one avis for the main dossier' do
|
||||
expect(flash.notice).to eq("Une demande d'avis a été envoyée à email@a.com")
|
||||
expect(saved_avis.email).to eq("email@a.com")
|
||||
expect(saved_avis.dossier).to eq(dossier)
|
||||
end
|
||||
|
||||
it 'sends another avis for the linked dossiers' do
|
||||
expect(Avis.count).to eq(old_avis_count + 2)
|
||||
expect(linked_avis.dossier).to eq(linked_dossier)
|
||||
end
|
||||
end
|
||||
|
||||
context 'but the expert can’t access the linked dossier' do
|
||||
it 'sends a single avis for the main dossier, but doesn’t give access to the linked dossiers' do
|
||||
expect(flash.notice).to eq("Une demande d'avis a été envoyée à email@a.com")
|
||||
expect(Avis.count).to eq(old_avis_count + 1)
|
||||
expect(saved_avis.email).to eq("email@a.com")
|
||||
expect(saved_avis.dossier).to eq(dossier)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#show" do
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -9,9 +9,13 @@ feature 'Inviting an expert:' do
|
|||
let(:expert_password) { 'mot de passe d’expert' }
|
||||
let(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) }
|
||||
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs.filter(&:dossier_link?).map(&:value).compact) }
|
||||
|
||||
context 'as an Instructeur' do
|
||||
scenario 'I can invite an expert' do
|
||||
# assign instructeur to linked dossier
|
||||
instructeur.assign_to_procedure(linked_dossier.procedure)
|
||||
|
||||
login_as instructeur.user, scope: :user
|
||||
visit instructeur_dossier_path(procedure, dossier)
|
||||
|
||||
|
|
Loading…
Reference in a new issue