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 2 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.filter(Q(jira_issue=None) | Q(finding_group__jira_issue=None))
Copy link
Contributor

Choose a reason for hiding this comment

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

This will only return Findings that are either missing jira_issue or missing finding_group__jira_issue. Shouldn't it simply return everything, unfiltered?

Copy link
Contributor

@Maffooch Maffooch Nov 27, 2024

Choose a reason for hiding this comment

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

This function is only called when the input supplied does not match what is expected, and low key sorta fails. I believe the thought process is along the lines of "if something unexpected happens, removing all findings with jira links would be a good indicator". This is just me speculating though. Would need @hblankenship to confirm

On the other side, returning all results (as if the filter was never applied) is a totally valid approach as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I apologize for not getting to this earlier. Testing shows that the option returns the same thing not applying the filter returns. The reason it returns them all, despite what it looks like, is because jira_issue is None for finding_group__jira_issue findings and finding_group__jira_issue is None for jira_issue items. I have modified it to just return without filtering to alleviate the confusion.


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")
Maffooch marked this conversation as resolved.
Show resolved Hide resolved

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