diff options
author | Rémy Coutable <remy@rymai.me> | 2019-04-10 09:47:53 +0300 |
---|---|---|
committer | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-04-10 10:18:01 +0300 |
commit | 05655f3b63d207bd72c29e92a97270a8c801cb05 (patch) | |
tree | 442d0102b6c94fc5f15683d77b8be2fd09efe987 /app | |
parent | 5cc71ca7cdb375dc46659999d9ac871e16f221d0 (diff) |
Merge branch 'revert-2cc01f12' into 'master'
Revert "Merge branch 'sh-optimize-projects-api' into 'master'"
Closes #60315
See merge request gitlab-org/gitlab-ce!27195
(cherry picked from commit 3b163a75b7789c92a001343ebccaac00b645eb8d)
bcfd04a2 Revert "Merge branch 'sh-optimize-projects-api' into 'master'"
Diffstat (limited to 'app')
-rw-r--r-- | app/finders/projects_finder.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 43 |
2 files changed, 9 insertions, 36 deletions
diff --git a/app/finders/projects_finder.rb b/app/finders/projects_finder.rb index 0319e95d439..93d3c991846 100644 --- a/app/finders/projects_finder.rb +++ b/app/finders/projects_finder.rb @@ -81,7 +81,7 @@ class ProjectsFinder < UnionFinder if private_only? current_user.authorized_projects else - Project.public_or_visible_to_user(current_user, params[:visibility_level]) + Project.public_or_visible_to_user(current_user) end end end diff --git a/app/models/project.rb b/app/models/project.rb index e2869fc2ad5..65e8c5b4191 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -459,41 +459,14 @@ class Project < ApplicationRecord # Returns a collection of projects that is either public or visible to the # logged in user. - # - # requested_visiblity_levels: Normally all projects that are visible - # to the user (e.g. internal and public) are queried, but this - # parameter allows the caller to narrow the search space to optimize - # database queries. For instance, a caller may only want to see - # internal projects. Instead of querying for internal and public - # projects and throwing away public projects, this parameter allows - # the query to be targeted for only internal projects. - def self.public_or_visible_to_user(user = nil, requested_visibility_levels = []) - return public_to_user unless user - - visible_levels = Gitlab::VisibilityLevel.levels_for_user(user) - include_private = true - requested_visibility_levels = Array(requested_visibility_levels) - - if requested_visibility_levels.present? - visible_levels &= requested_visibility_levels - include_private = requested_visibility_levels.include?(Gitlab::VisibilityLevel::PRIVATE) - end - - public_or_internal_rel = - if visible_levels.present? - where('projects.visibility_level IN (?)', visible_levels) - else - Project.none - end - - private_rel = - if include_private - where('EXISTS (?)', user.authorizations_for_projects) - else - Project.none - end - - public_or_internal_rel.or(private_rel) + def self.public_or_visible_to_user(user = nil) + if user + where('EXISTS (?) OR projects.visibility_level IN (?)', + user.authorizations_for_projects, + Gitlab::VisibilityLevel.levels_for_user(user)) + else + public_to_user + end end # project features may be "disabled", "internal", "enabled" or "public". If "internal", |