112112 add_success_message_to_response ,
113113 apply_cwe_to_template ,
114114 calculate_grade ,
115- close_external_issue ,
116115 do_false_positive_history ,
117116 get_page_items ,
118117 get_page_items_and_count ,
@@ -1140,68 +1139,22 @@ def close_finding(request, fid):
11401139 if request .method == "POST" :
11411140 form = CloseFindingForm (request .POST , missing_note_types = missing_note_types )
11421141
1143- close_external_issue (finding , "Closed by defectdojo" , "github" )
1144-
11451142 if form .is_valid ():
1146- now = timezone .now ()
1147- new_note = form .save (commit = False )
1148- new_note .author = request .user
1149- new_note .date = form .cleaned_data .get ("mitigated" ) or now
1150- new_note .save ()
1151- finding .notes .add (new_note )
1152-
1153- messages .add_message (
1154- request , messages .SUCCESS , "Note Saved." , extra_tags = "alert-success" ,
1155- )
1143+ messages .add_message (request , messages .SUCCESS , "Note Saved." , extra_tags = "alert-success" )
11561144
11571145 if len (missing_note_types ) <= 1 :
1158- finding .active = False
1159- now = timezone .now ()
1160- finding .mitigated = form .cleaned_data .get ("mitigated" ) or now
1161- finding .mitigated_by = (
1162- form .cleaned_data .get ("mitigated_by" ) or request .user
1146+ finding_helper .close_finding (
1147+ finding = finding ,
1148+ user = request .user ,
1149+ is_mitigated = True ,
1150+ mitigated = form .cleaned_data .get ("mitigated" ),
1151+ mitigated_by = form .cleaned_data .get ("mitigated_by" ) or request .user ,
1152+ false_p = form .cleaned_data .get ("false_p" , False ),
1153+ out_of_scope = form .cleaned_data .get ("out_of_scope" , False ),
1154+ duplicate = form .cleaned_data .get ("duplicate" , False ),
1155+ note_entry = form .cleaned_data .get ("entry" ),
1156+ note_type = form .cleaned_data .get ("note_type" ),
11631157 )
1164- finding .is_mitigated = True
1165- finding .under_review = False
1166- finding .last_reviewed = finding .mitigated
1167- finding .last_reviewed_by = request .user
1168- finding .false_p = form .cleaned_data .get ("false_p" , False )
1169- finding .out_of_scope = form .cleaned_data .get ("out_of_scope" , False )
1170- finding .duplicate = form .cleaned_data .get ("duplicate" , False )
1171- endpoint_status = finding .status_finding .all ()
1172- for status in endpoint_status :
1173- status .mitigated_by = (
1174- form .cleaned_data .get ("mitigated_by" ) or request .user
1175- )
1176- status .mitigated_time = form .cleaned_data .get ("mitigated" ) or now
1177- status .mitigated = True
1178- status .last_modified = timezone .now ()
1179- status .save ()
1180- # Clear the risk acceptance, if present
1181- ra_helper .risk_unaccept (request .user , finding )
1182-
1183- # Manage the jira status changes
1184- push_to_jira = False
1185- # Determine if the finding is in a group. if so, not push to jira
1186- finding_in_group = finding .has_finding_group
1187- # Check if there is a jira issue that needs to be updated
1188- jira_issue_exists = finding .has_jira_issue or (finding .finding_group and finding .finding_group .has_jira_issue )
1189- # fetch the project
1190- jira_instance = jira_helper .get_jira_instance (finding )
1191- jira_project = jira_helper .get_jira_project (finding )
1192- # Only push if the finding is not in a group
1193- if jira_issue_exists :
1194- # Determine if any automatic sync should occur
1195- push_to_jira = jira_helper .is_push_all_issues (finding ) or jira_instance .finding_jira_sync
1196- # Add the closing note
1197- if (jira_project .push_notes or push_to_jira ) and not finding_in_group :
1198- jira_helper .add_comment (finding , new_note , force_push = True )
1199- # Save the finding
1200- finding .save (push_to_jira = (push_to_jira and not finding_in_group ))
1201- # we only push the group after saving the finding to make sure
1202- # the updated data of the finding is pushed as part of the group
1203- if push_to_jira and finding_in_group :
1204- jira_helper .push_to_jira (finding .finding_group )
12051158
12061159 messages .add_message (
12071160 request ,
@@ -1210,17 +1163,7 @@ def close_finding(request, fid):
12101163 extra_tags = "alert-success" ,
12111164 )
12121165
1213- # Note: this notification has not be moved to "@receiver(pre_save, sender=Finding)" method as many other notifications
1214- # Because it could generate too much noise, we keep it here only for findings created by hand in WebUI
1215- # TODO: but same should be implemented for API endpoint
1216-
1217- create_notification (
1218- event = "finding_closed" ,
1219- title = _ ("Closing of %s" ) % finding .title ,
1220- finding = finding ,
1221- description = f'The finding "{ finding .title } " was closed by { request .user } ' ,
1222- url = reverse ("view_finding" , args = (finding .id ,)),
1223- )
1166+ # Notification sent by helper
12241167 return HttpResponseRedirect (
12251168 reverse ("view_test" , args = (finding .test .id ,)),
12261169 )
0 commit comments