Commit e98438d4 authored by Dylan Griffith's avatar Dylan Griffith

Revert changes to User#ci_authorized_users to defer group runner API changes to later

parent 0d30b00d
...@@ -995,17 +995,10 @@ class User < ActiveRecord::Base ...@@ -995,17 +995,10 @@ class User < ActiveRecord::Base
def ci_authorized_runners def ci_authorized_runners
@ci_authorized_runners ||= begin @ci_authorized_runners ||= begin
project_runner_ids = Ci::RunnerProject runner_ids = Ci::RunnerProject
.where(project: authorized_projects(Gitlab::Access::MASTER)) .where(project: authorized_projects(Gitlab::Access::MASTER))
.select(:runner_id) .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
end end
...@@ -1194,11 +1187,6 @@ class User < ActiveRecord::Base ...@@ -1194,11 +1187,6 @@ class User < ActiveRecord::Base
max_member_access_for_group_ids([group_id])[group_id] max_member_access_for_group_ids([group_id])[group_id]
end end
def owned_or_masters_groups
union = Gitlab::SQL::Union.new([owned_groups, masters_groups])
Group.from("(#{union.to_sql}) namespaces")
end
protected protected
# override, from Devise::Validatable # override, from Devise::Validatable
......
...@@ -1787,12 +1787,14 @@ describe User do ...@@ -1787,12 +1787,14 @@ describe User do
describe '#ci_authorized_runners' do describe '#ci_authorized_runners' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:runner_1) { create(:ci_runner) } let(:runner) { create(:ci_runner) }
let(:runner_2) { create(:ci_runner) }
context 'without any projects nor groups' do before do
let!(:project) { create(:project, runners: [runner_1]) } project.runners << runner
let!(:group) { create(:group) } end
context 'without any projects' do
let(:project) { create(:project) }
it 'does not load' do it 'does not load' do
expect(user.ci_authorized_runners).to be_empty expect(user.ci_authorized_runners).to be_empty
...@@ -1801,38 +1803,10 @@ describe User do ...@@ -1801,38 +1803,10 @@ describe User do
context 'with personal projects runners' do context 'with personal projects runners' do
let(:namespace) { create(:namespace, owner: user) } let(:namespace) { create(:namespace, owner: user) }
let!(:project) { create(:project, namespace: namespace, runners: [runner_1]) } let(:project) { create(:project, namespace: namespace) }
it 'loads' do it 'loads' do
expect(user.ci_authorized_runners).to contain_exactly(runner_1) expect(user.ci_authorized_runners).to contain_exactly(runner)
end
end
context 'with personal group runner' do
let!(:project) { create(:project, runners: [runner_1]) }
let!(:group) do
create(:group, runners: [runner_2]).tap do |group|
group.add_owner(user)
end
end
it 'loads' do
expect(user.ci_authorized_runners).to contain_exactly(runner_2)
end
end
context 'with personal project and group runner' do
let(:namespace) { create(:namespace, owner: user) }
let!(:project) { create(:project, namespace: namespace, runners: [runner_1]) }
let!(:group) do
create(:group, runners: [runner_2]).tap do |group|
group.add_owner(user)
end
end
it 'loads' do
expect(user.ci_authorized_runners).to contain_exactly(runner_1, runner_2)
end end
end end
...@@ -1843,7 +1817,7 @@ describe User do ...@@ -1843,7 +1817,7 @@ describe User do
end end
it 'loads' do it 'loads' do
expect(user.ci_authorized_runners).to contain_exactly(runner_1) expect(user.ci_authorized_runners).to contain_exactly(runner)
end end
end end
...@@ -1860,21 +1834,7 @@ describe User do ...@@ -1860,21 +1834,7 @@ describe User do
context 'with groups projects runners' do context 'with groups projects runners' do
let(:group) { create(:group) } let(:group) { create(:group) }
let!(:project) { create(:project, group: group, runners: [runner_1]) } let(:project) { create(:project, group: group) }
def add_user(access)
group.add_user(user, access)
end
it_behaves_like :member
end
context 'with groups runners' do
let!(:group) do
create(:group, runners: [runner_1]).tap do |group|
group.add_owner(user)
end
end
def add_user(access) def add_user(access)
group.add_user(user, access) group.add_user(user, access)
...@@ -1884,7 +1844,7 @@ describe User do ...@@ -1884,7 +1844,7 @@ describe User do
end end
context 'with other projects runners' do context 'with other projects runners' do
let!(:project) { create(:project, runners: [runner_1]) } let(:project) { create(:project) }
def add_user(access) def add_user(access)
project.add_role(user, access) project.add_role(user, access)
...@@ -1897,7 +1857,7 @@ describe User do ...@@ -1897,7 +1857,7 @@ describe User do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:another_user) { create(:user) } let(:another_user) { create(:user) }
let(:subgroup) { create(:group, parent: group) } let(:subgroup) { create(:group, parent: group) }
let!(:project) { create(:project, group: subgroup, runners: [runner_1]) } let(:project) { create(:project, group: subgroup) }
def add_user(access) def add_user(access)
group.add_user(user, access) group.add_user(user, access)
......
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