From 9207cc5aa57bb4b968e73a5f6f4938be2c6ccad9 Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Thu, 1 Oct 2020 18:29:53 +0200 Subject: [PATCH] =?UTF-8?q?Ajoute=20un=20flag=20pour=20qu'un=20expert=20ne?= =?UTF-8?q?=20puisse=20pas=20inviter=20une=20autre=20personne=20=C3=A0=20d?= =?UTF-8?q?onner=20son=20avis=20sur=20un=20dossier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 4 ++++ .../instructeurs/avis_controller.rb | 16 ++++++++++----- .../instructeurs/avis/instruction.html.haml | 2 +- .../instructeurs/avis_controller_spec.rb | 20 +++++++++++++++++++ .../avis/instruction.html.haml_spec.rb | 8 ++++++++ 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c307e0ffc..7ed38f687 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -82,6 +82,10 @@ class ApplicationController < ActionController::Base Flipper.enabled?(feature_name, current_user) end + def feature_enabled_for?(feature_name, item) + Flipper.enabled?(feature_name, item) + end + def authenticate_logged_user! if instructeur_signed_in? authenticate_instructeur! diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index 0b392fa13..8b2c0487c 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -71,13 +71,19 @@ module Instructeurs end def create_avis - @new_avis = create_avis_from_params(avis.dossier, avis.confidentiel) + @procedure = Procedure.find(params[:procedure_id]) + if !feature_enabled_for?(:expert_not_allowed_to_invite, @procedure) + @new_avis = create_avis_from_params(avis.dossier, avis.confidentiel) - if @new_avis.nil? - redirect_to instruction_instructeur_avis_path(avis.procedure, avis) + if @new_avis.nil? + redirect_to instruction_instructeur_avis_path(avis.procedure, avis) + else + set_avis_and_dossier + render :instruction + end else - set_avis_and_dossier - render :instruction + flash.alert = "Cette démarche ne vous permet pas de demander un avis externe" + redirect_to instruction_instructeur_avis_path(avis.procedure, avis) end end diff --git a/app/views/instructeurs/avis/instruction.html.haml b/app/views/instructeurs/avis/instruction.html.haml index 2dc248ee2..80c0c359c 100644 --- a/app/views/instructeurs/avis/instruction.html.haml +++ b/app/views/instructeurs/avis/instruction.html.haml @@ -31,7 +31,7 @@ .send-wrapper = f.submit 'Envoyer votre avis', class: 'button send' - - if !@dossier.termine? + - if !@dossier.termine? && !feature_enabled_for?(:expert_not_allowed_to_invite, @avis.procedure) = render partial: "instructeurs/shared/avis/form", locals: { url: avis_instructeur_avis_path(@avis.procedure, @avis), linked_dossiers: @dossier.linked_dossiers_for(current_instructeur), must_be_confidentiel: @avis.confidentiel?, avis: @new_avis } - if @dossier.avis_for(current_instructeur).present? diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index 497ac2e56..720578b19 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -152,6 +152,26 @@ describe Instructeurs::AvisController, type: :controller do end end + describe '#expert_cannot_invite_another_expert' do + let!(:previous_avis) { Avis.create(dossier: dossier, claimant: claimant, instructeur: instructeur, confidentiel: previous_avis_confidentiel) } + let(:previous_avis_confidentiel) { false } + let(:asked_confidentiel) { false } + let(:intro) { 'introduction' } + let(:emails) { ["toto@totomail.com"] } + let(:invite_linked_dossiers) { nil } + + before do + Flipper.enable_actor(:expert_not_allowed_to_invite, procedure) + post :create_avis, params: { id: previous_avis.id, procedure_id: procedure.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers, introduction_file: @introduction_file } } + end + + context 'when the expert cannot invite another expert' do + let(:asked_confidentiel) { false } + it { expect(flash.alert).to eq("Cette démarche ne vous permet pas de demander un avis externe") } + it { expect(response).to redirect_to(instruction_instructeur_avis_path(procedure, previous_avis)) } + end + end + describe '#create_avis' do let!(:previous_avis) { Avis.create(dossier: dossier, claimant: claimant, instructeur: instructeur, confidentiel: previous_avis_confidentiel) } let(:emails) { ['a@b.com'] } diff --git a/spec/views/instructeur/avis/instruction.html.haml_spec.rb b/spec/views/instructeur/avis/instruction.html.haml_spec.rb index 411d93f6c..ef112aba3 100644 --- a/spec/views/instructeur/avis/instruction.html.haml_spec.rb +++ b/spec/views/instructeur/avis/instruction.html.haml_spec.rb @@ -20,4 +20,12 @@ describe 'instructeurs/avis/instruction.html.haml', type: :view do let(:confidentiel) { false } it { is_expected.to have_text("Cet avis est partagé avec les autres experts") } end + + context 'when an expert is not allowed to invite another expert' do + let(:confidentiel) { false } + before do + Flipper.enable_actor(:expert_not_allowed_to_invite, avis.procedure) + end + it { is_expected.to have_no_text("Inviter des personnes à donner leur avis") } + end end