[frontend] Limit the amount of rules per policy
Why are we doing this work
Each rule requires an additional query. If we don't restrict the amount of rules per policy this can cause performance problems if users would setup a lot of rules.
Non-functional requirements
-
Documentation: -
Feature flag: vulnerability_management_policy_type -
Performance: -
Testing: unit tests
Implementation plan
- Limit the amount of rules to maximally 5 in https://gitlab.com/gitlab-org/gitlab/-/blob/enforce-max-policy-limit/ee/app/validators/json_schemas/security_orchestration_policy.json#L67
- Test this. Check merge request approval policy rules limit for inspiration.
- Conditionally hide "Add rule" if 5 rules has been added already. Update spec accordingly.
Verification steps
- Go to https://gitlab.com/gitlab-org/govern/threat-insights-demos/verification-projects/vulnerability-management-policy/security-reports/-/security/policies
- Click "Select policy" on the vulnerability management policy tile
- Click "New policy"
- Verify you can see "Add new rule" button
- Add 5 rules
- Verify you can still see "Add new rule" button, but now it's disabled. Verify that hovering on it shows a tooltip: "You can add a maximum of 5 rules."
- Go to yaml mode and add a new rule by copy-pasting
- Verify the yaml gets highlighted red and hovering shows the JSON schema tooltip mentioning the max of 5 rules
- Go back to rule mode, add a name, and click "Save policy". Verify that there is an error, coming from backend:
property '/vulnerability_management_policy/1/rules' is invalid: error_type=maxItems
Edited by Lorenz van Herwaarden