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

Add a filter for Findings for Has Any JIRA (grouped or single) #11313

Merged
merged 4 commits into from
Dec 3, 2024
Merged
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
31 changes: 31 additions & 0 deletions dojo/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,35 @@ def filter(self, qs, value):
return self.options[value][1](self, qs, self.field_name)


class FindingHasJIRAFilter(ChoiceFilter):
def no_jira(self, qs, name):
return qs.filter(Q(jira_issue=None) & Q(finding_group__jira_issue=None))

def any_jira(self, qs, name):
return qs.filter(~Q(jira_issue=None) | ~Q(finding_group__jira_issue=None))

def all_items(self, qs, name):
return qs

options = {
0: (_("Yes"), any_jira),
1: (_("No"), no_jira),
}

def __init__(self, *args, **kwargs):
kwargs["choices"] = [
(key, value[0]) for key, value in six.iteritems(self.options)]
super().__init__(*args, **kwargs)

def filter(self, qs, value):
try:
value = int(value)
except (ValueError, TypeError):
return self.all_items(qs, self.field_name)

return self.options[value][1](self, qs, self.field_name)


class ProductSLAFilter(ChoiceFilter):
def any(self, qs, name):
return qs
Expand Down Expand Up @@ -1576,6 +1605,7 @@ class FindingFilterHelper(FilterSet):
test_import_finding_action__test_import = NumberFilter(widget=HiddenInput())
endpoints = NumberFilter(widget=HiddenInput())
status = FindingStatusFilter(label="Status")

has_component = BooleanFilter(
field_name="component_name",
lookup_expr="isnull",
Expand Down Expand Up @@ -1610,6 +1640,7 @@ class FindingFilterHelper(FilterSet):
lookup_expr="isnull",
exclude=True,
label="Has Group JIRA")
has_any_jira = FindingHasJIRAFilter(label="Has Any JIRA")

outside_of_sla = FindingSLAFilter(label="Outside of SLA")
has_tags = BooleanFilter(field_name="tags", lookup_expr="isnull", exclude=True, label="Has tags")
Expand Down