Fix merge request approval rule validations
What does this MR do and why?
Fixes #247119 (closed)
When creating or updating merge request we allow users to supply approval_rules_attributes. Previously, the MergeApprovalRequestRule validations included
validates :name, uniqueness: { scope: [:merge_request_id, :section] }
However, we were saving the records via MergeRequest which means
- the validations were not being triggered (added
validates_associated :approval_rules
to MergeRequest) - the uniqueness validator is not designed to work with bulk upserts (switched to ruby instead of SQL for validation to ensure in-memory approval_rules are validated against each other, not against the db)
Screenshots or screen recordings
How to set up and validate locally
- Ensure you have an unlimited license installed in GDK
- Navigate to a project
- Create an MR with custom approval rules where multiple rules have the same name
- Save -> should now show error
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Joe Woodward