@@ -1505,10 +1505,6 @@ class Engagement(models.Model):
15051505 default = "threat_model" , editable = False )
15061506 tmodel_path = models .CharField (max_length = 1000 , default = "none" ,
15071507 editable = False , blank = True , null = True )
1508- risk_acceptance = models .ManyToManyField ("Risk_Acceptance" ,
1509- default = None ,
1510- editable = False ,
1511- blank = True )
15121508 done_testing = models .BooleanField (default = False , editable = False )
15131509 engagement_type = models .CharField (editable = True , max_length = 30 , default = "Interactive" ,
15141510 null = True ,
@@ -1550,7 +1546,7 @@ def copy(self):
15501546 old_notes = list (self .notes .all ())
15511547 old_files = list (self .files .all ())
15521548 old_tags = list (self .tags .all ())
1553- old_risk_acceptances = list (self .risk_acceptance .all ())
1549+ old_risk_acceptances = list (self .risk_acceptance_set .all ())
15541550 old_tests = list (Test .objects .filter (engagement = self ))
15551551 # Save the object before setting any ManyToMany relationships
15561552 copy .save ()
@@ -1565,7 +1561,7 @@ def copy(self):
15651561 test .copy (engagement = copy )
15661562 # Copy the risk_acceptances
15671563 for risk_acceptance in old_risk_acceptances :
1568- copy . risk_acceptance .add ( risk_acceptance . copy (engagement = copy ) )
1564+ risk_acceptance .copy (engagement = copy )
15691565 # Assign any tags
15701566 copy .tags .set (old_tags )
15711567
@@ -1595,9 +1591,6 @@ def unaccepted_open_findings(self):
15951591
15961592 return findings
15971593
1598- def accept_risks (self , accepted_risks ):
1599- self .risk_acceptance .add (* accepted_risks )
1600-
16011594 @property
16021595 def has_jira_issue (self ):
16031596 import dojo .jira_link .helper as jira_helper
@@ -2163,9 +2156,6 @@ def unaccepted_open_findings(self):
21632156
21642157 return findings
21652158
2166- def accept_risks (self , accepted_risks ):
2167- self .engagement .risk_acceptance .add (* accepted_risks )
2168-
21692159 @property
21702160 def deduplication_algorithm (self ):
21712161 deduplicationAlgorithm = settings .DEDUPE_ALGO_LEGACY
@@ -3663,6 +3653,8 @@ class Risk_Acceptance(models.Model):
36633653
36643654 name = models .CharField (max_length = 300 , null = False , blank = False , help_text = _ ("Descriptive name which in the future may also be used to group risk acceptances together across engagements and products" ))
36653655
3656+ engagement = models .ForeignKey (Engagement , editable = False , blank = False , null = False , on_delete = models .CASCADE )
3657+
36663658 accepted_findings = models .ManyToManyField (Finding )
36673659
36683660 recommendation = models .CharField (choices = TREATMENT_CHOICES , max_length = 2 , null = False , default = TREATMENT_FIX , help_text = _ ("Recommendation from the security team." ), verbose_name = _ ("Security Recommendation" ))
@@ -3704,26 +3696,17 @@ def name_and_expiration_info(self):
37043696 return str (self .name ) + (" (expired " if self .is_expired else " (expires " ) + (timezone .localtime (self .expiration_date ).strftime ("%b %d, %Y" ) if self .expiration_date else "Never" ) + ")"
37053697
37063698 def get_breadcrumbs (self ):
3707- bc = self .engagement_set . first () .get_breadcrumbs ()
3699+ bc = self .engagement .get_breadcrumbs ()
37083700 bc += [{"title" : str (self ),
37093701 "url" : reverse ("view_risk_acceptance" , args = (
3710- self .engagement_set . first () .product .id , self .id ))}]
3702+ self .engagement .product .id , self .id ))}]
37113703 return bc
37123704
37133705 @property
37143706 def is_expired (self ):
37153707 return self .expiration_date_handled is not None
37163708
3717- # relationship is many to many, but we use it as one-to-many
3718- @property
3719- def engagement (self ):
3720- engs = self .engagement_set .all ()
3721- if engs :
3722- return engs [0 ]
3723-
3724- return None
3725-
3726- def copy (self , engagement = None ):
3709+ def copy (self , engagement ):
37273710 copy = _copy_model_util (self )
37283711 # Save the necessary ManyToMany relationships
37293712 old_notes = list (self .notes .all ())
@@ -3734,9 +3717,10 @@ def copy(self, engagement=None):
37343717 for notes in old_notes :
37353718 copy .notes .add (notes .copy ())
37363719 # Assign any accepted findings
3737- if engagement :
3738- new_accepted_findings = Finding .objects .filter (test__engagement = engagement , hash_code__in = old_accepted_findings_hash_codes , risk_accepted = True ).distinct ()
3739- copy .accepted_findings .set (new_accepted_findings )
3720+ new_accepted_findings = Finding .objects .filter (test__engagement = engagement , hash_code__in = old_accepted_findings_hash_codes , risk_accepted = True ).distinct ()
3721+ copy .accepted_findings .set (new_accepted_findings )
3722+ copy .engagement = engagement
3723+ copy .save ()
37403724 return copy
37413725
37423726
0 commit comments