Skip to content

Commit

Permalink
adding range filters for EPSS
Browse files Browse the repository at this point in the history
  • Loading branch information
hblankenship committed Dec 24, 2024
1 parent 44293d0 commit 3f02c28
Showing 1 changed file with 26 additions and 9 deletions.
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

0 comments on commit 3f02c28

Please sign in to comment.