diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-09-07 15:49:29 +0200 |
---|---|---|
committer | Alexis Reigel <alexis.reigel.ext@siemens.com> | 2018-04-23 09:21:42 +0200 |
commit | 7fbdd17cbcd19086694f575884191a6d137838dc (patch) | |
tree | 7078210d24ab355917cb13aece27470ae4ef1196 /app | |
parent | 9507f39459316719088722510a6ae11b79a4b442 (diff) | |
download | gitlab-ce-7fbdd17cbcd19086694f575884191a6d137838dc.tar.gz |
authorize group runners on user
Diffstat (limited to 'app')
-rw-r--r-- | app/models/group.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 16 |
2 files changed, 16 insertions, 2 deletions
diff --git a/app/models/group.rb b/app/models/group.rb index ec27f757f46..c34c913a16b 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -29,6 +29,8 @@ class Group < Namespace has_many :labels, class_name: 'GroupLabel' has_many :variables, class_name: 'Ci::GroupVariable' has_many :custom_attributes, class_name: 'GroupCustomAttribute' + has_many :runner_groups, class_name: 'Ci::RunnerGroup' + has_many :runners, through: :runner_groups, source: :runner, class_name: 'Ci::Runner' has_many :uploads, as: :model, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent diff --git a/app/models/user.rb b/app/models/user.rb index b0668148972..0c5c0fef9d4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -995,10 +995,17 @@ class User < ActiveRecord::Base def ci_authorized_runners @ci_authorized_runners ||= begin - runner_ids = Ci::RunnerProject + project_runner_ids = Ci::RunnerProject .where(project: authorized_projects(Gitlab::Access::MASTER)) .select(:runner_id) - Ci::Runner.specific.where(id: runner_ids) + + group_runner_ids = Ci::RunnerGroup + .where(group_id: owned_or_masters_groups.select(:id)) + .select(:runner_id) + + union = Gitlab::SQL::Union.new([project_runner_ids, group_runner_ids]) + + Ci::Runner.specific.where("ci_runners.id IN (#{union.to_sql})") # rubocop:disable GitlabSecurity/SqlInjection end end @@ -1187,6 +1194,11 @@ class User < ActiveRecord::Base max_member_access_for_group_ids([group_id])[group_id] end + def owned_or_masters_groups + union = Gitlab::SQL::Union.new([owned_groups, masters_groups]) + Group.from("(#{union.to_sql}) namespaces") + end + protected # override, from Devise::Validatable |