Commit 87c373f7 authored by Stan Hu's avatar Stan Hu

Merge branch '273433-fix-handling-empty-approval-project-rules-when-creating-mr' into 'master'

Fix creating an MR when a project approval rule has no approvers

See merge request gitlab-org/gitlab!59671
parents 5a137f95 4c263881
......@@ -53,7 +53,7 @@ module ApprovalRules
rule_attributes[:user_ids] = provided_user_ids & visible_user_ids
end
if rule_attributes[:group_ids].blank? && rule_attributes[:user_ids].blank?
if rule_attributes[:group_ids].blank? && rule_attributes[:user_ids].blank? && rule_attributes[:name].blank?
rule_attributes[:rule_type] = :any_approver
rule_attributes[:name] = ApprovalRuleLike::ALL_MEMBERS
end
......
---
title: Fix creating an MR when a project approval rule has no approvers
merge_request: 59671
author:
type: fixed
......@@ -80,6 +80,22 @@ RSpec.describe ApprovalRules::ParamsFilteringService do
let(:expected_groups) { [accessible_group] }
end
# When a project approval rule is genuinely empty, it should not be converted
# an any_approver rule
context 'empty project approval rule' do
let(:approval_rules_attributes) { [{ name: 'Foo', user_ids: [], group_ids: [] }] }
it 'adds empty rule', :aggregate_failures do
rules = service.execute[:approval_rules_attributes]
expect(rules.size).to eq(1)
expect(rules[0]['name']).to eq('Foo')
expect(rules[0]['user_ids']).to be_empty
expect(rules[0]['group_ids']).to be_empty
expect(rules[0].key?('rule_type')).to be_falsy
end
end
context 'inapplicable user defined rules' do
let!(:source_rule) { create(:approval_project_rule, project: project) }
let!(:another_source_rule) { create(:approval_project_rule, project: project) }
......@@ -148,7 +164,7 @@ RSpec.describe ApprovalRules::ParamsFilteringService do
let(:can_update_approvers?) { true }
let(:approval_rules_attributes) do
[
{ user_ids: [], group_ids: [] }
{ user_ids: [], group_ids: [], name: '' }
]
end
......
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