simplify and improve perf by making the feature works only for id search
This commit is contained in:
parent
d245e12559
commit
c2de73c09d
5 changed files with 20 additions and 13 deletions
|
@ -29,14 +29,22 @@ class RechercheController < ApplicationController
|
|||
@followed_dossiers_id = current_instructeur&.followed_dossiers&.where(id: @paginated_ids)&.ids || []
|
||||
@dossier_avis_ids_h = current_expert&.avis&.where(dossier_id: @paginated_ids)&.pluck(:dossier_id, :id).to_h || {}
|
||||
|
||||
# we want to retrieve dossiers that are not accessible to the instructor because he is not in the instructor group
|
||||
# to display an alert in the view
|
||||
instructeur_procedure_dossiers_ids = DossierSearchService
|
||||
.matching_dossiers(Dossier.joins(:procedure).where(procedure: {id: current_instructeur&.procedures&.ids}), @search_terms, with_annotation: true)
|
||||
# if an instructor search for a dossier which is in his procedures but not available to his intructor group
|
||||
# we want to display an alert in view
|
||||
|
||||
not_in_instructor_group_dossiers_ids = instructeur_procedure_dossiers_ids - matching_dossiers_ids
|
||||
# to make it simpler we only do it if the @search_terms is an id
|
||||
return if !DossierSearchService.id_compatible?(@search_terms)
|
||||
|
||||
@not_in_instructor_group_dossiers = Dossier.where(id: not_in_instructor_group_dossiers_ids)
|
||||
dossier_instructeur_searched_for = Dossier.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)
|
||||
|
||||
if current_instructeur&.procedures&.include?(dossier_instructeur_searched_for.procedure)
|
||||
@dossier_not_in_instructor_group = dossier_instructeur_searched_for
|
||||
else
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
|
||||
.container
|
||||
|
||||
- if @not_in_instructor_group_dossiers.present?
|
||||
- if @dossier_not_in_instructor_group.present?
|
||||
.fr-alert.fr-alert--info.fr-alert--sm.fr-mt-3w
|
||||
- @not_in_instructor_group_dossiers.each do |dossier|
|
||||
= p t('views.instructeurs.search.not_in_instructor_group_dossier', dossier_id: dossier.id, procedure_libelle: dossier.procedure.libelle, groupe_instructeur_label: dossier.groupe_instructeur.label)
|
||||
= 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)
|
||||
|
||||
.page-title
|
||||
Résultat de la recherche :
|
||||
|
|
|
@ -183,7 +183,7 @@ en:
|
|||
avis:
|
||||
introduction_file_explaination: "File attached to the request for advice"
|
||||
search:
|
||||
not_in_instructor_group_dossier: "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_libelle}” procedure corresponds to your search, but it is attached to the “%{groupe_instructeur_label}” instructor group."
|
||||
users:
|
||||
dossiers:
|
||||
archived_dossier: "Your file will be kept %{duree_conservation_dossiers_dans_ds} more months"
|
||||
|
|
|
@ -179,7 +179,7 @@ fr:
|
|||
avis:
|
||||
introduction_file_explaination: "Fichier joint à la demande d’avis"
|
||||
search:
|
||||
not_in_instructor_group_dossier: "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} »."
|
||||
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} »."
|
||||
users:
|
||||
dossiers:
|
||||
archived_dossier: "Votre dossier sera conservé %{duree_conservation_dossiers_dans_ds} mois supplémentaire"
|
||||
|
|
|
@ -74,7 +74,7 @@ describe RechercheController, type: :controller do
|
|||
it 'does not return the dossier' do
|
||||
subject
|
||||
expect(assigns(:projected_dossiers).count).to eq(0)
|
||||
expect(assigns(:not_in_instructor_group_dossiers).count).to eq(0)
|
||||
expect(assigns(:dossier_not_in_instructor_group)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -92,7 +92,7 @@ describe RechercheController, type: :controller do
|
|||
it 'does not return the dossier but it returns a message' do
|
||||
subject
|
||||
expect(assigns(:projected_dossiers).count).to eq(0)
|
||||
expect(assigns(:not_in_instructor_group_dossiers)).to eq([dossier3])
|
||||
expect(assigns(:dossier_not_in_instructor_group)).to eq(dossier3)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue