From 0bc7d61190e31fb625fa15015c6ea39979efc0d8 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 24 Aug 2023 15:44:22 +0200 Subject: [PATCH] fix(dossier): exclude brouillons from recherche --- app/controllers/recherche_controller.rb | 2 +- spec/controllers/recherche_controller_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/recherche_controller.rb b/app/controllers/recherche_controller.rb index 191b21e3671..116cde51194 100644 --- a/app/controllers/recherche_controller.rb +++ b/app/controllers/recherche_controller.rb @@ -35,7 +35,7 @@ def index # to make it simpler we only do it if the @search_terms is an id return if !DossierSearchService.id_compatible?(@search_terms) - dossier_instructeur_searched_for = Dossier.find_by(id: @search_terms) + dossier_instructeur_searched_for = Dossier.state_not_brouillon.find_by(id: @search_terms) return if dossier_instructeur_searched_for.nil? return if current_instructeur&.groupe_instructeur_ids&.include?(dossier_instructeur_searched_for.groupe_instructeur_id) diff --git a/spec/controllers/recherche_controller_spec.rb b/spec/controllers/recherche_controller_spec.rb index 78a128fdaf0..6726df73022 100644 --- a/spec/controllers/recherche_controller_spec.rb +++ b/spec/controllers/recherche_controller_spec.rb @@ -78,6 +78,20 @@ end end + context 'when dossier is brouillon without groupe instructeur' do + let(:dossier2) { create(:dossier, :brouillon, procedure: procedure) } + let(:query) { dossier2.id } + before { dossier2.update(groupe_instructeur_id: nil) } + + it { is_expected.to have_http_status(200) } + + it 'does not return the dossier' do + subject + expect(assigns(:projected_dossiers).count).to eq(0) + expect(assigns(:dossier_not_in_instructor_group)).to eq(nil) + end + end + context 'when instructeur is attached to the procedure but is not in the instructor group of the dossier' do let!(:gi_p1_1) { GroupeInstructeur.create(label: 'groupe 1', procedure: procedure) } let!(:gi_p1_2) { GroupeInstructeur.create(label: 'groupe 2', procedure: procedure) }