Skip to content

Commit 8dd0306

Browse files
move save call out of jira helper
1 parent cbed310 commit 8dd0306

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

dojo/finding/views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,9 @@ def reopen_finding(request, fid):
14101410
status.save()
14111411
# Clear the risk acceptance, if present
14121412
ra_helper.risk_unaccept(request.user, finding)
1413-
jira_helper.save_and_push_to_jira(finding)
1413+
finding.save(dedupe_option=False, push_to_jira=False)
1414+
if jira_helper.is_push_all_issues(finding) or jira_helper.is_keep_in_sync_with_jira(finding):
1415+
jira_helper.push_to_jira(finding)
14141416

14151417
reopen_external_issue(finding, "re-opened by defectdojo", "github")
14161418

dojo/jira_link/helper.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ def _safely_get_obj_status_for_jira(obj: Finding | Finding_Group, *, isenforced:
141141
return status or ["Inactive"]
142142

143143

144+
def is_keep_in_sync_with_jira(finding):
145+
keep_in_sync_enabled = False
146+
# Check if there is a jira issue that needs to be updated
147+
jira_issue_exists = finding.has_jira_issue or (finding.finding_group and finding.finding_group.has_jira_issue)
148+
# Only push if the finding is not in a group
149+
if jira_issue_exists:
150+
# Determine if any automatic sync should occur
151+
keep_in_sync_enabled = get_jira_instance(finding).finding_jira_sync
152+
153+
return keep_in_sync_enabled
154+
155+
144156
# checks if a finding can be pushed to JIRA
145157
# optionally provides a form with the new data for the finding
146158
# any finding that already has a JIRA issue can be pushed again to JIRA
@@ -1823,26 +1835,6 @@ def process_resolution_from_jira(finding, resolution_id, resolution_name, assign
18231835
return status_changed
18241836

18251837

1826-
def save_and_push_to_jira(finding):
1827-
# Manage the jira status changes
1828-
push_to_jira_decision = False
1829-
# Determine if the finding is in a group. if so, not push to jira yet
1830-
finding_in_group = finding.has_finding_group
1831-
# Check if there is a jira issue that needs to be updated
1832-
jira_issue_exists = finding.has_jira_issue or (finding.finding_group and finding.finding_group.has_jira_issue)
1833-
# Only push if the finding is not in a group
1834-
if jira_issue_exists:
1835-
# Determine if any automatic sync should occur
1836-
push_to_jira_decision = is_push_all_issues(finding) \
1837-
or get_jira_instance(finding).finding_jira_sync
1838-
# Save the finding
1839-
finding.save(dedupe_option=False, product_grading_option=False, issue_updater_option=False, push_to_jira=(push_to_jira_decision and not finding_in_group))
1840-
# we only push the group after saving the finding to make sure
1841-
# the updated data of the finding is pushed as part of the group
1842-
if push_to_jira_decision and finding_in_group:
1843-
push_to_jira(finding.finding_group)
1844-
1845-
18461838
def get_finding_group_findings_above_threshold(finding_group):
18471839
"""Get the findings that are above the minimum threshold"""
18481840
jira_minimum_threshold = 0

dojo/risk_acceptance/helper.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def expire_now(risk_acceptance):
3333
if risk_acceptance.restart_sla_expired:
3434
finding.sla_start_date = timezone.now().date()
3535
# this method both saves and pushed to JIRA (no other post processing)
36-
jira_helper.save_and_push_to_jira(finding)
36+
finding.save(dedupe_option=False)
37+
if jira_helper.is_push_all_issues(finding) or jira_helper.is_keep_in_sync_with_jira(finding):
38+
jira_helper.push_to_jira(finding)
3739

3840
reactivated_findings.append(finding)
3941
else:
@@ -72,7 +74,9 @@ def reinstate(risk_acceptance, old_expiration_date):
7274
# Update any endpoint statuses on each of the findings
7375
update_endpoint_statuses(finding, accept_risk=True)
7476
# this method both saves and pushed to JIRA (no other post processing)
75-
jira_helper.save_and_push_to_jira(finding)
77+
finding.save(dedupe_option=False)
78+
if jira_helper.is_push_all_issues(finding) or jira_helper.is_keep_in_sync_with_jira(finding):
79+
jira_helper.push_to_jira(finding)
7680
reinstated_findings.append(finding)
7781
else:
7882
logger.debug("%i:%s: already inactive, not making any changes", finding.id, finding)
@@ -113,7 +117,10 @@ def remove_finding_from_risk_acceptance(user: Dojo_User, risk_acceptance: Risk_A
113117
# Update any endpoint statuses on each of the findings
114118
update_endpoint_statuses(finding, accept_risk=False)
115119
# this method both saves and pushed to JIRA (no other post processing)
116-
jira_helper.save_and_push_to_jira(finding)
120+
finding.save(dedupe_option=False)
121+
if jira_helper.is_push_all_issues(finding) or jira_helper.is_keep_in_sync_with_jira(finding):
122+
jira_helper.push_to_jira(finding)
123+
117124
# best effort jira integration, no status changes
118125
post_jira_comments(risk_acceptance, [finding], unaccepted_message_creator)
119126
# Add a note to reflect that the finding was removed from the risk acceptance
@@ -319,6 +326,9 @@ def simple_risk_accept(user: Dojo_User, finding: Finding, *, perform_save=True)
319326
finding.save(dedupe_option=False)
320327
# post_jira_comment might reload from database so see unaccepted finding. but the comment
321328
# only contains some text so that's ok
329+
if jira_helper.is_push_all_issues(finding) or jira_helper.is_keep_in_sync_with_jira(finding):
330+
jira_helper.push_to_jira(finding)
331+
322332
post_jira_comment(finding, accepted_message_creator)
323333
# Add a note to reflect that the finding was removed from the risk acceptance
324334
if user is not None:
@@ -349,7 +359,8 @@ def risk_unaccept(user: Dojo_User, finding: Finding, *, perform_save=True, post_
349359
post_jira_comment(finding, unaccepted_message_creator)
350360

351361
# Update the JIRA obect for this finding
352-
jira_helper.save_and_push_to_jira(finding)
362+
if jira_helper.is_push_all_issues(finding) or jira_helper.is_keep_in_sync_with_jira(finding):
363+
jira_helper.push_to_jira(finding)
353364

354365
# Add a note to reflect that the finding was removed from the risk acceptance
355366
if user is not None:

0 commit comments

Comments
 (0)