Skip to content

Fix merge request approval rule validations

Joe Woodward requested to merge fix/approval_rule_validation into master

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

  1. the validations were not being triggered (added validates_associated :approval_rules to MergeRequest)
  2. 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

image

How to set up and validate locally

  1. Ensure you have an unlimited license installed in GDK
  2. Navigate to a project
  3. Create an MR with custom approval rules where multiple rules have the same name
  4. 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.

Edited by Joe Woodward

Merge request reports