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

Adding range filters for EPSS #11469

Open
wants to merge 1 commit into
base: bugfix
Choose a base branch
from
Open
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
35 changes: 26 additions & 9 deletions dojo/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,15 @@ class ApiProductFilter(DojoFilter):
)


class PercentageRangeFilter(RangeFilter):
def filter(self, qs, value):
if value is not None:
start = value.start / decimal.Decimal("100.0") if value.start else None
stop = value.stop / decimal.Decimal("100.0") if value.stop else None
value = slice(start, stop)
return super().filter(qs, value)


class ApiFindingFilter(DojoFilter):
# BooleanFilter
active = BooleanFilter(field_name="active")
Expand Down Expand Up @@ -1463,6 +1472,23 @@ class ApiFindingFilter(DojoFilter):
cwe = NumberInFilter(field_name="cwe", lookup_expr="in")
defect_review_requested_by = NumberInFilter(field_name="defect_review_requested_by", lookup_expr="in")
endpoints = NumberInFilter(field_name="endpoints", lookup_expr="in")
epss_score = PercentageRangeFilter(
field_name="epss_score",
label="EPSS score range",
help_text=(
"The range of EPSS score percentages to filter on; the min input is a lower bound, "
"the max is an upper bound. Leaving one empty will skip that bound (e.g., leaving "
"the min bound input empty will filter only on the max bound -- filtering on "
'"less than or equal"). Leading 0 required.'
))
epss_percentile = PercentageRangeFilter(
field_name="epss_percentile",
label="EPSS percentile range",
help_text=(
"The range of EPSS percentiles to filter on; the min input is a lower bound, the max "
"is an upper bound. Leaving one empty will skip that bound (e.g., leaving the min bound "
'input empty will filter only on the max bound -- filtering on "less than or equal"). Leading 0 required.'
))
found_by = NumberInFilter(field_name="found_by", lookup_expr="in")
id = NumberInFilter(field_name="id", lookup_expr="in")
last_reviewed_by = NumberInFilter(field_name="last_reviewed_by", lookup_expr="in")
Expand Down Expand Up @@ -1564,15 +1590,6 @@ def filter_percentage(self, queryset, name, value):
return queryset.filter(**lookup_kwargs)


class PercentageRangeFilter(RangeFilter):
def filter(self, qs, value):
if value is not None:
start = value.start / decimal.Decimal("100.0") if value.start else None
stop = value.stop / decimal.Decimal("100.0") if value.stop else None
value = slice(start, stop)
return super().filter(qs, value)


class FindingFilterHelper(FilterSet):
title = CharFilter(lookup_expr="icontains")
date = DateRangeFilter(field_name="date", label="Date Discovered")
Expand Down
Loading