From 6c1d1d6b48fbc4e5e21a2a85bbe794f0900c4ea4 Mon Sep 17 00:00:00 2001 From: Harold Blankenship <36673698+hblankenship@users.noreply.github.com> Date: Tue, 3 Dec 2024 10:02:10 -0600 Subject: [PATCH] Add a filter for Findings for Has Any JIRA (grouped or single) (#11313) * initial attempt * filter by jira * Update dojo/filters.py * Less confusing all return --------- Co-authored-by: Cody Maffucci <46459665+Maffooch@users.noreply.github.com> --- dojo/filters.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/dojo/filters.py b/dojo/filters.py index a2c40685cd..6a1228865b 100644 --- a/dojo/filters.py +++ b/dojo/filters.py @@ -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 @@ -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", @@ -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")