Commit dc759018 authored by Andreas Brandl's avatar Andreas Brandl
Browse files

Use yield instead of

parent e638c068d5c7
......@@ -61,25 +61,25 @@ def authorized_snippets
# Returns a collection of projects that is either public or visible to the
# logged in user.
# A caller may pass in a block to modify individual parts of
# A caller must pass in a block to modify individual parts of
# the query, e.g. to apply .with_feature_available_for_user on top of it.
# This is useful for performance as we can stick those additional filters
# at the bottom of e.g. the UNION.
def projects_for_user(&block)
return unless current_user
def projects_for_user
return yield(Project.public_to_user) unless current_user
# If the current_user is allowed to see all projects,
# we can shortcut and just return.
return if current_user.full_private_access?
return yield(Project.all) if current_user.full_private_access?
authorized = current_user
.where('project_authorizations.project_id =')
authorized_projects ='EXISTS (?)', authorized))
authorized_projects = yield(Project.where('EXISTS (?)', authorized))
levels = Gitlab::VisibilityLevel.levels_for_user(current_user)
visible_projects = levels))
visible_projects = yield(Project.where(visibility_level: levels))
# We use a UNION here instead of OR clauses since this results in better
# performance.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment