Skip to content

Commit 11281ad

Browse files
move save call out of jira helper
1 parent 136dc4b commit 11281ad

File tree

3 files changed

+33
-25
lines changed

3 files changed

+33
-25
lines changed

dojo/finding/views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,9 @@ def reopen_finding(request, fid):
14371437
status.save()
14381438
# Clear the risk acceptance, if present
14391439
ra_helper.risk_unaccept(request.user, finding)
1440-
jira_helper.save_and_push_to_jira(finding)
1440+
finding.save(dedupe_option=False, push_to_jira=False)
1441+
if jira_helper.is_push_all_issues(finding) or jira_helper.is_keep_in_sync_with_jira(finding):
1442+
jira_helper.push_to_jira(finding)
14411443

14421444
reopen_external_issue(finding, "re-opened by defectdojo", "github")
14431445

dojo/jira_link/helper.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ def is_push_all_issues(instance):
109109
return None
110110

111111

112+
def is_keep_in_sync_with_jira(finding):
113+
keep_in_sync_enabled = False
114+
# Check if there is a jira issue that needs to be updated
115+
jira_issue_exists = finding.has_jira_issue or (finding.finding_group and finding.finding_group.has_jira_issue)
116+
# Only push if the finding is not in a group
117+
if jira_issue_exists:
118+
# Determine if any automatic sync should occur
119+
keep_in_sync_enabled = get_jira_instance(finding).finding_jira_sync
120+
121+
return keep_in_sync_enabled
122+
123+
124+
112125
def _safely_get_finding_group_status(finding_group: Finding_Group) -> str:
113126
# Accommodating a strange behavior where a finding group sometimes prefers `obj.status` rather than `obj.status()`
114127
try:
@@ -674,6 +687,8 @@ def push_to_jira(obj, *args, **kwargs):
674687
raise ValueError(msg)
675688

676689
if isinstance(obj, Finding):
690+
if obj.finding_group:
691+
return push_finding_group_to_jira(obj.finding_group)
677692
return push_finding_to_jira(obj, *args, **kwargs)
678693

679694
if isinstance(obj, Finding_Group):
@@ -1744,23 +1759,3 @@ def process_resolution_from_jira(finding, resolution_id, resolution_name, assign
17441759
if status_changed:
17451760
finding.save()
17461761
return status_changed
1747-
1748-
1749-
def save_and_push_to_jira(finding):
1750-
# Manage the jira status changes
1751-
push_to_jira_decision = False
1752-
# Determine if the finding is in a group. if so, not push to jira yet
1753-
finding_in_group = finding.has_finding_group
1754-
# Check if there is a jira issue that needs to be updated
1755-
jira_issue_exists = finding.has_jira_issue or (finding.finding_group and finding.finding_group.has_jira_issue)
1756-
# Only push if the finding is not in a group
1757-
if jira_issue_exists:
1758-
# Determine if any automatic sync should occur
1759-
push_to_jira_decision = is_push_all_issues(finding) \
1760-
or get_jira_instance(finding).finding_jira_sync
1761-
# Save the finding
1762-
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))
1763-
# we only push the group after saving the finding to make sure
1764-
# the updated data of the finding is pushed as part of the group
1765-
if push_to_jira_decision and finding_in_group:
1766-
push_to_jira(finding.finding_group)

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)