Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/snippets_finder.rb')
-rw-r--r--app/finders/snippets_finder.rb39
1 files changed, 29 insertions, 10 deletions
diff --git a/app/finders/snippets_finder.rb b/app/finders/snippets_finder.rb
index 9dd7e508c22..cb824aca33f 100644
--- a/app/finders/snippets_finder.rb
+++ b/app/finders/snippets_finder.rb
@@ -67,17 +67,30 @@ class SnippetsFinder < UnionFinder
return Snippet.none if project.nil? && params[:project].present?
return Snippet.none if project && !project.feature_available?(:snippets, current_user)
- items = init_collection
- items = by_ids(items)
- items = items.with_optional_visibility(visibility_from_scope)
- items = by_created_at(items)
-
- items.order_by(sort_param)
+ filter_snippets.order_by(sort_param)
end
private
- def init_collection
+ def filter_snippets
+ if return_all_available_and_permited?
+ snippets = all_snippets_for_admin
+ else
+ snippets = all_snippets
+ snippets = by_ids(snippets)
+ snippets = snippets.with_optional_visibility(visibility_from_scope)
+ end
+
+ by_created_at(snippets)
+ end
+
+ def return_all_available_and_permited?
+ # Currently limited to access_levels `admin` and `auditor`
+ # See policies/base_policy.rb files for specifics.
+ params[:all_available] && current_user&.can_read_all_resources?
+ end
+
+ def all_snippets
if explore?
snippets_for_explore
elsif only_personal?
@@ -121,6 +134,12 @@ class SnippetsFinder < UnionFinder
prepared_union(queries)
end
+ def all_snippets_for_admin
+ return Snippet.only_project_snippets if only_project?
+
+ Snippet.all
+ end
+
def snippets_for_a_single_project
Snippet.for_project_with_user(project, current_user)
end
@@ -182,10 +201,10 @@ class SnippetsFinder < UnionFinder
end
end
- def by_ids(items)
- return items unless params[:ids].present?
+ def by_ids(snippets)
+ return snippets unless params[:ids].present?
- items.id_in(params[:ids])
+ snippets.id_in(params[:ids])
end
def author