Account for enforced policies in policy approval setting overrides
What does this MR do and why?
We are working on warn mode for merge request approval policies (&15552).
Addresses a follow-up to !208075 (merged) where we started noting approval_settings overrides from merge request approval policies that are in warn-mode.
When a warn-mode and default-enforced policy apply to a project, and the warn-mode policy's approval_settings override the project settings, this should only be considered an override if the default-enforced policy's approval_settings doesn't enforce the setting.
References
Screenshots or screen recordings
| Before | After |
|---|---|
![]() |
![]() |
How to set up and validate locally
- Enable the feature flag:
echo "Feature.enable(:security_policy_approval_warn_mode)" | rails c - Create a new project
- Navigate to
Settings > Merge requests, and underApproval settings, untick thePrevent approval by merge request creatorcheckbox and clickSave changes - Navigate to
Code > Branchesand create thefoobarbranch - Navigate to
Settings > Protected branchesand protect thefoobarbranch - Navigate to
Secure > Policiesand create the following Merge request approval policies:
approval_policy:
- name: Warn Mode Policy A
enabled: true
enforcement_type: warn
rules:
- type: any_merge_request
branch_type: protected
commits: any
actions:
- type: require_approval
approvals_required: 1
role_approvers:
- owner
- type: send_bot_message
enabled: true
approval_settings:
prevent_approval_by_author: true
require_password_to_approve: false
approval_policy:
- name: Warn Mode Policy B
enabled: true
enforcement_type: warn
rules:
- type: any_merge_request
branch_type: protected
commits: any
actions:
- type: require_approval
approvals_required: 1
role_approvers:
- owner
- type: send_bot_message
enabled: true
approval_settings:
prevent_approval_by_author: false
require_password_to_approve: true
approval_policy:
- name: Enforced Policy
enabled: true
rules:
- type: any_merge_request
branch_type: protected
commits: any
actions:
- type: require_approval
approvals_required: 1
role_approvers:
- owner
- type: send_bot_message
enabled: true
approval_settings:
prevent_approval_by_author: true
- Open a new merge request targeting the default branch
- Compare the approval setting override section in the bot comment to the screenshot above
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #563868 (closed)
Edited by Dominic Bauer

