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
end
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
# rubocop: disable CodeReuse/ActiveRecord
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
def contains_hidden_groups?
hidden_groups.loaded? ? hidden_groups.present? : hidden_groups.exists?
end
# rubocop: enable CodeReuse/ActiveRecord
private
def groups
return Group.none if rule.any_approver?
rule.groups
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
expect(rule[:name]).to eq('All Members')
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
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