Skip to content

Commit 358de4a

Browse files
committed
display filter labels and fix colors
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent f339dd9 commit 358de4a

4 files changed

Lines changed: 38 additions & 34 deletions

File tree

dejacode/static/css/dejacode_bootstrap.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ table.text-break thead {
9494
}
9595
.bg-warning-orange {
9696
background-color: var(--bs-orange);
97+
color: #000;
98+
}
99+
.text-warning-orange {
100+
color: var(--bs-orange) !important;
97101
}
98102
.spinner-border-md {
99103
--bs-spinner-width: 1.5rem;

product_portfolio/filters.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,23 @@ class Meta:
130130
]
131131

132132

133+
class HasComplianceIssueFilter(django_filters.BooleanFilter):
134+
"""Filter objects that have a compliance alert (warning or error) on their usage policy."""
135+
136+
def __init__(self, *args, **kwargs):
137+
kwargs.setdefault("label", _("Compliance issues"))
138+
kwargs.setdefault("field_name", "compliance_alert")
139+
super().__init__(*args, **kwargs)
140+
141+
def filter(self, qs, value):
142+
if value is None:
143+
return qs
144+
lookup = {f"{self.field_name}__in": ["warning", "error"]}
145+
if value:
146+
return qs.filter(**lookup)
147+
return qs.exclude(**lookup)
148+
149+
133150
class BaseProductRelationFilterSet(DataspacedFilterSet):
134151
field_name_prefix = None
135152
dropdown_fields = [
@@ -149,6 +166,7 @@ class BaseProductRelationFilterSet(DataspacedFilterSet):
149166
)
150167
is_modified = BooleanChoiceFilter()
151168
object_type = django_filters.CharFilter(
169+
label="Item type",
152170
method="filter_object_type",
153171
widget=DropDownWidget(
154172
anchor="#inventory",
@@ -178,6 +196,14 @@ class BaseProductRelationFilterSet(DataspacedFilterSet):
178196
to_field_name="key",
179197
queryset=License.objects.only("key", "short_name", "dataspace__id"),
180198
)
199+
has_licenses = HasValueFilter(
200+
label=_("Has licenses"),
201+
field_name="license_expression",
202+
)
203+
license_compliance_issues = HasComplianceIssueFilter(
204+
label="License compliance issues",
205+
field_name="licenses__usage_policy__compliance_alert",
206+
)
181207

182208
@staticmethod
183209
def filter_object_type(queryset, name, value):
@@ -244,6 +270,9 @@ class ProductComponentFilterSet(BaseProductRelationFilterSet):
244270
anchor="#inventory", right_align=True, link_content='<i class="fas fa-bug"></i>'
245271
),
246272
)
273+
compliance_issues = HasComplianceIssueFilter(
274+
field_name="component__usage_policy__compliance_alert",
275+
)
247276

248277
class Meta:
249278
model = ProductComponent
@@ -256,23 +285,6 @@ class Meta:
256285
]
257286

258287

259-
class HasComplianceIssueFilter(django_filters.BooleanFilter):
260-
"""Filter objects that have a compliance alert (warning or error) on their usage policy."""
261-
262-
def __init__(self, *args, **kwargs):
263-
kwargs.setdefault("label", _("Compliance issues"))
264-
kwargs.setdefault("field_name", "compliance_alert")
265-
super().__init__(*args, **kwargs)
266-
267-
def filter(self, qs, value):
268-
if value is None:
269-
return qs
270-
lookup = {f"{self.field_name}__in": ["warning", "error"]}
271-
if value:
272-
return qs.filter(**lookup)
273-
return qs.exclude(**lookup)
274-
275-
276288
class ProductPackageFilterSet(BaseProductRelationFilterSet):
277289
field_name_prefix = "package"
278290
dropdown_fields = [
@@ -331,18 +343,9 @@ class ProductPackageFilterSet(BaseProductRelationFilterSet):
331343
("unknown", _("Reachability not known")),
332344
),
333345
)
334-
has_licenses = HasValueFilter(
335-
label=_("Has licenses"),
336-
field_name="license_expression",
337-
)
338346
compliance_issues = HasComplianceIssueFilter(
339-
label="Package compliance issues",
340347
field_name="package__usage_policy__compliance_alert",
341348
)
342-
license_compliance_issues = HasComplianceIssueFilter(
343-
label="License compliance issues",
344-
field_name="licenses__usage_policy__compliance_alert",
345-
)
346349

347350
class Meta:
348351
model = ProductPackage
@@ -356,9 +359,6 @@ class Meta:
356359
"vulnerability_analyses__justification",
357360
"is_reachable",
358361
"exploitability",
359-
"has_licenses",
360-
"compliance_issues",
361-
"license_compliance_issues",
362362
]
363363

364364
def __init__(self, *args, **kwargs):

product_portfolio/templates/product_portfolio/compliance/compliance_panels.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ <h3 class="fs-6 fw-medium mb-0">{% trans "Security compliance" %}</h3>
7878
{% elif max_vulnerability_severity == "critical" %}
7979
<span class="badge text-bg-danger">{% trans "Critical" %}</span>
8080
{% elif max_vulnerability_severity == "high" %}
81-
<span class="badge" style="background-color: var(--bs-orange); color: #fff;">{% trans "High" %}</span>
81+
<span class="badge bg-warning-orange">{% trans "High" %}</span>
8282
{% elif max_vulnerability_severity == "medium" %}
8383
<span class="badge text-bg-warning">{% trans "Medium" %}</span>
8484
{% else %}
@@ -114,7 +114,7 @@ <h3 class="fs-6 fw-medium mb-0">{% trans "Security compliance" %}</h3>
114114
{% if vulnerability.risk_score_label == "critical" %}
115115
<span class="badge text-bg-danger">{% trans "Critical" %}</span>
116116
{% elif vulnerability.risk_score_label == "high" %}
117-
<span class="badge" style="background-color: var(--bs-orange); color: #fff;">{% trans "High" %}</span>
117+
<span class="badge bg-warning-orange">{% trans "High" %}</span>
118118
{% elif vulnerability.risk_score_label == "medium" %}
119119
<span class="badge text-bg-warning">{% trans "Medium" %}</span>
120120
{% elif vulnerability.risk_score_label == "low" %}

product_portfolio/templates/product_portfolio/compliance/metric_cards.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<div class="col-6 col-md-3">
1919
<div class="bg-body-secondary rounded-3 p-3">
2020
<div class="small text-body-secondary mb-1">{% trans "License compliance" %}</div>
21-
<div class="fs-4 fw-medium lh-sm {% if license_compliance_pct == 100 %}text-success{% elif license_compliance_pct >= 90 %}text-warning{% else %}text-danger{% endif %}">
21+
<div class="fs-4 fw-medium lh-sm {% if license_compliance_pct == 100 %}text-success{% elif license_compliance_pct >= 90 %}text-warning-orange{% else %}text-danger{% endif %}">
2222
{{ license_compliance_pct }}%
2323
</div>
2424
<div class="text-body-tertiary fs-xs mt-1">
@@ -35,7 +35,7 @@
3535
<div class="col-6 col-md-3">
3636
<div class="bg-body-secondary rounded-3 p-3">
3737
<div class="small text-body-secondary mb-1">{% trans "License coverage" %}</div>
38-
<div class="fs-4 fw-medium lh-sm {% if license_coverage_pct == 100 %}text-success{% elif license_coverage_pct >= 90 %}text-warning{% else %}text-danger{% endif %}">
38+
<div class="fs-4 fw-medium lh-sm {% if license_coverage_pct == 100 %}text-success{% elif license_coverage_pct >= 90 %}text-warning-orange{% else %}text-danger{% endif %}">
3939
{{ license_coverage_pct }}%
4040
</div>
4141
<div class="text-body-tertiary fs-xs mt-1">
@@ -66,7 +66,7 @@
6666
{% trans "of" %} {{ vulnerability_count }} {% trans "above threshold of" %} {{ risk_threshold_number }}
6767
</div>
6868
{% else %}
69-
<div class="fs-4 fw-medium lh-sm {% if max_vulnerability_severity == 'critical' %}text-danger{% elif max_vulnerability_severity == 'high' or max_vulnerability_severity == 'medium' %}text-warning{% else %}text-info{% endif %}">
69+
<div class="fs-4 fw-medium lh-sm {% if max_vulnerability_severity == 'critical' %}text-danger{% elif max_vulnerability_severity == 'high' %}text-warning-orange{% elif max_vulnerability_severity == 'medium' %}text-warning{% else %}text-info{% endif %}">
7070
{{ vulnerability_count }}
7171
</div>
7272
<div class="text-body-tertiary fs-xs mt-1">

0 commit comments

Comments
 (0)