Fix risk acceptance API to link to engagement and add validations and permission check#14140
Draft
valentijnscholten wants to merge 4 commits intoDefectDojo:devfrom
Draft
Conversation
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
blakeaowens
approved these changes
Jan 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #12644
This PR addresses several critical issues with the risk acceptance API:
Risk acceptances created via API now appear in engagement panel
engagement.risk_acceptance.add(instance)in thecreate()methodAdded validation for
enable_full_risk_acceptanceproduct settingvalidate()method to fail early (no need to create then delete)Added protection against engagement switching
self.instance.accepted_findings.all()instead of filtering for better performanceComprehensive API tests
test_risk_acceptance_api.pywith 7 test casesAPI 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.