Commit 30ba0614 authored by Mark Chao's avatar Mark Chao

Rename to fallback_approvals_required

Fix spec so fallback path is tested
parent 2345197d
......@@ -44,20 +44,20 @@ class ApprovalState
return false unless project.feature_available?(:merge_request_approvers)
if regular_rules.empty?
overall_approvals_required > 0
fallback_approvals_required > 0
else
wrapped_approval_rules.any? { |rule| rule.approvals_required > 0 }
end
end
def overall_approvals_required
@overall_approvals_required ||= [project.approvals_before_merge, merge_request.approvals_before_merge || 0].max
def fallback_approvals_required
@fallback_approvals_required ||= [project.approvals_before_merge, merge_request.approvals_before_merge || 0].max
end
def approved?
strong_memoize(:approved) do
if regular_rules.empty?
approvals.size >= overall_approvals_required
approvals.size >= fallback_approvals_required
else
wrapped_approval_rules.all?(&:approved?)
end
......@@ -65,7 +65,17 @@ class ApprovalState
end
def any_approver_allowed?
approved? || overall_approvals_required > approvers.size
approved?
end
def approvals_required
strong_memoize(:approvals_required) do
if regular_rules.empty?
[project.approvals_before_merge, merge_request.approvals_before_merge || 0].max
else
wrapped_approval_rules.sum(&:approvals_required)
end
end
end
# Number of approvals remaining (excluding existing approvals) before the MR is
......@@ -73,7 +83,7 @@ class ApprovalState
def approvals_left
strong_memoize(:approvals_left) do
if regular_rules.empty?
[overall_approvals_required - approved_approvers.size, 0].max
[fallback_approvals_required - approved_approvers.size, 0].max
else
wrapped_approval_rules.sum(&:approvals_left)
end
......
......@@ -268,7 +268,7 @@ module EE
end
expose :wrapped_approval_rules, as: :rules, using: MergeRequestApprovalRule
expose :overall_approvals_required, as: :fallback_approvals_required
expose :fallback_approvals_required
end
# Decorates Project
......@@ -332,10 +332,7 @@ module EE
expose :approved?, as: :approved
# @deprecated, reads from first regular rule instead
expose :approvals_required do |approval_state|
approval_state.first_regular_rule&.approvals_required
end
expose :approvals_required
expose :approvals_left
......
......@@ -522,7 +522,6 @@ describe "API::MergeRequestApprovals with approval_rule enabled" do
context 'when disable_overriding_approvers_per_merge_request is false on the project' do
before do
project.update(disable_overriding_approvers_per_merge_request: false)
create(:approval_merge_request_rule, merge_request: merge_request)
end
it 'allows you to override approvals required' 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