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:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-18 21:06:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-18 21:06:21 +0300
commit6d59e989185a7d2645792b713d1b5d95d46651fd (patch)
treef89d869a6c557a3e6e0b9305290259ab1d6fb589 /app/finders/snippets_finder.rb
parent5c521d1f9b1e389e2f9b2b5fccf3798159a10f8d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders/snippets_finder.rb')
-rw-r--r--app/finders/snippets_finder.rb21
1 files changed, 16 insertions, 5 deletions
diff --git a/app/finders/snippets_finder.rb b/app/finders/snippets_finder.rb
index 6e2bb1ded43..bd6b6190fb5 100644
--- a/app/finders/snippets_finder.rb
+++ b/app/finders/snippets_finder.rb
@@ -41,13 +41,14 @@
class SnippetsFinder < UnionFinder
include FinderMethods
- attr_accessor :current_user, :project, :author, :scope
+ attr_accessor :current_user, :project, :author, :scope, :explore
def initialize(current_user = nil, params = {})
@current_user = current_user
@project = params[:project]
@author = params[:author]
@scope = params[:scope].to_s
+ @explore = params[:explore]
if project && author
raise(
@@ -66,13 +67,23 @@ class SnippetsFinder < UnionFinder
private
def init_collection
- if project
+ if explore
+ snippets_for_explore
+ elsif project
snippets_for_a_single_project
else
snippets_for_multiple_projects
end
end
+ # Produces a query that retrieves snippets for the Explore page
+ #
+ # We only show personal snippets here because this page is meant for
+ # discovery, and project snippets are of limited interest here.
+ def snippets_for_explore
+ Snippet.public_to_user(current_user).only_personal_snippets
+ end
+
# Produces a query that retrieves snippets from multiple projects.
#
# The resulting query will, depending on the user's permissions, include the
@@ -86,7 +97,7 @@ class SnippetsFinder < UnionFinder
# Each collection is constructed in isolation, allowing for greater control
# over the resulting SQL query.
def snippets_for_multiple_projects
- queries = [global_snippets]
+ queries = [personal_snippets]
if Ability.allowed?(current_user, :read_cross_project)
queries << snippets_of_visible_projects
@@ -100,8 +111,8 @@ class SnippetsFinder < UnionFinder
Snippet.for_project_with_user(project, current_user)
end
- def global_snippets
- snippets_for_author_or_visible_to_user.only_global_snippets
+ def personal_snippets
+ snippets_for_author_or_visible_to_user.only_personal_snippets
end
# Returns the snippets that the current user (logged in or not) can view.