Commit 008456a
committed
Fix risk acceptance API to link to engagement and add validations
Fixes #12644
This commit addresses several issues with the risk acceptance API:
1. Risk acceptances created via API now appear in engagement panel
- Added engagement.risk_acceptance.add(instance) in create() method
- Fixes the main bug where API-created risk acceptances were orphaned
2. Added validation for enable_full_risk_acceptance product setting
- API now respects the product-level setting before creating instances
- Validates in validate() method to fail early
3. Added protection against engagement switching
- Prevents moving risk acceptances between engagements via PATCH/PUT
- Validates even when risk acceptance has no findings (edge case)
4. Performance improvement
- Use self.instance.accepted_findings.all() instead of filtering
5. Comprehensive API tests
- Added test_risk_acceptance_api.py with 7 test cases
- Covers all edge cases and validation scenarios
- All tests passing
Changes:
- dojo/api_v2/serializers.py: Enhanced RiskAcceptanceSerializer
- unittests/test_risk_acceptance_api.py: New comprehensive test suite1 parent 179abcc commit 008456a
2 files changed
Lines changed: 383 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1555 | 1555 | | |
1556 | 1556 | | |
1557 | 1557 | | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
1558 | 1564 | | |
1559 | 1565 | | |
1560 | 1566 | | |
| |||
1616 | 1622 | | |
1617 | 1623 | | |
1618 | 1624 | | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
1619 | 1632 | | |
1620 | | - | |
| 1633 | + | |
| 1634 | + | |
1621 | 1635 | | |
1622 | 1636 | | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
1623 | 1645 | | |
1624 | 1646 | | |
1625 | 1647 | | |
| |||
0 commit comments