From 29980ab1309a9933c78112db21cbd59972b40d40 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 17 Oct 2023 14:25:14 +0200 Subject: [PATCH] fix(search): show a message if searching for deleted dossier --- app/controllers/recherche_controller.rb | 7 +++++++ app/models/instructeur.rb | 1 + app/views/recherche/index.html.haml | 3 +++ config/locales/en.yml | 3 ++- config/locales/fr.yml | 1 + spec/controllers/recherche_controller_spec.rb | 15 +++++++++++++++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/controllers/recherche_controller.rb b/app/controllers/recherche_controller.rb index 116cde511..7280671f6 100644 --- a/app/controllers/recherche_controller.rb +++ b/app/controllers/recherche_controller.rb @@ -9,6 +9,13 @@ class RechercheController < ApplicationController def index @search_terms = search_terms + @dossiers_count = 0 + + if instructeur_signed_in? && DossierSearchService.id_compatible?(@search_terms) + @deleted_dossier = current_instructeur.deleted_dossiers.find_by(dossier_id: @search_terms) + end + + return if @deleted_dossier.present? @instructeur_dossiers_ids = DossierSearchService .matching_dossiers(current_instructeur&.dossiers, @search_terms, with_annotation: true) diff --git a/app/models/instructeur.rb b/app/models/instructeur.rb index 5a5f92b16..a856c203a 100644 --- a/app/models/instructeur.rb +++ b/app/models/instructeur.rb @@ -5,6 +5,7 @@ class Instructeur < ApplicationRecord has_many :groupe_instructeurs, -> { order(:label) }, through: :assign_to has_many :unordered_groupe_instructeurs, through: :assign_to, source: :groupe_instructeur has_many :procedures, -> { distinct }, through: :unordered_groupe_instructeurs + has_many :deleted_dossiers, through: :procedures has_many :batch_operations, dependent: :nullify has_many :assign_to_with_email_notifications, -> { with_email_notifications }, class_name: 'AssignTo', inverse_of: :instructeur has_many :groupe_instructeur_with_email_notifications, through: :assign_to_with_email_notifications, source: :groupe_instructeur diff --git a/app/views/recherche/index.html.haml b/app/views/recherche/index.html.haml index 3e652405d..a8a6e90bc 100644 --- a/app/views/recherche/index.html.haml +++ b/app/views/recherche/index.html.haml @@ -5,6 +5,9 @@ - if @dossier_not_in_instructor_group.present? .fr-alert.fr-alert--info.fr-alert--sm.fr-mt-3w = p t('views.instructeurs.search.dossier_not_in_instructor_group', dossier_id: @dossier_not_in_instructor_group.id, procedure_libelle: @dossier_not_in_instructor_group.procedure.libelle, groupe_instructeur_label: @dossier_not_in_instructor_group.groupe_instructeur.label) + - if @deleted_dossier.present? + .fr-alert.fr-alert--info.fr-alert--sm.fr-mt-3w + = p t('views.instructeurs.search.deleted_dossier', dossier_id: @deleted_dossier.dossier_id, procedure_libelle: @deleted_dossier.procedure.libelle, deleted_at: l(@deleted_dossier.deleted_at)) .page-title Résultat de la recherche : diff --git a/config/locales/en.yml b/config/locales/en.yml index b42a1b05e..477434739 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -389,7 +389,8 @@ en: avis: introduction_file_explaination: "File attached to the request for advice" search: - dossier_not_in_instructor_group: "File no. %{dossier_id} of the “%{procedure_libelle}” procedure corresponds to your search, but it is attached to the “%{groupe_instructeur_label}” instructor group." + dossier_not_in_instructor_group: "File no. %{dossier_id} of the procedure “%{procedure_libelle}” matches your search but it is attached to the “%{groupe_instructeur_label}” instructor group." + deleted_dossier: "The File no. %{dossier_id} of the procedure “%{procedure_libelle}}” matches your search but it was deleted on %{deleted_at}." users: dossiers: archived_dossier: "Your file will be kept %{duree_conservation_dossiers_dans_ds} more months" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 080c89d98..afd649710 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -392,6 +392,7 @@ fr: introduction_file_explaination: "Fichier joint à la demande d’avis" search: dossier_not_in_instructor_group: "Le dossier n° %{dossier_id} de la procédure « %{procedure_libelle} » correspond à votre recherche mais il est rattaché au groupe d’instructeurs « %{groupe_instructeur_label} »." + deleted_dossier: "Le dossier n° %{dossier_id} de la procédure « %{procedure_libelle} » correspond à votre recherche mais il a été supprimé le %{deleted_at}." users: dossiers: archived_dossier: "Votre dossier sera conservé %{duree_conservation_dossiers_dans_ds} mois supplémentaire" diff --git a/spec/controllers/recherche_controller_spec.rb b/spec/controllers/recherche_controller_spec.rb index 6726df730..205ab2689 100644 --- a/spec/controllers/recherche_controller_spec.rb +++ b/spec/controllers/recherche_controller_spec.rb @@ -110,6 +110,21 @@ describe RechercheController, type: :controller do end end + context 'when dossier is deleted' do + let!(:deleted_dossier) { DeletedDossier.create_from_dossier(dossier, DeletedDossier.reasons.fetch(:user_request)) } + let(:query) { deleted_dossier.dossier_id } + + before { subject } + + it { is_expected.to have_http_status(200) } + + it 'does not return the dossier but it returns a message' do + subject + expect(assigns(:dossiers_count)).to eq(0) + expect(assigns(:deleted_dossier)).to eq(deleted_dossier) + end + end + context 'with an id out of range' do let(:query) { 123456789876543234567 }