Skip to content

Commit 4c2be20

Browse files
Merge pull request #1768 from lucasclgibson/claude/fix-audit-high-findings
Fix the High findings from the UI audit
2 parents ca0f212 + 144fbdd commit 4c2be20

137 files changed

Lines changed: 669 additions & 400 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎sbomify/apps/compliance/apis.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def save_doc_signature(request: HttpRequest, assessment_id: str, payload: Signat
540540
``mark_safe`` rendering path (worst case).
541541
542542
Saving the signature bumps any existing DoC ``CRAGeneratedDocument``
543-
to ``is_stale=True`` so the wizard's "Refresh Stale Documents"
543+
to ``is_stale=True`` so the wizard's "Refresh stale documents"
544544
button picks it up — the operator must regenerate before the
545545
public reader will surface the updated declaration. We do not
546546
auto-regenerate here because a signature change is a deliberate

‎sbomify/apps/compliance/js/cra-doc-signature.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Saving deliberately marks the existing DoC ``CRAGeneratedDocument``
1212
* as stale rather than auto-regenerating; the operator confirms by
1313
* clicking "Generate Declaration of Conformity" afterwards. The
14-
* "Refresh Stale Documents" button picks the change up automatically.
14+
* "Refresh stale documents" button picks the change up automatically.
1515
*/
1616
import SignaturePad from 'signature_pad';
1717

‎sbomify/apps/compliance/templates/compliance/components/cra_stepper.html.j2‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{# CRA Wizard Step Progress Bar #}
22
{# Expects: step (int), step_names (dict), completed_steps (list), assessment_id (str) #}
33
{# A completed step is a link back to it: the anchor wraps the step, because a #}
4-
{# step is not a link everywhere else the rail is used. #}
4+
{# step is not a link everywhere else the rail is used. Captions are sr-only on #}
5+
{# phones rather than hidden, because they are the only name those links have. #}
56
<nav aria-label="Wizard progress">
67
<c-navigation.stepper>
78
{% for step_num, step_label in step_names.items %}
89
{% if step_num in completed_steps and step_num != step %}
910
<a href="{% url 'compliance:cra_step' assessment_id=assessment_id step=step_num %}">
10-
<c-navigation.stepper-step state="completed" label="{{ step_label }}" label_class="hidden sm:inline">
11+
<c-navigation.stepper-step state="completed" label="{{ step_label }}" label_class="sr-only sm:not-sr-only">
1112
<i class="fas fa-check text-xs" aria-hidden="true"></i>
1213
</c-navigation.stepper-step>
1314
</a>
1415
{% elif step_num == step %}
15-
<c-navigation.stepper-step state="active" label="{{ step_label }}" label_class="hidden sm:inline" aria-current="step">{{ step_num }}</c-navigation.stepper-step>
16+
<c-navigation.stepper-step state="active" label="{{ step_label }}" label_class="sr-only sm:not-sr-only" aria-current="step">{{ step_num }}</c-navigation.stepper-step>
1617
{% else %}
17-
<c-navigation.stepper-step label="{{ step_label }}" label_class="hidden sm:inline">{{ step_num }}</c-navigation.stepper-step>
18+
<c-navigation.stepper-step label="{{ step_label }}" label_class="sr-only sm:not-sr-only">{{ step_num }}</c-navigation.stepper-step>
1819
{% endif %}
1920
{% if not forloop.last %}
2021
{% if step_num in completed_steps %}

‎sbomify/apps/compliance/templates/compliance/components/document_card.html.j2‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{# Document card — used inside x-for loop with `doc` variable (docKinds item) in scope #}
22
<c-cards.card flush>
3-
<div class="px-4 py-3 flex items-center justify-between">
4-
<div class="flex items-center gap-3">
5-
<i class="fas fa-file-lines text-text-muted"></i>
6-
<span class="font-medium text-text text-sm" x-text="doc.label"></span>
3+
{# Wraps on a phone: the status and actions drop under the name rather than squeezing it. #}
4+
<div class="px-4 py-3 flex flex-wrap items-center justify-between gap-x-3 gap-y-2">
5+
<div class="flex min-w-0 flex-1 items-center gap-3">
6+
<i class="fas fa-file-lines text-text-muted" aria-hidden="true"></i>
7+
<span class="min-w-0 font-medium text-text text-sm" x-text="doc.label"></span>
78
</div>
8-
<div class="flex items-center gap-2">
9+
<div class="ml-auto flex shrink-0 items-center gap-2">
910
<template x-if="getDocStatus(doc.key) === 'current'">
1011
<c-badges.success>Current</c-badges.success>
1112
</template>
@@ -16,13 +17,15 @@
1617
<c-badges.secondary>Not generated</c-badges.secondary>
1718
</template>
1819
<c-buttons.ghost size="sm" @click="previewDocument(doc.key, doc.label)" ::aria-label="'Preview ' + doc.label">
19-
<i class="fas fa-eye"></i>
20+
<i class="fas fa-eye" aria-hidden="true"></i>
2021
</c-buttons.ghost>
2122
<c-buttons.ghost size="sm" @click="generateDocument(doc.key)" ::disabled="generatingDoc === doc.key" ::aria-label="'Generate ' + doc.label">
2223
<span x-show="generatingDoc === doc.key">
2324
{% include "core/components/brand/loader.html.j2" with class="tw-loader-inline" %}
2425
</span>
25-
<i x-show="generatingDoc !== doc.key" class="fas fa-rotate"></i>
26+
<i x-show="generatingDoc !== doc.key"
27+
class="fas fa-rotate"
28+
aria-hidden="true"></i>
2629
</c-buttons.ghost>
2730
</div>
2831
</div>

‎sbomify/apps/compliance/templates/compliance/cra_step_5.html.j2‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,24 @@
155155
</div>
156156
</c-slot>
157157
<c-buttons.secondary @click="refreshStale()" ::disabled="isRefreshing" class="w-full">
158-
<span x-show="!isRefreshing"><i class="fas fa-sync mr-2"></i> Refresh Stale Documents</span>
158+
<span x-show="!isRefreshing"><i class="fas fa-sync mr-2" aria-hidden="true"></i> Refresh stale documents</span>
159159
<span x-show="isRefreshing" x-cloak>
160160
{% include "core/components/brand/loader.html.j2" with class="tw-loader-inline mr-2" %}
161161
Refreshing...</span>
162162
</c-buttons.secondary>
163163
{# Prominent DoC preview — CRA Article 28 declaration must be reviewed before signing #}
164164
<c-buttons.secondary @click="previewDocument('declaration_of_conformity', 'Declaration of Conformity')" data-testid="preview-doc-btn" class="w-full">
165-
<i class="fas fa-eye mr-2"></i> Preview Declaration of Conformity
165+
<i class="fas fa-eye mr-2" aria-hidden="true"></i> Preview declaration
166166
</c-buttons.secondary>
167167
{# On-demand DoC PDF — sidesteps the full bundle export when an auditor or notified body just wants the signed Article 28 declaration as a PDF #}
168168
<c-buttons.secondary @click="downloadDocumentPdf('declaration_of_conformity', 'Declaration of Conformity')" ::disabled="downloadingDocPdf" data-testid="download-doc-pdf-btn" class="w-full">
169-
<span x-show="!downloadingDocPdf"><i class="fas fa-file-pdf mr-2"></i> Download Declaration of Conformity (PDF)</span>
169+
<span x-show="!downloadingDocPdf"><i class="fas fa-file-pdf mr-2" aria-hidden="true"></i> Download declaration (PDF)</span>
170170
<span x-show="downloadingDocPdf" x-cloak>
171171
{% include "core/components/brand/loader.html.j2" with class="tw-loader-inline mr-2" %}
172172
Preparing PDF…</span>
173173
</c-buttons.secondary>
174174
<c-buttons.primary @click="exportBundle()" ::disabled="isExporting || !exportAvailable" class="w-full">
175-
<span x-show="!isExporting"><i class="fas fa-download mr-2"></i> Export Compliance Bundle</span>
175+
<span x-show="!isExporting"><i class="fas fa-download mr-2" aria-hidden="true"></i> Export compliance bundle</span>
176176
<span x-show="isExporting" x-cloak>
177177
{% include "core/components/brand/loader.html.j2" with class="tw-loader-inline mr-2" %}
178178
Exporting...</span>

‎sbomify/apps/core/js/htmx-bundle.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import '../../../assets/css/tailwind.src.css';
33

44
import '../../vulnerability_scanning/js/vulnerability-chart';
55
import './layout-interactions';
6+
import './table-stack';
67
import './alerts-global';
78
import './clipboard-global';
89

‎sbomify/apps/core/js/main.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { initThemeManager } from './theme-manager';
77
initThemeManager();
88

99
import './layout-interactions';
10+
import './table-stack';
1011
import './notifications-modal';
1112

1213
import Alpine from 'alpinejs';
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { describe, expect, test } from 'bun:test';
2+
3+
import { labelTable } from './table-stack';
4+
5+
interface FakeCell {
6+
colSpan: number;
7+
textContent: string;
8+
dataset: Record<string, string>;
9+
attributes: Map<string, string>;
10+
hasAttribute(name: string): boolean;
11+
setAttribute(name: string, value: string): void;
12+
}
13+
14+
function cell(text = '', colSpan = 1, dataset: Record<string, string> = {}): FakeCell {
15+
const attributes = new Map<string, string>();
16+
return {
17+
colSpan,
18+
textContent: text,
19+
dataset,
20+
attributes,
21+
hasAttribute: (name) => attributes.has(name),
22+
setAttribute: (name, value) => void attributes.set(name, value),
23+
};
24+
}
25+
26+
function table(headers: FakeCell[], rows: FakeCell[][]): HTMLTableElement {
27+
return {
28+
tHead: { rows: [{ cells: headers }] },
29+
tBodies: [{ rows: rows.map((cells) => ({ cells })) }],
30+
} as unknown as HTMLTableElement;
31+
}
32+
33+
describe('labelTable', () => {
34+
test('labels each cell with its column header', () => {
35+
const name = cell('Acme');
36+
const status = cell('Public');
37+
labelTable(table([cell(' Product \n'), cell('Visibility')], [[name, status]]));
38+
expect(name.attributes.get('data-label')).toBe('Product');
39+
expect(status.attributes.get('data-label')).toBe('Visibility');
40+
});
41+
42+
test('leaves full-width cells and empty headers unlabelled', () => {
43+
const empty = cell('No products yet', 2);
44+
const actions = cell('Edit');
45+
labelTable(table([cell('Product'), cell('')], [[empty], [cell('Acme'), actions]]));
46+
expect(empty.attributes.has('data-label')).toBe(false);
47+
expect(actions.attributes.has('data-label')).toBe(false);
48+
});
49+
50+
test('counts header colspans so later cells keep their column', () => {
51+
const last = cell('3 days');
52+
labelTable(table([cell('Name', 2), cell('Age')], [[cell('a'), cell('b'), last]]));
53+
expect(last.attributes.get('data-label')).toBe('Age');
54+
});
55+
56+
test("keeps a label the template already set, and honours a header's own label", () => {
57+
const own = cell('x');
58+
own.attributes.set('data-label', 'Custom');
59+
const fromHeader = cell('y');
60+
labelTable(table([cell('A'), cell('Sort', 1, { label: 'Severity' })], [[own, fromHeader]]));
61+
expect(own.attributes.get('data-label')).toBe('Custom');
62+
expect(fromHeader.attributes.get('data-label')).toBe('Severity');
63+
});
64+
65+
test('skips an empty header row a template left before the real one', () => {
66+
const value = cell('14 days');
67+
const stray = { cells: [] };
68+
const header = { cells: [cell('Patch SLA')] };
69+
labelTable({
70+
tHead: { rows: [stray, header] },
71+
tBodies: [{ rows: [{ cells: [value] }] }],
72+
} as unknown as HTMLTableElement);
73+
expect(value.attributes.get('data-label')).toBe('Patch SLA');
74+
});
75+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Column labels for tables that stack on phones.
3+
*
4+
* Below the sm breakpoint a `table[data-stack]` lays each row out as a block
5+
* (tailwind.src.css, "Stacked tables"), so the header row is no longer beside
6+
* the values it names. Each cell takes its column's header text as
7+
* `data-label`, which the stylesheet prints above the value.
8+
*
9+
* Tables arrive three ways: in the page, swapped in by HTMX, and filled by
10+
* Alpine `x-for` after either. The first two are caught on load and after each
11+
* settle; the third by watching each table for new rows.
12+
*/
13+
14+
const TABLE = 'table[data-stack]';
15+
const observed = new WeakSet<HTMLTableElement>();
16+
17+
function headerLabels(table: HTMLTableElement): string[] {
18+
const labels: string[] = [];
19+
// The row that holds the header cells: a stray empty <tr> before it would
20+
// otherwise leave every cell unlabelled.
21+
const headerRow = Array.from(table.tHead?.rows ?? []).find((row) => row.cells.length > 0);
22+
if (!headerRow) return labels;
23+
for (const th of Array.from(headerRow.cells)) {
24+
// An explicit data-label wins, for a header whose text is not a label.
25+
const text = (th.dataset.label ?? th.textContent ?? '').replace(/\s+/g, ' ').trim();
26+
for (let span = 0; span < Math.max(th.colSpan, 1); span++) labels.push(text);
27+
}
28+
return labels;
29+
}
30+
31+
export function labelTable(table: HTMLTableElement): void {
32+
const labels = headerLabels(table);
33+
if (!labels.length) return;
34+
for (const body of Array.from(table.tBodies)) {
35+
for (const row of Array.from(body.rows)) {
36+
let column = 0;
37+
for (const cell of Array.from(row.cells)) {
38+
const label = cell.colSpan > 1 ? '' : labels[column] ?? '';
39+
// A cell's own label is the author's choice; only fill the gap.
40+
if (!cell.hasAttribute('data-label') && label) cell.setAttribute('data-label', label);
41+
column += Math.max(cell.colSpan, 1);
42+
}
43+
}
44+
}
45+
}
46+
47+
function scan(root: ParentNode): void {
48+
if (typeof root.querySelectorAll !== 'function') return;
49+
root.querySelectorAll<HTMLTableElement>(TABLE).forEach((table) => {
50+
labelTable(table);
51+
if (observed.has(table)) return;
52+
observed.add(table);
53+
new MutationObserver(() => labelTable(table)).observe(table, { childList: true, subtree: true });
54+
});
55+
}
56+
57+
export function initTableStack(): void {
58+
if (document.readyState === 'loading') {
59+
document.addEventListener('DOMContentLoaded', () => scan(document));
60+
} else {
61+
scan(document);
62+
}
63+
// The whole document, not the event's element: after an outerHTML swap
64+
// that element is the one just removed, and the new table is not under it.
65+
document.addEventListener('htmx:afterSettle', () => scan(document));
66+
}
67+
68+
// Guarded so the pure labelling can be imported by a spec without a DOM.
69+
if (typeof document !== 'undefined' && typeof document.querySelectorAll === 'function') initTableStack();

‎sbomify/apps/core/templates/core/components/component_meta_info_editor.html.j2‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,11 @@
107107
<div class="space-y-3"
108108
x-data="{ prevRelease: metadata.release_date, prevEos: metadata.end_of_support, prevEol: metadata.end_of_life }"
109109
x-effect=" if (prevRelease !== metadata.release_date) { hasUnsavedChanges = true; prevRelease = metadata.release_date; } if (prevEos !== metadata.end_of_support) { hasUnsavedChanges = true; prevEos = metadata.end_of_support; } if (prevEol !== metadata.end_of_life) { hasUnsavedChanges = true; prevEol = metadata.end_of_life; } ">
110-
<c-forms.label>Key Dates</c-forms.label>
110+
<c-forms.label>Key dates</c-forms.label>
111111
<div class="grid grid-cols-1 md:grid-cols-3 gap-3">
112-
<!-- Release Date -->
113-
<div class="p-3 rounded-lg bg-border/10 border border-border/30">
114-
<div class="text-xs font-medium text-text-muted mb-2">Release Date</div>
115-
{% include 'components/date_picker.html.j2' with value_binding='metadata.release_date' placeholder='Set date...' %}
116-
</div>
117-
<!-- End of Support -->
118-
<div class="p-3 rounded-lg bg-border/10 border border-border/30">
119-
<div class="text-xs font-medium text-text-muted mb-2">End of Support</div>
120-
{% include 'components/date_picker.html.j2' with value_binding='metadata.end_of_support' placeholder='Set date...' %}
121-
</div>
122-
<!-- End of Life -->
123-
<div class="p-3 rounded-lg bg-border/10 border border-border/30">
124-
<div class="text-xs font-medium text-text-muted mb-2">End of Life</div>
125-
{% include 'components/date_picker.html.j2' with value_binding='metadata.end_of_life' placeholder='Set date...' %}
126-
</div>
112+
{% include 'components/date_picker.html.j2' with value_binding='metadata.release_date' label='Release date' %}
113+
{% include 'components/date_picker.html.j2' with value_binding='metadata.end_of_support' label='End of support' %}
114+
{% include 'components/date_picker.html.j2' with value_binding='metadata.end_of_life' label='End of life' %}
127115
</div>
128116
</div>
129117
</div>

0 commit comments

Comments
 (0)