Skip to content

Commit

Permalink
Add a filter for Findings for Has Any JIRA (grouped or single) (#11313)
Browse files Browse the repository at this point in the history
* initial attempt

* filter by jira

* Update dojo/filters.py

* Less confusing all return

---------

Co-authored-by: Cody Maffucci <[email protected]>
  • Loading branch information
hblankenship and Maffooch authored Dec 3, 2024
1 parent 522aa5a commit 6c1d1d6
Showing 1 changed file with 31 additions and 0 deletions.
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

0 comments on commit 6c1d1d6

Please sign in to comment.