summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2015-11-18 12:30:24 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2015-11-18 13:05:45 +0100
commite116a356b8ac07bd3a935c40ceb274d67d808c83 (patch)
treeec0efa2e61d9102be9ff7bff6ff3ba41d2a36c0f /app
parenta4fc8112df3cf6cb344cfba65f5df46c7a99bef7 (diff)
downloadgitlab-ce-e116a356b8ac07bd3a935c40ceb274d67d808c83.tar.gz
Refactor User#authorized_groups/projects
These methods no longer include public groups/projects (that don't belong to the actual user) as this is handled by the various finder classes now. This also removes the need for passing extra arguments. Note that memoizing was removed _explicitly_. For whatever reason doing so messes up the users controller to a point where it claims a certain user does _not_ have access to certain groups/projects when it does have access. Existing code shouldn't be affected as these methods are only called in ways that they'd run queries anyway (e.g. a combination of "any?" and "each" which would run 2 queries regardless of memoizing).
Diffstat (limited to 'app')
-rw-r--r--app/models/user.rb35
1 files changed, 6 insertions, 29 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index d523b3f0491..20a2457eec9 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -389,40 +389,17 @@ class User < ActiveRecord::Base
end
end
- # Returns the groups a user has access to, optionally including any public
- # groups.
- #
- # public_internal - When set to "true" all public groups and groups of public
- # projects are also included.
- #
- # Returns an ActiveRecord::Relation
- def authorized_groups(public_internal = false)
+ # Returns the groups a user has access to
+ def authorized_groups
union = Gitlab::SQL::Union.
- new([groups.select(:id), authorized_projects(public_internal).
- select(:namespace_id)])
-
- sql = "namespaces.id IN (#{union.to_sql})"
-
- if public_internal
- sql << ' OR public IS TRUE'
- end
+ new([groups.select(:id), authorized_projects.select(:namespace_id)])
- Group.where(sql)
+ Group.where("namespaces.id IN (#{union.to_sql})")
end
# Returns the groups a user is authorized to access.
- #
- # public_internal - When set to "true" all public/internal projects will also
- # be included.
- def authorized_projects(public_internal = false)
- base = "projects.id IN (#{projects_union.to_sql})"
-
- if public_internal
- Project.where("#{base} OR projects.visibility_level IN (?)",
- Project.public_and_internal_levels)
- else
- Project.where(base)
- end
+ def authorized_projects
+ Project.where("projects.id IN (#{projects_union.to_sql})")
end
def owned_projects