diff --git a/app/controllers/new_gestionnaire/recherche_controller.rb b/app/controllers/new_gestionnaire/recherche_controller.rb index ec58b9083..c50d321ad 100644 --- a/app/controllers/new_gestionnaire/recherche_controller.rb +++ b/app/controllers/new_gestionnaire/recherche_controller.rb @@ -2,7 +2,7 @@ module NewGestionnaire class RechercheController < GestionnaireController def index @search_terms = params[:q] - @dossiers = DossierSearchService.matching_dossiers_for_gestionnaire(@search_terms) + @dossiers = DossierSearchService.matching_dossiers_for_gestionnaire(@search_terms, current_gestionnaire) end end end diff --git a/app/services/dossier_search_service.rb b/app/services/dossier_search_service.rb index 1cf851b29..c00c2964f 100644 --- a/app/services/dossier_search_service.rb +++ b/app/services/dossier_search_service.rb @@ -1,9 +1,9 @@ class DossierSearchService - def self.matching_dossiers_for_gestionnaire(search_terms) + def self.matching_dossiers_for_gestionnaire(search_terms, gestionnaire) # exact id match? id = search_terms.to_i if id != 0 && id_compatible?(id) # Sometimes gestionnaire is searching dossiers with a big number (ex: SIRET), ActiveRecord can't deal with them and throws ActiveModel::RangeError. id_compatible? prevents this. - dossiers = dossiers_by_id(id) + dossiers = dossiers_by_id(id, gestionnaire) end if dossiers.nil? @@ -13,7 +13,7 @@ class DossierSearchService # full text search if dossiers.empty? dossiers = Search.new( - gestionnaire: current_gestionnaire, + gestionnaire: gestionnaire, query: search_terms ).results end @@ -23,9 +23,9 @@ class DossierSearchService private - def self.dossiers_by_id(id) - dossiers = current_gestionnaire.dossiers.where(id: id) + - current_gestionnaire.dossiers_from_avis.where(id: id) + def self.dossiers_by_id(id, gestionnaire) + dossiers = gestionnaire.dossiers.where(id: id) + + gestionnaire.dossiers_from_avis.where(id: id) dossiers.uniq end