summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2015-11-18 13:02:03 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2015-11-18 13:05:45 +0100
commit73f302edf98d6c292c048c913f76282058d6d81c (patch)
tree1e5637d3dc970aeff28342ee8bae6b2839008678 /app/models
parentfbdf3767495cd60b002f24ab4e9aa4d0c019de95 (diff)
downloadgitlab-ce-73f302edf98d6c292c048c913f76282058d6d81c.tar.gz
Apply CI scope changes to the User model
These changes are based on those from commit 03f5ff750b107b30a6d306aafb6699a9c9ecff0d, except they use a UNION instead of plucking IDs into memory.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/user.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 20a2457eec9..47439ce4b00 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -770,15 +770,10 @@ class User < ActiveRecord::Base
!solo_owned_groups.present?
end
- def ci_authorized_projects
- @ci_authorized_projects ||=
- Ci::Project.where("gitlab_id IN (#{projects_union.to_sql})")
- end
-
def ci_authorized_runners
@ci_authorized_runners ||= begin
runner_ids = Ci::RunnerProject.joins(:project).
- where("ci_projects.gitlab_id IN (#{projects_union.to_sql})").
+ where("ci_projects.gitlab_id IN (#{ci_projects_union.to_sql})").
select(:runner_id)
Ci::Runner.specific.where(id: runner_ids)
@@ -792,4 +787,13 @@ class User < ActiveRecord::Base
groups_projects.select(:id),
projects.select(:id)])
end
+
+ def ci_projects_union
+ scope = { access_level: [Gitlab::Access::MASTER, Gitlab::Access::OWNER] }
+ groups = groups_projects.where(members: scope)
+ other = projects.where(members: scope)
+
+ Gitlab::SQL::Union.new([personal_projects.select(:id), groups.select(:id),
+ other.select(:id)])
+ end
end