Commit 1a651214 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'id-ignore-any-approver-rules-with-groups' into 'master'

Fix creating merge requests with approval rules

See merge request gitlab-org/gitlab!33582
parents a88df3d3 c00f1154
...@@ -11,17 +11,25 @@ module ApprovalRules ...@@ -11,17 +11,25 @@ module ApprovalRules
end end
def visible_groups def visible_groups
@visible_groups ||= rule.groups.public_or_visible_to_user(current_user) @visible_groups ||= groups.public_or_visible_to_user(current_user)
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def hidden_groups def hidden_groups
@hidden_groups ||= rule.groups.where.not(id: visible_groups.map(&:id)) @hidden_groups ||= groups.where.not(id: visible_groups.map(&:id))
end end
def contains_hidden_groups? def contains_hidden_groups?
hidden_groups.loaded? ? hidden_groups.present? : hidden_groups.exists? hidden_groups.loaded? ? hidden_groups.present? : hidden_groups.exists?
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
private
def groups
return Group.none if rule.any_approver?
rule.groups
end
end end
end end
---
title: Fix creating merge requests with approval rules
merge_request: 33582
author:
type: fixed
...@@ -159,6 +159,33 @@ describe ApprovalRules::ParamsFilteringService do ...@@ -159,6 +159,33 @@ describe ApprovalRules::ParamsFilteringService do
expect(rule[:name]).to eq('All Members') expect(rule[:name]).to eq('All Members')
end end
end end
# A test case for https://gitlab.com/gitlab-org/gitlab/-/issues/208978#note_353379792
# Approval project rules with any_approver type have groups, but they shouldn't
context 'any approver rule from a project rule' do
let(:can_update_approvers?) { true }
let(:approval_rules_attributes) do
[
{ user_ids: [""], group_ids: [""], approval_project_rule_id: approval_rule.id }
]
end
context 'and the project rule has hidden groups' do
let(:approval_rule) do
create(:approval_project_rule, project: project, rule_type: :any_approver).tap do |rule|
rule.groups << create(:group, :private)
end
end
it 'sets rule type for the rules attributes' do
params = service.execute
rule = params[:approval_rules_attributes].first
expect(rule[:rule_type]).to eq(:any_approver)
expect(rule[:name]).to eq('All Members')
end
end
end
end end
context 'update' do context 'update' 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