Merge pull request #9618 from tchak/fix-search-deleted-dossiers

fix(search): show a message if searching for deleted dossier
This commit is contained in:
Colin Darie 2023-10-19 08:37:06 +00:00 committed by GitHub
commit befb875318
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 1 deletions

View file

@ -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)

View file

@ -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

View file

@ -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 :

View file

@ -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"

View file

@ -392,6 +392,7 @@ fr:
introduction_file_explaination: "Fichier joint à la demande davis"
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 dinstructeurs « %{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"

View file

@ -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 }