diff options
Diffstat (limited to 'app/finders/snippets_finder.rb')
-rw-r--r-- | app/finders/snippets_finder.rb | 21 |
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. |