[#2179] Don't depend on current_gestionnaire in DossierSearchService
This commit is contained in:
parent
57fd59b8d5
commit
a72388bb37
2 changed files with 7 additions and 7 deletions
|
@ -2,7 +2,7 @@ module NewGestionnaire
|
||||||
class RechercheController < GestionnaireController
|
class RechercheController < GestionnaireController
|
||||||
def index
|
def index
|
||||||
@search_terms = params[:q]
|
@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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
class DossierSearchService
|
class DossierSearchService
|
||||||
def self.matching_dossiers_for_gestionnaire(search_terms)
|
def self.matching_dossiers_for_gestionnaire(search_terms, gestionnaire)
|
||||||
# exact id match?
|
# exact id match?
|
||||||
id = search_terms.to_i
|
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.
|
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
|
end
|
||||||
|
|
||||||
if dossiers.nil?
|
if dossiers.nil?
|
||||||
|
@ -13,7 +13,7 @@ class DossierSearchService
|
||||||
# full text search
|
# full text search
|
||||||
if dossiers.empty?
|
if dossiers.empty?
|
||||||
dossiers = Search.new(
|
dossiers = Search.new(
|
||||||
gestionnaire: current_gestionnaire,
|
gestionnaire: gestionnaire,
|
||||||
query: search_terms
|
query: search_terms
|
||||||
).results
|
).results
|
||||||
end
|
end
|
||||||
|
@ -23,9 +23,9 @@ class DossierSearchService
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.dossiers_by_id(id)
|
def self.dossiers_by_id(id, gestionnaire)
|
||||||
dossiers = current_gestionnaire.dossiers.where(id: id) +
|
dossiers = gestionnaire.dossiers.where(id: id) +
|
||||||
current_gestionnaire.dossiers_from_avis.where(id: id)
|
gestionnaire.dossiers_from_avis.where(id: id)
|
||||||
dossiers.uniq
|
dossiers.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue