From 6021b0a70934f8b38e1801da7dcf96d916061754 Mon Sep 17 00:00:00 2001 From: David H Date: Fri, 26 Apr 2024 08:47:06 -0600 Subject: [PATCH] add findings_count ordering to filters include dojo_sort snippet in findings_count table header add findings_count annotation to include column in query --- dojo/filters.py | 2 ++ dojo/product/views.py | 4 ++++ dojo/templates/dojo/product.html | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dojo/filters.py b/dojo/filters.py index f355625d80..619fc8b1b6 100644 --- a/dojo/filters.py +++ b/dojo/filters.py @@ -1182,6 +1182,7 @@ class ProductFilter(DojoFilter): ('origin', 'origin'), ('external_audience', 'external_audience'), ('internet_accessible', 'internet_accessible'), + ('findings_count', 'findings_count') ), field_labels={ 'name': 'Product Name', @@ -1193,6 +1194,7 @@ class ProductFilter(DojoFilter): 'origin': 'Origin ', 'external_audience': 'External Audience ', 'internet_accessible': 'Internet Accessible ', + 'findings_count': 'Findings Count ', } ) diff --git a/dojo/product/views.py b/dojo/product/views.py index 09f0e007b0..c100a9531b 100755 --- a/dojo/product/views.py +++ b/dojo/product/views.py @@ -68,6 +68,10 @@ def product(request): # see https://code.djangoproject.com/ticket/23771 and https://code.djangoproject.com/ticket/25375 name_words = prods.values_list('name', flat=True) + prods = prods.annotate( + findings_count=Count('engagement__test__finding', filter=Q(engagement__test__finding__active=True)) + ) + prod_filter = ProductFilter(request.GET, queryset=prods, user=request.user) prod_list = get_page_items(request, prod_filter.qs, 25) diff --git a/dojo/templates/dojo/product.html b/dojo/templates/dojo/product.html index d022812de8..6dd7859204 100644 --- a/dojo/templates/dojo/product.html +++ b/dojo/templates/dojo/product.html @@ -62,7 +62,7 @@

{% if system_settings.enable_github %} GitHub {% endif %} - Active (Verified) Findings + {% dojo_sort request 'Active (Verified) Findings' 'findings_count' %} Vulnerable Hosts / Endpoints Contact {% comment %} The display field is translated in the function. No need to translate here as well{% endcomment %}