Skip to content

Commit 7ab452e

Browse files
committed
Improve card values
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 5602234 commit 7ab452e

2 files changed

Lines changed: 41 additions & 17 deletions

File tree

product_portfolio/templates/product_portfolio/compliance_dashboard.html

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ <h1 class="h3 mb-0">{% trans "Compliance Control Center" %}</h1>
6363
</div>
6464
<div class="text-body-tertiary fs-xs mt-1">
6565
{% if total_critical %}
66-
{{ total_critical }} {% trans "critical" %}{% if total_high %}, {{ total_high }} {% trans "high" %}{% endif %}
66+
{{ total_critical }} {% trans "critical" %}{% if total_high %}, {{ total_high }} {% trans "high" %}{% endif %}{% if total_medium %}, {{ total_medium }} {% trans "medium" %}{% endif %}{% if total_low %}, {{ total_low }} {% trans "low" %}{% endif %}
6767
{% elif total_vulnerabilities %}
6868
{% trans "across all products" %}
6969
{% else %}
@@ -78,11 +78,11 @@ <h1 class="h3 mb-0">{% trans "Compliance Control Center" %}</h1>
7878
<table class="table table-sm mb-0">
7979
<thead>
8080
<tr>
81-
<th class="">{% trans "Product" %}</th>
82-
<th class="text-end">{% trans "Packages" %}</th>
83-
<th class="text-end">{% trans "License compliance" %}</th>
84-
<th class="text-end">{% trans "Security compliance" %}</th>
85-
<th class="text-end">{% trans "Vulnerabilities" %}</th>
81+
<th class="fw-medium">{% trans "Product" %}</th>
82+
<th class="fw-medium text-end">{% trans "Packages" %}</th>
83+
<th class="fw-medium text-end">{% trans "License compliance" %}</th>
84+
<th class="fw-medium text-end">{% trans "Security compliance" %}</th>
85+
<th class="fw-medium text-end">{% trans "Vulnerabilities" %}</th>
8686
</tr>
8787
</thead>
8888
<tbody>
@@ -134,8 +134,14 @@ <h1 class="h3 mb-0">{% trans "Compliance Control Center" %}</h1>
134134
{% if product.high_count %}
135135
<span class="badge bg-warning-orange-subtle text-warning-orange ms-1">{{ product.high_count }} {% trans "high" %}</span>
136136
{% endif %}
137-
{% if not product.critical_count and not product.high_count %}
138-
<span class="badge bg-secondary-subtle text-secondary-emphasis">{{ product.vulnerability_count }}</span>
137+
{% if product.medium_count %}
138+
<span class="badge bg-warning-subtle text-warning-emphasis ms-1">{{ product.medium_count }} {% trans "medium" %}</span>
139+
{% endif %}
140+
{% if product.low_count %}
141+
<span class="badge bg-info-subtle text-info-emphasis ms-1">{{ product.low_count }} {% trans "low" %}</span>
142+
{% endif %}
143+
{% if not product.vulnerability_count %}
144+
<span class="text-body-tertiary small">{% trans "None" %}</span>
139145
{% endif %}
140146
</td>
141147
</tr>

product_portfolio/views.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,6 +2845,14 @@ def get_queryset(self):
28452845
distinct=True,
28462846
),
28472847
max_risk_score=Max("productpackages__package__affected_by_vulnerabilities__risk_score"),
2848+
max_risk_level=Case(
2849+
When(max_risk_score__gte=8.0, then=Value("critical")),
2850+
When(max_risk_score__gte=6.0, then=Value("high")),
2851+
When(max_risk_score__gte=3.0, then=Value("medium")),
2852+
When(max_risk_score__gte=0.1, then=Value("low")),
2853+
default=Value(""),
2854+
output_field=CharField(max_length=8),
2855+
),
28482856
critical_count=Count(
28492857
"productpackages__package__affected_by_vulnerabilities",
28502858
filter=Q(
@@ -2857,6 +2865,20 @@ def get_queryset(self):
28572865
filter=Q(productpackages__package__affected_by_vulnerabilities__risk_level="high"),
28582866
distinct=True,
28592867
),
2868+
medium_count=Count(
2869+
"productpackages__package__affected_by_vulnerabilities",
2870+
filter=Q(
2871+
productpackages__package__affected_by_vulnerabilities__risk_level="medium"
2872+
),
2873+
distinct=True,
2874+
),
2875+
low_count=Count(
2876+
"productpackages__package__affected_by_vulnerabilities",
2877+
filter=Q(
2878+
productpackages__package__affected_by_vulnerabilities__risk_level="low"
2879+
),
2880+
distinct=True,
2881+
),
28602882
license_warning_count=Count(
28612883
"productpackages__licenses",
28622884
filter=Q(productpackages__licenses__usage_policy__compliance_alert="warning"),
@@ -2867,20 +2889,12 @@ def get_queryset(self):
28672889
filter=Q(productpackages__licenses__usage_policy__compliance_alert="error"),
28682890
distinct=True,
28692891
),
2870-
max_risk_level=Case(
2871-
When(max_risk_score__gte=8.0, then=Value("critical")),
2872-
When(max_risk_score__gte=6.0, then=Value("high")),
2873-
When(max_risk_score__gte=3.0, then=Value("medium")),
2874-
When(max_risk_score__gte=0.1, then=Value("low")),
2875-
default=Value(""),
2876-
output_field=CharField(max_length=8),
2877-
),
28782892
).order_by(
28792893
F("max_risk_score").desc(nulls_last=True),
28802894
"-license_error_count",
28812895
"-license_warning_count",
28822896
"name",
2883-
"version",
2897+
"-version",
28842898
)
28852899

28862900
def get_context_data(self, **kwargs):
@@ -2910,6 +2924,8 @@ def get_context_data(self, **kwargs):
29102924
total_vulnerabilities=Sum("vulnerability_count"),
29112925
total_critical=Sum("critical_count"),
29122926
total_high=Sum("high_count"),
2927+
total_medium=Sum("medium_count"),
2928+
total_low=Sum("low_count"),
29132929
)
29142930

29152931
context.update(
@@ -2921,6 +2937,8 @@ def get_context_data(self, **kwargs):
29212937
"total_vulnerabilities": totals["total_vulnerabilities"] or 0,
29222938
"total_critical": totals["total_critical"] or 0,
29232939
"total_high": totals["total_high"] or 0,
2940+
"total_medium": totals["total_medium"] or 0,
2941+
"total_low": totals["total_low"] or 0,
29242942
}
29252943
)
29262944

0 commit comments

Comments
 (0)