@@ -22,23 +22,21 @@ def expire_now(risk_acceptance):
2222 reactivated_findings = []
2323 if risk_acceptance .reactivate_expired :
2424 for finding in risk_acceptance .accepted_findings .all ():
25- if not finding .active :
26- logger .debug ("%i:%s: unaccepting a.k.a reactivating finding." , finding .id , finding )
27- finding .active = True
28- finding .risk_accepted = False
25+ if not finding .active : # not sure why this is important
26+ logger .debug ("%i:%s: unaccepting/reactivating finding." , finding .id , finding )
27+
2928 # Update any endpoint statuses on each of the findings
3029 update_endpoint_statuses (finding , accept_risk = False )
30+ risk_unaccept (None , finding , post_comments = False ) # comments will be posted at end
3131
3232 if risk_acceptance .restart_sla_expired :
3333 finding .sla_start_date = timezone .now ().date ()
34+ finding .save (dedupe_option = False ) # resave if changed after risk_unaccept
3435
35- finding .save (dedupe_option = False )
3636 reactivated_findings .append (finding )
37- # findings remain in this risk acceptance for reporting / metrics purposes
3837 else :
3938 logger .debug ("%i:%s already active, no changes made." , finding .id , finding )
4039
41- # best effort JIRA integration, no status changes
4240 post_jira_comments (risk_acceptance , risk_acceptance .accepted_findings .all (), expiration_message_creator )
4341
4442 risk_acceptance .expiration_date = timezone .now ()
@@ -189,7 +187,7 @@ def expiration_handler(*args, **kwargs):
189187 product = risk_acceptance .engagement .product ,
190188 url = reverse ("view_risk_acceptance" , args = (risk_acceptance .engagement .id , risk_acceptance .id )))
191189
192- post_jira_comments (risk_acceptance , expiration_warning_message_creator , heads_up_days )
190+ post_jira_comments (risk_acceptance , risk_acceptance . accepted_findings . all (), expiration_warning_message_creator , heads_up_days )
193191
194192 risk_acceptance .expiration_date_warned = timezone .now ()
195193 risk_acceptance .save ()
@@ -243,20 +241,22 @@ def unaccepted_message_creator(risk_acceptance, heads_up_days=0):
243241
244242
245243def post_jira_comment (finding , message_factory , heads_up_days = 0 ):
246- if not finding or not finding .has_jira_issue :
244+ if not finding or ( not finding .has_jira_issue and not finding . has_jira_group_issue ) :
247245 return
248-
249246 jira_project = jira_helper .get_jira_project (finding )
250247
251248 if jira_project and jira_project .risk_acceptance_expiration_notification :
252249 jira_instance = jira_helper .get_jira_instance (finding )
253-
254250 if jira_instance :
255251
256252 jira_comment = message_factory (None , heads_up_days )
257253
258- logger .debug ("Creating JIRA comment for something risk acceptance related" )
259- jira_helper .add_simple_jira_comment (jira_instance , finding .jira_issue , jira_comment )
254+ jira_issue = None
255+ if finding .has_jira_issue :
256+ jira_issue = finding .jira_issue
257+ elif finding .has_jira_group_issue :
258+ jira_issue = finding .finding_group .jira_issue
259+ jira_helper .add_simple_jira_comment (jira_instance , jira_issue , jira_comment )
260260
261261
262262def post_jira_comments (risk_acceptance , findings , message_factory , heads_up_days = 0 ):
@@ -270,11 +270,15 @@ def post_jira_comments(risk_acceptance, findings, message_factory, heads_up_days
270270
271271 if jira_instance :
272272 jira_comment = message_factory (risk_acceptance , heads_up_days )
273-
274273 for finding in findings :
274+ jira_issue = None
275275 if finding .has_jira_issue :
276- logger .debug ("Creating JIRA comment for something risk acceptance related" )
277- jira_helper .add_simple_jira_comment (jira_instance , finding .jira_issue , jira_comment )
276+ jira_issue = finding .jira_issue
277+ elif finding .has_jira_group_issue :
278+ jira_issue = finding .finding_group .jira_issue
279+
280+ if jira_issue :
281+ jira_helper .add_simple_jira_comment (jira_instance , jira_issue , jira_comment )
278282
279283
280284def get_expired_risk_acceptances_to_handle ():
@@ -319,7 +323,7 @@ def simple_risk_accept(user: Dojo_User, finding: Finding, perform_save=True) ->
319323 ))
320324
321325
322- def risk_unaccept (user : Dojo_User , finding : Finding , perform_save = True ) -> None :
326+ def risk_unaccept (user : Dojo_User , finding : Finding , perform_save = True , post_comments = True ) -> None :
323327 logger .debug ("unaccepting finding %i:%s if it is currently risk accepted" , finding .id , finding )
324328 if finding .risk_accepted :
325329 logger .debug ("unaccepting finding %i:%s" , finding .id , finding )
@@ -336,7 +340,12 @@ def risk_unaccept(user: Dojo_User, finding: Finding, perform_save=True) -> None:
336340
337341 # post_jira_comment might reload from database so see unaccepted finding. but the comment
338342 # only contains some text so that's ok
339- post_jira_comment (finding , unaccepted_message_creator )
343+ if post_comments :
344+ post_jira_comment (finding , unaccepted_message_creator )
345+
346+ # Update the JIRA obect for this finding
347+ jira_helper .save_and_push_to_jira (finding )
348+
340349 # Add a note to reflect that the finding was removed from the risk acceptance
341350 if user is not None :
342351 finding .notes .add (Notes .objects .create (
0 commit comments