Skip to content

Conversation

@valentijnscholten
Copy link
Member

@valentijnscholten valentijnscholten commented Jan 21, 2026

Summary

Fixes #12644

This PR addresses several critical issues with the risk acceptance API:

  1. Risk acceptances created via API now appear in engagement panel

    • Added engagement.risk_acceptance.add(instance) in the create() method
    • Fixes the main bug where API-created risk acceptances were not linked to engagements
  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 (no need to create then delete)
  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)
    • Uses self.instance.accepted_findings.all() instead of filtering for better performance
  4. Comprehensive API tests

    • Added test_risk_acceptance_api.py with 7 test cases
    • Covers all edge cases and validation scenarios
    • All tests passing
  5. API now checks that user has Risk_Acceptance permission and not just Finding.Edit permission

This PR doesn't break Pro and doesn't need any changes in Pro as Pro has its own separate model and relationship to track links between Risk Aceeptance and Engagement.

Fixes DefectDojo#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 suite
@valentijnscholten valentijnscholten changed the title Fix risk acceptance API to link to engagement and add validations Fix risk acceptance API to link to engagement and add validations and permission check Jan 21, 2026
@mtesauro mtesauro requested a review from blakeaowens January 22, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Risk Acceptances created via the API do not show within the Risk Acceptance panel of an Engagement

1 participant