Skip to content

Commit e1b4c97

Browse files
prevent orphaned RAs getting findings but no eng
1 parent 0c5102e commit e1b4c97

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

dojo/api_v2/serializers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,7 @@ def create(self, validated_data):
15571557
ra_helper.add_findings_to_risk_acceptance(user, instance, instance.accepted_findings.all())
15581558

15591559
# Add risk acceptance to engagement
1560+
# This is fine as Pro has its own model + relationshop to track links with engagements.
15601561
if instance.accepted_findings.exists():
15611562
engagement = instance.accepted_findings.first().test.engagement
15621563
engagement.risk_acceptance.add(instance)
@@ -1580,6 +1581,13 @@ def update(self, instance, validated_data):
15801581
# Remove the ones that were not present in the payload
15811582
for finding in findings_to_remove:
15821583
ra_helper.remove_finding_from_risk_acceptance(user, instance, finding)
1584+
1585+
# Handle orphaned risk acceptances: link to engagement if it now has findings
1586+
# This is fine as Pro has its own model + relationshop to track links with engagements.
1587+
if instance.accepted_findings.exists() and not instance.engagement:
1588+
engagement = instance.accepted_findings.first().test.engagement
1589+
engagement.risk_acceptance.add(instance)
1590+
15831591
return instance
15841592

15851593
@extend_schema_field(serializers.CharField())

0 commit comments

Comments
 (0)