@@ -107,23 +107,49 @@ def finding_queries(
107107 monthly_counts = query_counts_for_period (MetricsPeriod .MONTH , months_between )
108108 weekly_counts = query_counts_for_period (MetricsPeriod .WEEK , weeks_between )
109109
110- top_ten = get_authorized_products (Permissions .Product_View )
110+ # Build Top 10 from all authorized Findings (not date-limited) to avoid empty lists due to date window
111+ findings_for_top_ten = all_authorized_findings
112+ if len (prod_type ) > 0 :
113+ findings_for_top_ten = findings_for_top_ten .filter (
114+ test__engagement__product__prod_type__in = prod_type ,
115+ )
111116 if get_system_setting ("enforce_verified_status" , True ) or get_system_setting ("enforce_verified_status_metrics" , True ):
112- top_ten = top_ten .filter (engagement__test__finding__verified = True )
113-
114- top_ten = top_ten .filter (engagement__test__finding__false_p = False ,
115- engagement__test__finding__duplicate = False ,
116- engagement__test__finding__out_of_scope = False ,
117- engagement__test__finding__mitigated__isnull = True ,
118- engagement__test__finding__severity__in = ("Critical" , "High" , "Medium" , "Low" ),
119- prod_type__in = prod_type )
117+ findings_for_top_ten = findings_for_top_ten .filter (verified = True )
118+
119+ findings_for_top_ten = findings_for_top_ten .filter (
120+ false_p = False ,
121+ duplicate = False ,
122+ out_of_scope = False ,
123+ mitigated__isnull = True ,
124+ active = True ,
125+ risk_accepted = False ,
126+ severity__in = ("Critical" , "High" , "Medium" , "Low" ),
127+ )
120128
121- top_ten = severity_count (
122- top_ten , "annotate" , "engagement__test__finding__severity" ,
123- ).order_by (
129+ # Group by product id/name and count findings by severity
130+ top_ten = findings_for_top_ten .values (
131+ product_id = F ("test__engagement__product__id" ),
132+ product_name = F ("test__engagement__product__name" ),
133+ )
134+ top_ten = severity_count (top_ten , "annotate" , "severity" ).order_by (
124135 "-critical" , "-high" , "-medium" , "-low" ,
125136 )[:10 ]
126137
138+ # Remap keys to match template expectations (id/name)
139+ top_ten = [
140+ {
141+ "id" : row .get ("product_id" ),
142+ "name" : row .get ("product_name" ),
143+ "critical" : row .get ("critical" ),
144+ "high" : row .get ("high" ),
145+ "medium" : row .get ("medium" ),
146+ "low" : row .get ("low" ),
147+ "info" : row .get ("info" ),
148+ "total" : row .get ("total" ),
149+ }
150+ for row in top_ten
151+ ]
152+
127153 return {
128154 "all" : filtered_findings ,
129155 "closed" : closed_filtered_findings ,
0 commit comments