Allow updating controls when requirement has five controls
What does this MR do and why?
Fixes saving a compliance framework when a requirement has five controls.
The control count validation (ComplianceRequirementsControl#controls_count_per_requirement) also counted the control being saved. So when a requirement had five controls, updating any existing control failed with "Compliance requirement cannot have more than 5 controls". This blocked the whole framework update, even when the requirement wasn't changed.
The validation now excludes the current record from the count. Adding a 6th control is still blocked.
Resolves #630360 (closed)
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
- Go to a group's Secure > Compliance center > Frameworks and create a framework with a requirement that has 5 controls.
- Edit the requirement and remove one control, or replace "At least two approvals" with "At least one approval".
- Click Update framework.
- Before this change, it fails with
Compliance requirement cannot have more than 5 controls. With this change, it saves.
Specs:
bin/rspec ee/spec/models/compliance_management/compliance_framework/compliance_requirements_control_spec.rb \
ee/spec/services/compliance_management/compliance_framework/compliance_requirements/update_service_spec.rbMR 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 #630360 (closed)