Skip to content

Commit fdf9ef7

Browse files
Improve display of SSVC decision tree in UI using YAML format #2058
1 parent 053c8fb commit fdf9ef7

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

vulnerabilities/templates/advisory_detail.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{% load static %}
55
{% load show_cvss %}
66
{% load url_filters %}
7+
{% load ssvc_filters %}
78

89
{% block title %}
910
VulnerableCode Advisory Details - {{ advisory.advisory_id }}
@@ -583,7 +584,7 @@
583584
<summary class="is-size-7 has-text-link" style="cursor: pointer;">
584585
View SSVC decision tree
585586
</summary>
586-
<pre>{{ ssvc.options|pprint }}</pre>
587+
<pre>{{ ssvc.options|to_yaml }}</pre>
587588
</details>
588589
</div>
589590
</div>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
10+
import saneyaml
11+
from django import template
12+
13+
register = template.Library()
14+
15+
16+
@register.filter(name="to_yaml")
17+
def to_yaml(value):
18+
"""
19+
Convert a Python object (typically SSVC options) to a
20+
human-readable YAML string.
21+
"""
22+
if not value:
23+
return ""
24+
try:
25+
return saneyaml.dump(value).strip()
26+
except Exception:
27+
return str(value)
28+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
10+
from vulnerabilities.templatetags.ssvc_filters import to_yaml
11+
12+
13+
def test_to_yaml_with_ssvc_options():
14+
options = [
15+
{"Exploitation": "active"},
16+
{"Automatable": "yes"},
17+
{"Technical Impact": "total"},
18+
{"Mission Prevalence": "essential"},
19+
{"Public Well-being Impact": "irreversible"},
20+
{"Mission & Well-being": "high"},
21+
]
22+
result = to_yaml(options)
23+
assert "Exploitation: active" in result
24+
assert "Technical Impact: total" in result
25+
assert "Mission Prevalence: essential" in result
26+
assert "Public Well-being Impact: irreversible" in result
27+
28+
29+
def test_to_yaml_with_empty_value():
30+
assert to_yaml(None) == ""
31+
assert to_yaml([]) == ""
32+
assert to_yaml("") == ""
33+
34+
35+
def test_to_yaml_with_non_serializable_value():
36+
result = to_yaml("plain string")
37+
assert isinstance(result, str)
38+

0 commit comments

Comments
 (0)