Skip to content

Commit 1dee081

Browse files
committed
refine the dashboard view
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent ce7ffe4 commit 1dee081

4 files changed

Lines changed: 49 additions & 22 deletions

File tree

product_portfolio/filters.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from product_portfolio.models import ProductComponent
3737
from product_portfolio.models import ProductDependency
3838
from product_portfolio.models import ProductPackage
39+
from product_portfolio.models import ProductPolicyViolation
3940
from product_portfolio.models import ProductStatus
4041
from vulnerabilities.filters import ScoreRangeFilter
4142
from vulnerabilities.models import RISK_SCORE_RANGES
@@ -149,6 +150,10 @@ class ProductFilterSet(DataspacedFilterSet):
149150
label=_("License issues"),
150151
method="filter_license_compliance_issues",
151152
)
153+
policy_violations = django_filters.BooleanFilter(
154+
label=_("Policy violations"),
155+
method="filter_policy_violations",
156+
)
152157

153158
class Meta:
154159
model = Product
@@ -189,6 +194,16 @@ def filter_license_compliance_issues(self, queryset, name, value):
189194
condition = Exists(has_alert)
190195
return queryset.filter(condition if value else ~condition)
191196

197+
def filter_policy_violations(self, queryset, name, value):
198+
if value is None:
199+
return queryset
200+
has_violation = ProductPolicyViolation.objects.filter(
201+
product_id=OuterRef("pk"),
202+
resolved=False,
203+
)
204+
condition = Exists(has_violation)
205+
return queryset.filter(condition if value else ~condition)
206+
192207

193208
class BaseProductRelationFilterSet(DataspacedFilterSet):
194209
field_name_prefix = None

product_portfolio/templates/product_portfolio/compliance/compliance_dashboard.html

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ <h1 class="h3 mb-0">
6868
</div>
6969
<div class="col-6 col-md-3">
7070
<div class="bg-body-secondary rounded-3 p-3">
71-
<div class="small text-body-secondary mb-1">{% trans "License issues" %}</div>
71+
<div class="small text-body-secondary mb-1">{% trans "License compliance" %}</div>
7272
{% if products_with_license_issues %}
7373
<a href="?license_compliance_issues=true" class="fs-4 fw-medium lh-sm text-danger">
7474
{{ products_with_license_issues }}
@@ -80,28 +80,13 @@ <h1 class="h3 mb-0">
8080
{% endif %}
8181
<div class="text-body-tertiary fs-xs mt-1">
8282
{% if products_with_license_issues %}
83-
{% trans "products with policy violations" %}
83+
{% trans "products with license compliance alerts" %}
8484
{% else %}
8585
{% trans "All products within policy" %}
8686
{% endif %}
8787
</div>
8888
</div>
8989
</div>
90-
<div class="col-6 col-md-3">
91-
<div class="bg-body-secondary rounded-3 p-3">
92-
<div class="small text-body-secondary mb-1">{% trans "Security issues" %}</div>
93-
<div class="fs-4 fw-medium lh-sm {% if products_with_critical_or_high %}text-danger{% elif products_with_vulnerabilities %}text-warning-orange{% else %}text-success{% endif %}">
94-
{{ products_with_critical_or_high }}
95-
</div>
96-
<div class="text-body-tertiary fs-xs mt-1">
97-
{% if products_with_critical_or_high %}
98-
{% trans "products with critical/high vulnerabilities" %}
99-
{% else %}
100-
{% trans "No critical or high vulnerabilities" %}
101-
{% endif %}
102-
</div>
103-
</div>
104-
</div>
10590
<div class="col-6 col-md-3">
10691
<div class="bg-body-secondary rounded-3 p-3">
10792
<div class="small text-body-secondary mb-1">{% trans "Total vulnerabilities" %}</div>
@@ -119,6 +104,27 @@ <h1 class="h3 mb-0">
119104
</div>
120105
</div>
121106
</div>
107+
<div class="col-6 col-md-3">
108+
<div class="bg-body-secondary rounded-3 p-3">
109+
<div class="small text-body-secondary mb-1">{% trans "Policy violations" %}</div>
110+
{% if products_with_policy_violations %}
111+
<a href="?policy_violations=true" class="fs-4 fw-medium lh-sm text-danger">
112+
{{ products_with_policy_violations }}
113+
</a>
114+
{% else %}
115+
<div class="fs-4 fw-medium lh-sm text-success">
116+
{{ products_with_policy_violations }}
117+
</div>
118+
{% endif %}
119+
<div class="text-body-tertiary fs-xs mt-1">
120+
{% if products_with_policy_violations %}
121+
{% trans "products with active rule violations" %}
122+
{% else %}
123+
{% trans "No active policy violations" %}
124+
{% endif %}
125+
</div>
126+
</div>
127+
</div>
122128
</div>
123129

124130
<div class="border rounded-3 p-3 pt-2 mb-3">

product_portfolio/templates/product_portfolio/compliance/compliance_panels.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ <h3 class="fs-6 fw-medium mb-0">{% trans "Security compliance" %}</h3>
217217
</div>
218218

219219
{% if policy_violations %}
220-
<div class="row g-4 mb-4">
220+
<div id="policy-violations" class="row g-4 mb-4">
221221
<div class="col-12">
222222
<div class="border rounded-3 p-3">
223223
<div class="d-flex justify-content-between align-items-center mb-3">

product_portfolio/views.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3075,14 +3075,20 @@ def get_context_data(self, **kwargs):
30753075
context = super().get_context_data(**kwargs)
30763076

30773077
products = self.object_list
3078-
products_with_issues = products.with_compliance_issues().count()
3078+
products_with_issues = products.filter(
3079+
Q(license_error_count__gt=0)
3080+
| Q(license_warning_count__gt=0)
3081+
| Q(critical_count__gt=0)
3082+
| Q(high_count__gt=0)
3083+
| Q(policy_violation_count__gt=0)
3084+
).count()
30793085

30803086
products_with_license_issues = products.filter(
30813087
Q(license_error_count__gt=0) | Q(license_warning_count__gt=0)
30823088
).count()
30833089

3084-
products_with_critical_or_high = products.filter(
3085-
Q(critical_count__gt=0) | Q(high_count__gt=0)
3090+
products_with_policy_violations = products.filter(
3091+
policy_violation_count__gt=0
30863092
).count()
30873093

30883094
totals = products.aggregate(
@@ -3098,7 +3104,7 @@ def get_context_data(self, **kwargs):
30983104
"total_products": context["paginator"].count,
30993105
"products_with_issues": products_with_issues,
31003106
"products_with_license_issues": products_with_license_issues,
3101-
"products_with_critical_or_high": products_with_critical_or_high,
3107+
"products_with_policy_violations": products_with_policy_violations,
31023108
"total_vulnerabilities": totals["total_vulnerabilities"] or 0,
31033109
"total_critical": totals["total_critical"] or 0,
31043110
"total_high": totals["total_high"] or 0,

0 commit comments

Comments
 (0)