diff --git a/config/feature_flags/development/restrict_pipeline_cancellation_by_role.yml b/config/feature_flags/development/restrict_pipeline_cancellation_by_role.yml deleted file mode 100644 index 0ef8a5d38dbec33f49d3209969f4814186a321f9..0000000000000000000000000000000000000000 --- a/config/feature_flags/development/restrict_pipeline_cancellation_by_role.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: restrict_pipeline_cancellation_by_role -introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/135047 -rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/429699 -milestone: '16.6' -type: development -group: group::pipeline execution -default_enabled: false diff --git a/doc/ci/pipelines/settings.md b/doc/ci/pipelines/settings.md index 4768c04c74810662aa77f90703bec3998ca54bba..31a2b74f5559bd51ac1b78b1045bb3fd9af58178 100644 --- a/doc/ci/pipelines/settings.md +++ b/doc/ci/pipelines/settings.md @@ -105,7 +105,7 @@ For more information, see [Deployment safety](../environments/deployment_safety. ## Restrict roles that can cancel pipelines or jobs **(PREMIUM ALL)** -> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/410634) in GitLab 16.7 [with a flag](../../administration/feature_flags.md) named `restrict_pipeline_cancellation_by_role`. Disabled by default. +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/137301) in GitLab 16.7. You can customize which roles have permission to cancel pipelines or jobs. diff --git a/ee/app/models/ci/project_cancellation_restriction.rb b/ee/app/models/ci/project_cancellation_restriction.rb index 3daeb937513ce8fe70c249e78f3e1021715d8981..794566c4750e71279a6635f8a4213a8c9d3a2b1d 100644 --- a/ee/app/models/ci/project_cancellation_restriction.rb +++ b/ee/app/models/ci/project_cancellation_restriction.rb @@ -27,8 +27,7 @@ def enabled? return false unless @project return false unless @ci_settings - Feature.enabled?(:restrict_pipeline_cancellation_by_role, @project) && - @project.licensed_feature_available?(:ci_pipeline_cancellation_restrictions) + @project.licensed_feature_available?(:ci_pipeline_cancellation_restrictions) end strong_memoize_attr :enabled? end diff --git a/ee/spec/models/ci/project_cancellation_restriction_spec.rb b/ee/spec/models/ci/project_cancellation_restriction_spec.rb index 9de39267f9365ed889d9d957733e3839c3c99f56..c04c1c780b31c1e92b3a9f16f9d2c7aa486b8f24 100644 --- a/ee/spec/models/ci/project_cancellation_restriction_spec.rb +++ b/ee/spec/models/ci/project_cancellation_restriction_spec.rb @@ -14,9 +14,7 @@ context 'when no project' do let(:project) { nil } - it 'returns false' do - is_expected.to be false - end + it { is_expected.to be false } end context 'when no ci settings' do @@ -24,14 +22,12 @@ allow(project).to receive(:ci_cd_settings).and_return(nil) end - it 'returns false' do - is_expected.to be false - end + it { is_expected.to be false } end - context 'when cancellation restrictions are enabled' do + context 'when the licensed feature is enabled' do before do - stub_enabled + stub_licensed_features(ci_pipeline_cancellation_restrictions: true) end it 'returns true if maintainers are the only ones allowed to cancel' do @@ -49,14 +45,8 @@ end end - context 'when cancellation restrictions are disabled' do - before do - stub_disabled - end - - it 'returns false' do - is_expected.to be false - end + context 'when the licensed_features is disabled' do + it { is_expected.to be false } end end @@ -66,9 +56,7 @@ context 'when no project' do let(:project) { nil } - it 'returns false' do - is_expected.to be false - end + it { is_expected.to be false } end context 'when no ci settings' do @@ -76,14 +64,12 @@ allow(project).to receive(:ci_cd_settings).and_return(nil) end - it 'returns false' do - is_expected.to be false - end + it { is_expected.to be false } end - context 'when cancellation restrictions are enabled' do + context 'when the licensed feature is enabled' do before do - stub_enabled + stub_licensed_features(ci_pipeline_cancellation_restrictions: true) end it 'returns true if no one is allowed to cancel' do @@ -101,14 +87,8 @@ end end - context 'when cancellation restrictions are disabled' do - before do - stub_disabled - end - - it 'returns false' do - is_expected.to be false - end + context 'when the licensed_features is disabled' do + it { is_expected.to be false } end end @@ -118,9 +98,7 @@ context 'when no project' do let(:project) { nil } - it 'returns false' do - is_expected.to be false - end + it { is_expected.to be false } end context 'when no ci settings' do @@ -128,59 +106,23 @@ allow(project).to receive(:ci_cd_settings).and_return(nil) end - it 'returns false' do - is_expected.to be false - end + it { is_expected.to be false } end - context 'when the feature is enabled and licensed' do + context 'when the feature is licensed' do before do - stub_enabled - end - - it 'returns true' do - is_expected.to be true - end - end - - context 'when the feature is disabled' do - before do - stub_feature_flags(restrict_pipeline_cancellation_by_role: false) stub_licensed_features(ci_pipeline_cancellation_restrictions: true) end - it 'returns false' do - is_expected.to be false - end + it { is_expected.to be true } end - context 'when the feature is enabled but not licensed' do + context 'when the feature is not licensed' do before do stub_licensed_features(ci_pipeline_cancellation_restrictions: false) end - it 'returns false' do - is_expected.to be false - end + it { is_expected.to be false } end - - context 'when the feature is disabled and not licensed' do - before do - stub_disabled - end - - it 'returns false' do - is_expected.to be false - end - end - end - - def stub_enabled - stub_licensed_features(ci_pipeline_cancellation_restrictions: true) - end - - def stub_disabled - stub_feature_flags(restrict_pipeline_cancellation_by_role: false) - stub_licensed_features(ci_pipeline_cancellation_restrictions: false) end end diff --git a/ee/spec/policies/project_policy_spec.rb b/ee/spec/policies/project_policy_spec.rb index 1898a99111474a85dfa2459e16bb113c4c7e987f..0feaed6567c998bd8856020ff157944bb2181429 100644 --- a/ee/spec/policies/project_policy_spec.rb +++ b/ee/spec/policies/project_policy_spec.rb @@ -1731,37 +1731,6 @@ it { is_expected.to(allowed ? be_allowed(ability) : be_disallowed(ability)) } end end - - context 'when feature is disabled' do - where(:restricted_role, :actual_role, :allowed) do - :developer | :guest | false - :developer | :reporter | false - :developer | :developer | true - :developer | :maintainer | true - :developer | :owner | true - :maintainer | :guest | false - :maintainer | :reporter | false - :maintainer | :developer | true - :maintainer | :maintainer | true - :maintainer | :owner | true - :no_one | :guest | false - :no_one | :reporter | false - :no_one | :developer | true - :no_one | :maintainer | true - :no_one | :owner | true - end - - with_them do - let(:current_user) { public_send(actual_role) } - - before do - stub_feature_flags(restrict_pipeline_cancellation_by_role: false) - project.update!(restrict_pipeline_cancellation_role: restricted_role) - end - - it { is_expected.to(allowed ? be_allowed(ability) : be_disallowed(ability)) } - end - end end describe 'prevents cancel_pipeline when CI cancllation restricted' do