4444from vulnerabilities .models import Vulnerability
4545from vulnerabilities .models import VulnerabilityAnalysisMixin
4646from vulnerabilities .triage .models import TriageAction
47- from vulnerabilities .triage .models import TriageRecord
4847
4948
5049class HasComplianceIssueFilter (django_filters .BooleanFilter ):
@@ -368,6 +367,7 @@ class ProductPackageFilterSet(BaseProductRelationFilterSet):
368367 dropdown_fields = [
369368 "is_modified" ,
370369 "weighted_risk_score" ,
370+ "triage_action" ,
371371 "vulnerability_analyses__state" ,
372372 "vulnerability_analyses__justification" ,
373373 "responses" ,
@@ -421,6 +421,12 @@ class ProductPackageFilterSet(BaseProductRelationFilterSet):
421421 ("unknown" , _ ("Reachability not known" )),
422422 ),
423423 )
424+ triage_action = django_filters .ChoiceFilter (
425+ label = _ ("Triage action" ),
426+ choices = TriageAction .choices ,
427+ empty_label = _ ("All actions" ),
428+ method = "filter_triage_action" ,
429+ )
424430 compliance_issues = HasComplianceIssueFilter (
425431 field_name = "package__usage_policy__compliance_alert" ,
426432 distinct = True ,
@@ -440,6 +446,15 @@ class Meta:
440446 "exploitability" ,
441447 ]
442448
449+ @staticmethod
450+ def filter_triage_action (queryset , name , value ):
451+ if not value :
452+ return queryset
453+ return queryset .filter (
454+ triage_records__action = value ,
455+ triage_records__ruleset__enabled = True ,
456+ ).distinct ()
457+
443458 def __init__ (self , * args , ** kwargs ):
444459 super ().__init__ (* args , ** kwargs )
445460 self .filters ["vulnerability_analyses__state" ].extra ["null_label" ] = "(No values)"
@@ -586,32 +601,3 @@ class Meta:
586601 "is_pinned" ,
587602 "is_direct" ,
588603 ]
589-
590-
591- class TriageRecordFilterSet (DataspacedFilterSet ):
592- dropdown_fields = ["action" ]
593-
594- q = SearchFilter (
595- label = _ ("Search" ),
596- search_fields = [
597- "product_package__package__name" ,
598- "product_package__package__namespace" ,
599- "product_package__package__version" ,
600- ],
601- )
602- action = django_filters .ChoiceFilter (
603- label = _ ("Action" ),
604- choices = TriageAction .choices ,
605- empty_label = _ ("All actions" ),
606- )
607- sort = DefaultOrderingFilter (
608- label = _ ("Sort" ),
609- fields = [
610- ("product_package__package__name" , "package" ),
611- ("detected_date" , "detected_date" ),
612- ],
613- )
614-
615- class Meta :
616- model = TriageRecord
617- fields = ["action" ]
0 commit comments