diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-16 06:08:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-16 06:08:24 +0300 |
commit | e8d7ac4f14bcc70921ea9d63c75cd2e7f2cd5c31 (patch) | |
tree | 052085464aee0497ae525771ed066ef6a83c3eee /app/services | |
parent | 292d054661cc3e24bb1a4be98dacfd41fa7ad14e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/search_service.rb | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 5453940f8b7..650dc197f8c 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -82,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) } - 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 } + 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) + + 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, |