Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dissallow already linked issue #11298

Open
wants to merge 1 commit into
base: bugfix
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dojo/api_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,12 @@ def validate(self, data):
msg = "Either engagement or finding or finding_group has to be set."
raise serializers.ValidationError(msg)

if finding:
linked_finding = jira_helper.jira_already_linked(finding, data.get("jira_key"), data.get("jira_id"))
if linked_finding:
msg = "JIRA issue " + data.get("jira_key") + " already linked to " + reverse("view_finding", args=(linked_finding,))
raise serializers.ValidationError(msg)
Comment on lines +1291 to +1294
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
linked_finding = jira_helper.jira_already_linked(finding, data.get("jira_key"), data.get("jira_id"))
if linked_finding:
msg = "JIRA issue " + data.get("jira_key") + " already linked to " + reverse("view_finding", args=(linked_finding,))
raise serializers.ValidationError(msg)
if (linked_finding := jira_helper.jira_already_linked(finding, data.get("jira_key"), data.get("jira_id"))) is not None:
msg = "JIRA issue " + data.get("jira_key") + " already linked to " + reverse("view_finding", args=(linked_finding.id,))
raise serializers.ValidationError(msg)


return data


Expand Down
11 changes: 11 additions & 0 deletions dojo/jira_link/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,17 @@ def add_simple_jira_comment(jira_instance, jira_issue, comment):
return False


def jira_already_linked(finding, jira_issue_key, jira_id):
jira_issues = JIRA_Issue.objects.filter(jira_id=jira_id, jira_key=jira_issue_key).exclude(engagement__isnull=False)
jira_issues = jira_issues.exclude(finding=finding)

result = 0
if len(jira_issues) > 0:
result = jira_issues[0].finding_id

return result
Comment on lines +1429 to +1437
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def jira_already_linked(finding, jira_issue_key, jira_id):
jira_issues = JIRA_Issue.objects.filter(jira_id=jira_id, jira_key=jira_issue_key).exclude(engagement__isnull=False)
jira_issues = jira_issues.exclude(finding=finding)
result = 0
if len(jira_issues) > 0:
result = jira_issues[0].finding_id
return result
def jira_already_linked(finding, jira_issue_key, jira_id) -> Finding | None:
jira_issues = JIRA_Issue.objects.filter(jira_id=jira_id, jira_key=jira_issue_key).exclude(engagement__isnull=False)
jira_issues = jira_issues.exclude(finding=finding)
return jira_issues.first()



def finding_link_jira(request, finding, new_jira_issue_key):
logger.debug("linking existing jira issue %s for finding %i", new_jira_issue_key, finding.id)

Expand Down