diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-10-13 17:53:47 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-11-07 12:49:24 +0100 |
commit | 467b346f0684053081d7e762df1a2b5df5888543 (patch) | |
tree | df7b8363c57eb489ab280dcdf7362f23d8c15c72 /app/models | |
parent | 3c957c006633d2df44f0d23a3131294f9b657d2b (diff) | |
download | gitlab-ce-467b346f0684053081d7e762df1a2b5df5888543.tar.gz |
Add User#projects_with_reporter_access_limited_to
This method can be used to retrieve a list of projects for a user that
said user has reporter access to. This list is then be reduced down to
a specific set of projects. This allows you to reduce a list of projects
to a list of projects you have reporter access to in an efficient
manner.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/user.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 65e96ee6b2e..c0dffa7b6ea 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -444,6 +444,16 @@ class User < ActiveRecord::Base Project.where("projects.id IN (#{projects_union(min_access_level).to_sql})") end + # Returns the projects this user has reporter (or greater) access to, limited + # to at most the given projects. + # + # This method is useful when you have a list of projects and want to + # efficiently check to which of these projects the user has at least reporter + # access. + def projects_with_reporter_access_limited_to(projects) + authorized_projects(Gitlab::Access::REPORTER).where(id: projects) + end + def viewable_starred_projects starred_projects.where("projects.visibility_level IN (?) OR projects.id IN (#{projects_union.to_sql})", [Project::PUBLIC, Project::INTERNAL]) |