Skip to content

Commit 3ad6439

Browse files
authored
Merge pull request #251 from jan-cerny/issue250
Fix colors in CPE AL details
2 parents ce3f578 + fb03120 commit 3ad6439

File tree

4 files changed

+16
-29
lines changed

4 files changed

+16
-29
lines changed

openscap_report/report_generators/html_templates/js/oval_graph_generation_script.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function generate_oval_tree(self, div_id_with_oval_graph_data) { // eslint-disab
167167
}
168168

169169
function get_CPE_AL_tree_node(root) {
170-
if (root.node_type == 'frac-ref') {
170+
if (root.node_type == 'fact-ref') {
171171
return undefined;
172172
}
173173

@@ -178,8 +178,8 @@ function get_CPE_AL_tree_node(root) {
178178
ul.setAttribute('role', "group");
179179
const fragment = document.createDocumentFragment();
180180
for (const child of root.children) {
181-
if (child.node_type == "frac-ref") {
182-
fragment.appendChild(render_CPE_frac_ref(child));
181+
if (child.node_type == "fact-ref") {
182+
fragment.appendChild(render_CPE_fact_ref(child));
183183
} else {
184184
fragment.appendChild(get_CPE_AL_tree_node(child));
185185
}
@@ -201,24 +201,15 @@ function get_colors_and_icons(node_data) {
201201
color = 'pf-m-red';
202202
icon = 'fa-times';
203203
}
204-
205-
let negate_color = '';
206-
let negate_icon = icon;
207-
if (node_data.negation) {
208-
negate_color = COLOR_TRANSLATION[NEGATION_COLOR[color]];
209-
negate_icon = NEGATION_ICON[icon];
210-
} else {
211-
negate_color = COLOR_TRANSLATION[color];
212-
}
213-
return { color, icon, negate_color, negate_icon };
204+
return { color, icon };
214205
}
215206

216207

217208
function base_operator_node(node_data, node_text) {
218-
const { color, icon, negate_color, negate_icon } = get_colors_and_icons(node_data);
219-
const node = get_node(negate_color);
209+
const { color, icon } = get_colors_and_icons(node_data);
210+
const node = get_node(COLOR_TRANSLATION[color]);
220211
node_text.appendChild(node);
221-
const html_icon = get_icon_as_html(negate_icon);
212+
const html_icon = get_icon_as_html(icon);
222213
node.appendChild(html_icon);
223214
if (node_data.negation) {
224215
node.appendChild(get_operator_label_with_tooltip("NOT", OVAL_OPERATOR_EXPLANATION));
@@ -241,12 +232,12 @@ function get_CPE_AL_operator_node(node_data) {
241232
}
242233

243234

244-
function render_CPE_frac_ref(node_data) {
235+
function render_CPE_fact_ref(node_data) {
245236
const { operator_node, node_text } = get_operator_node();
246237
const { node, color, icon } = base_operator_node(node_data.oval_tree, node_text);
247238

248239
node.appendChild(get_bold_text(` Reference to OVAL definition `));
249-
node_text.appendChild(get_label(color, "frac-ref", undefined, "cpe-label"," cpe-label__content"));
240+
node_text.appendChild(get_label(color, "fact-ref", undefined, "cpe-label"," cpe-label__content"));
250241
const span_space = SPAN.cloneNode();
251242
span_space.innerText = "\u00A0";
252243
node_text.appendChild(span_space);
@@ -321,11 +312,11 @@ function get_test_node() {
321312

322313
function render_OVAL_test(node_data) {
323314
const { test_node, node_content, node_text } = get_test_node();
324-
const { color, icon, negate_color, negate_icon } = get_colors_and_icons(node_data);
315+
const { color, icon } = get_colors_and_icons(node_data);
325316

326-
const node = get_node(negate_color);
317+
const node = get_node(COLOR_TRANSLATION[color]);
327318
node_text.appendChild(node);
328-
const html_icon = get_icon_as_html(negate_icon);
319+
const html_icon = get_icon_as_html(icon);
329320
node.appendChild(html_icon);
330321
if (node_data.negation) {
331322
node.appendChild(get_operator_label_with_tooltip("NOT", OVAL_OPERATOR_EXPLANATION));

openscap_report/scap_results_parser/data_structures/cpe_logical_test.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ def _get_result_counts(self):
3131
result = Counter(EMPTY_RESULT)
3232
for child in self.children:
3333
value = None
34-
if child.node_type == "frac-ref":
34+
if child.node_type == "fact-ref":
3535
value = str(child.oval_tree.evaluate_tree())
3636
else:
3737
value = str(child.evaluate_tree())
3838

3939
node_result = OVAL_RESULT_TO_CPE_RESULT.get(value, "error")
40-
if child.negation:
41-
node_result = NEGATE_VALUE[value]
4240
result[f"number_of_{node_result}"] += 1
4341
return result
4442

@@ -48,8 +46,6 @@ def _eval_operator(self, cpe_result):
4846
out_result = cpe_result.eval_operator_or()
4947
elif self.node_type.lower() == "and":
5048
out_result = cpe_result.eval_operator_and()
51-
if out_result is not None:
52-
self.value = out_result
5349
return out_result
5450

5551
def evaluate_tree(self):
@@ -58,4 +54,5 @@ def evaluate_tree(self):
5854
out_result = self._eval_operator(cpe_result)
5955
if self.negation:
6056
out_result = NEGATE_VALUE[out_result]
57+
self.value = out_result
6158
return out_result

openscap_report/scap_results_parser/oval_and_cpe_tree_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _load_cpe_platforms(self):
9090
logical_test=LogicalTest(
9191
node_type="AND",
9292
children=[LogicalTest(
93-
node_type="frac-ref",
93+
node_type="fact-ref",
9494
value=oval_definition.definition_id,
9595
oval_tree=oval_definition.oval_tree
9696
)],

openscap_report/scap_results_parser/parsers/cpe_al_parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ def get_logical_test(self, logical_test_el):
6161
check_id_ref = child_logical_test_el.get("id-ref")
6262
logical_test.children.append(
6363
LogicalTest(
64-
node_type="frac-ref",
65-
value=platform_name if platform_name is not None else check_id_ref,
64+
node_type="fact-ref",
6665
oval_tree=self._get_oval_cpe_tree(platform_name, check_id_ref))
6766
)
6867
if child_logical_test_el.get('operator') is not None:

0 commit comments

Comments
 (0)