From 50692a3c0922b4cec15ae4fc0a777dd70d6c896e Mon Sep 17 00:00:00 2001 From: hblankenship Date: Thu, 21 Nov 2024 14:41:21 -0600 Subject: [PATCH 1/4] initial attempt --- dojo/filters.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/dojo/filters.py b/dojo/filters.py index 35ceb20593..d1b363afae 100644 --- a/dojo/filters.py +++ b/dojo/filters.py @@ -235,6 +235,39 @@ def filter(self, qs, value): return self.options[value][1](self, qs, self.field_name) +class FindingHasJIRAFilter(ChoiceFilter): + def any(self, qs, name): + return qs.filter(Q(jira_issue=None) | Q(finding_group__jira_issue=None)) + + def has_jira_not_grouped(self, qs, name): + return qs.filter(Q(jira_issue=True) & Q(finding_group__jira_issue=False)) + + def has_jira_only_grouped(self, qs, name): + return qs.filter(Q(jira_issue=False) | Q(finding_group__jira_issue=True)) + + def has_any_jira(self, qs, name): + return qs.filter(Q(jira_issue=True) | Q(finding_group__jira_issue=True)) + + options = { + None: (_("Has No JIRA"), any), + 0: (_("Has JIRA Non-grouped"), has_jira_not_grouped), + 1: (_("Has JIRA Grouped Only"), has_jira_only_grouped), + 2: (_("Has Any JIRA"), has_any_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): + value = None + return self.options[value][1](self, qs, self.field_name) + + class ProductSLAFilter(ChoiceFilter): def any(self, qs, name): return qs @@ -1576,6 +1609,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 +1644,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") From 0feb2ee5a4e123845a7e1820150e45ca91a9b7ec Mon Sep 17 00:00:00 2001 From: hblankenship Date: Thu, 21 Nov 2024 18:16:59 -0600 Subject: [PATCH 2/4] filter by jira --- dojo/filters.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/dojo/filters.py b/dojo/filters.py index d1b363afae..7fd0704d20 100644 --- a/dojo/filters.py +++ b/dojo/filters.py @@ -236,23 +236,18 @@ def filter(self, qs, value): class FindingHasJIRAFilter(ChoiceFilter): - def any(self, qs, name): - return qs.filter(Q(jira_issue=None) | Q(finding_group__jira_issue=None)) - - def has_jira_not_grouped(self, qs, name): - return qs.filter(Q(jira_issue=True) & Q(finding_group__jira_issue=False)) + def no_jira(self, qs, name): + return qs.filter(Q(jira_issue=None) & Q(finding_group__jira_issue=None)) - def has_jira_only_grouped(self, qs, name): - return qs.filter(Q(jira_issue=False) | Q(finding_group__jira_issue=True)) + def any_jira(self, qs, name): + return qs.filter(~Q(jira_issue=None) | ~Q(finding_group__jira_issue=None)) - def has_any_jira(self, qs, name): - return qs.filter(Q(jira_issue=True) | Q(finding_group__jira_issue=True)) + def all_items(self, qs, name): + return qs.filter(Q(jira_issue=None) | Q(finding_group__jira_issue=None)) options = { - None: (_("Has No JIRA"), any), - 0: (_("Has JIRA Non-grouped"), has_jira_not_grouped), - 1: (_("Has JIRA Grouped Only"), has_jira_only_grouped), - 2: (_("Has Any JIRA"), has_any_jira), + 0: (_("Yes"), any_jira), + 1: (_("No"), no_jira), } def __init__(self, *args, **kwargs): @@ -264,7 +259,8 @@ def filter(self, qs, value): try: value = int(value) except (ValueError, TypeError): - value = None + return self.all_items(qs, self.field_name) + return self.options[value][1](self, qs, self.field_name) From 300a19c8ec4fc5e0f6c5d1b5470a53e57d172989 Mon Sep 17 00:00:00 2001 From: Cody Maffucci <46459665+Maffooch@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:33:06 -0600 Subject: [PATCH 3/4] Update dojo/filters.py --- dojo/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dojo/filters.py b/dojo/filters.py index 7fd0704d20..7abf78bfff 100644 --- a/dojo/filters.py +++ b/dojo/filters.py @@ -1640,7 +1640,7 @@ class FindingFilterHelper(FilterSet): lookup_expr="isnull", exclude=True, label="Has Group JIRA") - has_any_jira = FindingHasJIRAFilter(label="Has Any 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") From 34b483b5b3be959de2c06f1247e891ce3201f8cd Mon Sep 17 00:00:00 2001 From: Harold Blankenship <36673698+hblankenship@users.noreply.github.com> Date: Mon, 2 Dec 2024 07:17:58 -0600 Subject: [PATCH 4/4] Less confusing all return --- dojo/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dojo/filters.py b/dojo/filters.py index 7abf78bfff..a5e34779cf 100644 --- a/dojo/filters.py +++ b/dojo/filters.py @@ -243,7 +243,7 @@ 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.filter(Q(jira_issue=None) | Q(finding_group__jira_issue=None)) + return qs options = { 0: (_("Yes"), any_jira),