Commit 200fe12e authored by Patrick Bajao's avatar Patrick Bajao

Allow approvals_required to be lower than project

MR level approvals_required are currently restricted to be higher
than project level approvals_required.

This removes that restriction so the logic will be simpler.
parent 88a905dd
......@@ -18,7 +18,7 @@ export const mapApprovalRuleResponse = res => ({
hasSource: Boolean(res.source_rule),
name: res.name,
approvalsRequired: res.approvals_required,
minApprovalsRequired: res.source_rule ? res.source_rule.approvals_required : 0,
minApprovalsRequired: 0,
approvers: res.approvers,
containsHiddenGroups: res.contains_hidden_groups,
users: res.users,
......@@ -41,7 +41,7 @@ export const mapMRSourceRule = ({ id, ...rule }) => ({
...rule,
hasSource: true,
sourceId: id,
minApprovalsRequired: rule.approvalsRequired || 0,
minApprovalsRequired: 0,
});
/**
......
......@@ -38,7 +38,6 @@ class ApprovalMergeRequestRule < ApplicationRecord
has_one :approval_project_rule, through: :approval_merge_request_rule_source
alias_method :source_rule, :approval_project_rule
validate :validate_approvals_required, unless: :report_approver?
validate :validate_approval_project_rule
enum rule_type: {
......@@ -116,15 +115,6 @@ class ApprovalMergeRequestRule < ApplicationRecord
private
def validate_approvals_required
return unless approval_project_rule
return unless approvals_required_changed?
if approvals_required < approval_project_rule.approvals_required
errors.add(:approvals_required, :greater_than_or_equal_to, count: approval_project_rule.approvals_required)
end
end
def validate_approval_project_rule
return if approval_project_rule.blank?
return if merge_request.project == approval_project_rule.project
......
---
title: Allow approvals_required to be lower than project
merge_request: 14902
author:
type: changed
......@@ -278,33 +278,6 @@ describe ApprovalMergeRequestRule do
subject.assign_attributes(approvals_required: -1)
expect(subject).to be_invalid
end
context 'when project rule is present' do
let(:project_rule) { create(:approval_project_rule, project: merge_request.project, approvals_required: 3) }
it 'has to be greater than or equal to project rule approvals_required' do
subject.assign_attributes(approval_project_rule: project_rule, approvals_required: 2)
subject.valid?
expect(subject.errors[:approvals_required]).to include("must be greater than or equal to 3")
end
context 'when report_approver rule' do
subject do
build(:report_approver_rule, merge_request: merge_request, approvals_required: 1).tap do |rule|
rule.approval_project_rule = project_rule
end
end
it 'skips validation' do
expect(subject).to be_valid
subject.approvals_required = 0
expect(subject).to be_valid
end
end
end
end
end
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