Commit 73f302ed authored by Yorick Peterse's avatar Yorick Peterse

Apply CI scope changes to the User model

These changes are based on those from commit
03f5ff75, except they use a UNION
instead of plucking IDs into memory.
parent fbdf3767
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment