diff options
Diffstat (limited to 'app/services/search_service.rb')
-rw-r--r-- | app/services/search_service.rb | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/app/services/search_service.rb b/app/services/search_service.rb index bf21eba28f7..650dc197f8c 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -5,7 +5,6 @@ class SearchService SEARCH_TERM_LIMIT = 64 SEARCH_CHAR_LIMIT = 4096 - DEFAULT_PER_PAGE = Gitlab::SearchResults::DEFAULT_PER_PAGE MAX_PER_PAGE = 200 @@ -62,8 +61,8 @@ class SearchService @search_results ||= search_service.execute end - def search_objects - @search_objects ||= redact_unauthorized_results(search_results.objects(scope, page: params[:page], per_page: per_page)) + def search_objects(preload_method = nil) + @search_objects ||= redact_unauthorized_results(search_results.objects(scope, page: params[:page], per_page: per_page, preload_method: preload_method)) end private @@ -83,16 +82,21 @@ class SearchService end def redact_unauthorized_results(results_collection) - results = results_collection.to_a - permitted_results = results.select { |object| visible_result?(object) } + redacted_results = results_collection.reject { |object| visible_result?(object) } + + if redacted_results.any? + redacted_log = redacted_results.each_with_object({}) do |object, memo| + memo[object.id] = { ability: :"read_#{object.to_ability_name}", id: object.id, class_name: object.class.name } + end + + log_redacted_search_results(redacted_log.values) - redacted_results = (results - permitted_results).each_with_object({}) do |object, memo| - memo[object.id] = { ability: :"read_#{object.to_ability_name}", id: object.id, class_name: object.class.name } + return results_collection.id_not_in(redacted_log.keys) if results_collection.is_a?(ActiveRecord::Relation) end - log_redacted_search_results(redacted_results.values) if redacted_results.any? + return results_collection if results_collection.is_a?(ActiveRecord::Relation) - return results_collection.id_not_in(redacted_results.keys) if results_collection.is_a?(ActiveRecord::Relation) + permitted_results = results_collection - redacted_results Kaminari.paginate_array( permitted_results, |