Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions apps/web/src/lib/workflows/editor/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,31 @@ export const STEPS: StepSpec[] = [
{ path: 'with.error', label: 'Why it failed', kind: 'expression' }
]
},
{
type: 'core.grc.record_test',
label: 'Record a control test',
description:
'Keep what a compliance control test found as evidence. A pass counts for the test’s validity period; a failure raises control.failed.',
group: 'Actions',
module: 'grc',
template: { with: { test_id: '', passed: true, summary: '' } },
fields: [
{ path: 'with.test_id', label: 'Control test', kind: 'expression', hint: 'The test’s ID' },
{ path: 'with.passed', label: 'Passed', kind: 'expression', hint: 'true or false' },
{ path: 'with.summary', label: 'What it found', kind: 'expression' },
{ path: 'with.data', label: 'Data behind it', kind: 'expression' }
]
},
{
type: 'core.grc.expiring_evidence',
label: 'Find expiring evidence',
description:
'Compliance evidence about to expire, once per piece, with each program owner to tell.',
group: 'Actions',
module: 'grc',
template: { with: { days: 14 } },
fields: [{ path: 'with.days', label: 'Days ahead', kind: 'expression' }]
},
{
type: 'core.sales.log_email',
label: 'Log a sales email',
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/lib/workflows/editor/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ const ICONS: Record<string, typeof Globe> = {
'core.expense.read_receipt': ListChecks,
'core.expense.report_decide': ListChecks,
'core.expense.sync_result': ListChecks,
'core.grc.record_test': ListChecks,
'core.grc.expiring_evidence': ListChecks,
'core.sales.log_email': ListChecks,
'core.scope.context': ListChecks,
'core.scope.write': ListChecks,
Expand Down
23 changes: 23 additions & 0 deletions apps/web/src/routes/(app)/compliance/evidence/[id]/file/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { RequestHandler } from '@sveltejs/kit';
import { apiHeaders, apiUrl } from '#lib/server/api.ts';
import { withheld } from '#lib/server/withheld.ts';

/** Downloads an evidence file from the API. */
export const GET: RequestHandler = async (event) => {
const id = encodeURIComponent(event.params.id ?? '');
const upstream = await fetch(`${apiUrl}/api/v1/grc/evidence/${id}/file`, {
headers: apiHeaders(event),
signal: event.request.signal
}).catch(() => null);
const scan = await withheld(upstream);
if (scan) return scan;
if (!upstream?.ok || !upstream.body) {
return new Response('No file.', { status: upstream?.status ?? 503 });
}
const headers = new Headers({ 'x-content-type-options': 'nosniff' });
for (const name of ['content-type', 'content-disposition']) {
const value = upstream.headers.get(name);
if (value) headers.set(name, value);
}
return new Response(upstream.body, { headers });
};
14 changes: 13 additions & 1 deletion apps/web/src/routes/(app)/compliance/programs/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@
<th class="py-2 pr-3 font-medium">Requirements</th>
<th class="py-2 pr-3 font-medium">Status</th>
<th class="py-2 pr-3 font-medium">Responsibility</th>
<th class="py-2 pr-3 font-medium">Evidence</th>
<th class="py-2 pr-3 font-medium">Owner</th>
<th class="py-2 pr-3 font-medium">Target</th>
<th class="py-2"><span class="sr-only">Change</span></th>
Expand All @@ -317,7 +318,10 @@
<tr>
<td class="py-2 pr-3">
<a
href={resolve('/(app)/compliance/controls/[id]', { id: c.controlId })}
href={resolve('/(app)/compliance/programs/[id]/controls/[controlId]', {
id: p.id,
controlId: c.controlId
})}
class="text-fg hover:underline"
>
<span class="font-mono font-semibold">{c.ref}</span>
Expand All @@ -331,6 +335,14 @@
<td class="py-2 pr-3 text-fg">
{label(RESPONSIBILITIES, c.responsibility)}{#if c.thirdParty}: {c.thirdParty}{/if}
</td>
<td class="py-2 pr-3">
<span class="text-fg-muted">{c.evidenceCount}</span>
{#if c.expiredCount > 0}<Badge tone="warning">
{c.expiredCount} expired
</Badge>{/if}
{#if c.testsPassing === true}<Badge tone="success">Tests pass</Badge>{/if}
{#if c.testsPassing === false}<Badge tone="danger">Test failing</Badge>{/if}
</td>
<td class="py-2 pr-3 text-fg-muted">{c.ownerName ?? '—'}</td>
<td class="py-2 pr-3 text-fg-muted">{c.targetDate ?? '—'}</td>
<td class="py-2 text-right">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { error, fail } from '@sveltejs/kit';
import { formString } from '#lib/forms.ts';
import { api, apiHeaders, apiUrl } from '#lib/server/api.ts';
import { complianceAccess, failed } from '#lib/compliance/server.ts';
import type { Actions, PageServerLoad } from './$types';

export const load: PageServerLoad = async (event) => {
const { user } = await event.parent();
complianceAccess(user);
const client = api(event);
const { id, controlId } = event.params;
const [program, controls, evidence, tests, workflows] = await Promise.all([
client.GET('/api/v1/grc/programs/{id}', { params: { path: { id } } }),
client.GET('/api/v1/grc/programs/{id}/controls', { params: { path: { id } } }),
client.GET('/api/v1/grc/programs/{id}/controls/{control_id}/evidence', {
params: { path: { id, control_id: controlId } }
}),
client.GET('/api/v1/grc/programs/{id}/tests', { params: { path: { id } } }),
user.grantedPermissions.includes('workflow:read')
? client.GET('/api/v1/workflows')
: Promise.resolve({ data: [] })
]);
if (!program.data) error(program.response.status === 404 ? 404 : 503, 'No such program.');
const control = (controls.data ?? []).find((c) => c.controlId === controlId);
if (!control) error(404, 'That control isn’t in this program.');
return {
program: program.data,
control,
evidence: evidence.data ?? [],
tests: (tests.data ?? []).filter((t) => t.controlId === controlId),
workflows: (Array.isArray(workflows.data) ? workflows.data : []).map((w) => ({
value: w.id,
label: w.name
})),
canAssess: user.grantedPermissions.includes('grc:assess')
};
};

export const actions: Actions = {
addEvidence: async (event) => {
const form = await event.request.formData();
const kind = formString(form, 'kind') === 'link' ? 'link' : 'note';
const { error: problem, response } = await api(event).POST(
'/api/v1/grc/programs/{id}/controls/{control_id}/evidence',
{
params: { path: { id: event.params.id, control_id: event.params.controlId } },
body: {
kind,
title: formString(form, 'title'),
body: formString(form, 'body') || null,
url: formString(form, 'url') || null,
validUntil: formString(form, 'validUntil') || null,
supersedes: formString(form, 'supersedes') || null
}
}
);
if (!response.ok) return failed(response.status, problem, 'Could not keep it.');
return { message: 'Kept.' };
},
upload: async (event) => {
const form = await event.request.formData();
const file = form.get('file');
if (!(file instanceof File) || file.size === 0) return fail(400, { message: 'Choose a file.' });
const body = new FormData();
for (const k of ['title', 'validUntil', 'supersedes']) {
const v = formString(form, k).trim();
if (v) body.append(k, v);
}
body.append('file', file, file.name);
const res = await fetch(
`${apiUrl}/api/v1/grc/programs/${encodeURIComponent(event.params.id)}/controls/${encodeURIComponent(event.params.controlId)}/evidence/file`,
{ method: 'POST', headers: apiHeaders(event), body }
);
const data: unknown = await res.json().catch(() => null);
if (!res.ok) return failed(res.status, data, 'Could not keep the file.');
return { message: 'Kept.' };
},
addTest: async (event) => {
const form = await event.request.formData();
const { error: problem, response } = await api(event).POST('/api/v1/grc/programs/{id}/tests', {
params: { path: { id: event.params.id } },
body: {
controlId: event.params.controlId,
name: formString(form, 'name'),
description: formString(form, 'description') || null,
workflowId: formString(form, 'workflowId') || null,
validityDays: Number(formString(form, 'validityDays') || '30')
}
});
if (!response.ok) return failed(response.status, problem, 'Could not add it.');
return { message: 'Added. Have its workflow record results with this test’s ID.' };
},
toggleTest: async (event) => {
const form = await event.request.formData();
const { error: problem, response } = await api(event).PUT('/api/v1/grc/control-tests/{id}', {
params: { path: { id: formString(form, 'testId') } },
body: {
controlId: event.params.controlId,
name: formString(form, 'name'),
workflowId: formString(form, 'workflowId') || null,
validityDays: Number(formString(form, 'validityDays')),
active: formString(form, 'active') === 'true'
}
});
if (!response.ok) return failed(response.status, problem, 'Could not change it.');
return { message: 'Saved.' };
},
deleteTest: async (event) => {
const form = await event.request.formData();
const { error: problem, response } = await api(event).DELETE('/api/v1/grc/control-tests/{id}', {
params: { path: { id: formString(form, 'testId') } }
});
if (!response.ok) return failed(response.status, problem, 'Could not remove it.');
return { message: 'Removed.' };
}
};
Loading