Commit 71ba4d37 authored by Pedro Pombeiro's avatar Pedro Pombeiro Committed by Matthias Käppler

Allow admin to register group runners at all times

Even if valid runner registrars doesn't specify permission for group

Changelog: fixed
parent cb2611a3
...@@ -80,8 +80,7 @@ class GroupPolicy < Namespaces::GroupProjectNamespaceSharedPolicy ...@@ -80,8 +80,7 @@ class GroupPolicy < Namespaces::GroupProjectNamespaceSharedPolicy
condition(:crm_enabled, score: 0, scope: :subject) { Feature.enabled?(:customer_relations, @subject) && @subject.crm_enabled? } condition(:crm_enabled, score: 0, scope: :subject) { Feature.enabled?(:customer_relations, @subject) && @subject.crm_enabled? }
with_scope :subject condition(:group_runner_registration_allowed) do
condition(:group_runner_registration_allowed, score: 0, scope: :subject) do
Feature.disabled?(:runner_registration_control) || Gitlab::CurrentSettings.valid_runner_registrars.include?('group') Feature.disabled?(:runner_registration_control) || Gitlab::CurrentSettings.valid_runner_registrars.include?('group')
end end
...@@ -280,7 +279,7 @@ class GroupPolicy < Namespaces::GroupProjectNamespaceSharedPolicy ...@@ -280,7 +279,7 @@ class GroupPolicy < Namespaces::GroupProjectNamespaceSharedPolicy
prevent :admin_crm_organization prevent :admin_crm_organization
end end
rule { ~group_runner_registration_allowed }.policy do rule { ~admin & ~group_runner_registration_allowed }.policy do
prevent :register_group_runners prevent :register_group_runners
end end
......
...@@ -1076,37 +1076,33 @@ RSpec.describe GroupPolicy do ...@@ -1076,37 +1076,33 @@ RSpec.describe GroupPolicy do
end end
describe 'register_group_runners' do describe 'register_group_runners' do
shared_examples 'expected outcome based on runner registration control' do context 'admin' do
context 'with runner_registration_control FF disabled' do let(:current_user) { admin }
before do
stub_feature_flags(runner_registration_control: false)
end
it { is_expected.to be_allowed(:register_group_runners) } context 'when admin mode is enabled', :enable_admin_mode do
end context 'with runner_registration_control FF disabled' do
before do
stub_feature_flags(runner_registration_control: false)
end
context 'with runner_registration_control FF enabled' do it { is_expected.to be_allowed(:register_group_runners) }
before do
stub_feature_flags(runner_registration_control: true)
end end
context 'with group runner registration disabled' do context 'with runner_registration_control FF enabled' do
before do before do
stub_application_setting(valid_runner_registrars: ['project']) stub_feature_flags(runner_registration_control: true)
end end
it { is_expected.to be_disallowed(:register_group_runners) } it { is_expected.to be_allowed(:register_group_runners) }
end
end
end
context 'admin' do context 'with group runner registration disabled' do
let(:current_user) { admin } before do
stub_application_setting(valid_runner_registrars: ['project'])
context 'when admin mode is enabled', :enable_admin_mode do end
it { is_expected.to be_allowed(:register_group_runners) }
it_behaves_like 'expected outcome based on runner registration control' it { is_expected.to be_allowed(:register_group_runners) }
end
end
end end
context 'when admin mode is disabled' do context 'when admin mode is disabled' do
...@@ -1119,7 +1115,29 @@ RSpec.describe GroupPolicy do ...@@ -1119,7 +1115,29 @@ RSpec.describe GroupPolicy do
it { is_expected.to be_allowed(:register_group_runners) } it { is_expected.to be_allowed(:register_group_runners) }
it_behaves_like 'expected outcome based on runner registration control' context 'with runner_registration_control FF disabled' do
before do
stub_feature_flags(runner_registration_control: false)
end
it { is_expected.to be_allowed(:register_group_runners) }
end
context 'with runner_registration_control FF enabled' do
before do
stub_feature_flags(runner_registration_control: true)
end
it { is_expected.to be_allowed(:register_group_runners) }
context 'with group runner registration disabled' do
before do
stub_application_setting(valid_runner_registrars: ['project'])
end
it { is_expected.to be_disallowed(:register_group_runners) }
end
end
end end
context 'with maintainer' do context 'with maintainer' do
......
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