Apply CI scope changes to the User model
These changes are based on those from commit
03f5ff750b
, except they use a UNION
instead of plucking IDs into memory.
This commit is contained in:
parent
fbdf376749
commit
73f302edf9
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue