summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-04-10 03:36:09 +0000
committerStan Hu <stanhu@gmail.com>2019-04-10 03:36:09 +0000
commitbcfd04a2210c88997332c069493fb008e5d39d90 (patch)
treed8cd629d0620db96e7dee28f59ac95b1ad9561db /app/models
parent9d7ff90d9a7bd9dbe9184c9588510f247877274f (diff)
downloadgitlab-ce-bcfd04a2210c88997332c069493fb008e5d39d90.tar.gz
Revert "Merge branch 'sh-optimize-projects-api' into 'master'"revert-2cc01f12
This reverts merge request !26481
Diffstat (limited to 'app/models')
-rw-r--r--app/models/project.rb43
1 files changed, 8 insertions, 35 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 3e9bb6aedf1..66fc83113ea 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",