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
2 changes: 2 additions & 0 deletions Cargo.lock

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

74 changes: 55 additions & 19 deletions apps/web/src/routes/(app)/compliance/programs/[id]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,35 @@ export const load: PageServerLoad = async (event) => {
frameworks[0]?.versionId;
const status = STATUSES.find((s) => s === params.get('status'));
const q = params.get('q')?.trim() || undefined;
const [requirements, controls, catalog, signoff, requests, contacts, assessments, findings] =
await Promise.all([
versionId
? client.GET('/api/v1/grc/programs/{id}/requirements', {
params: { path: { id }, query: { versionId, status, q } }
})
: Promise.resolve({ data: [] }),
client.GET('/api/v1/grc/programs/{id}/controls', { params: { path: { id } } }),
client.GET('/api/v1/grc/frameworks'),
client.GET('/api/v1/grc/programs/{id}/signoff', { params: { path: { id } } }),
client.GET('/api/v1/grc/programs/{id}/evidence-requests', { params: { path: { id } } }),
user.activeModules.includes('crm') && user.grantedPermissions.includes('crm:read')
? client.GET('/api/v1/orgs/{id}/contacts', { params: { path: { id: program.data.orgId } } })
: Promise.resolve({ data: undefined }),
client.GET('/api/v1/grc/programs/{id}/assessments', { params: { path: { id } } }),
client.GET('/api/v1/grc/programs/{id}/findings', {
params: { path: { id }, query: { closed: params.get('closed') === 'on' } }
})
]);
const [
requirements,
controls,
catalog,
signoff,
requests,
contacts,
assessments,
findings,
links
] = await Promise.all([
versionId
? client.GET('/api/v1/grc/programs/{id}/requirements', {
params: { path: { id }, query: { versionId, status, q } }
})
: Promise.resolve({ data: [] }),
client.GET('/api/v1/grc/programs/{id}/controls', { params: { path: { id } } }),
client.GET('/api/v1/grc/frameworks'),
client.GET('/api/v1/grc/programs/{id}/signoff', { params: { path: { id } } }),
client.GET('/api/v1/grc/programs/{id}/evidence-requests', { params: { path: { id } } }),
user.activeModules.includes('crm') && user.grantedPermissions.includes('crm:read')
? client.GET('/api/v1/orgs/{id}/contacts', { params: { path: { id: program.data.orgId } } })
: Promise.resolve({ data: undefined }),
client.GET('/api/v1/grc/programs/{id}/assessments', { params: { path: { id } } }),
client.GET('/api/v1/grc/programs/{id}/findings', {
params: { path: { id }, query: { closed: params.get('closed') === 'on' } }
}),
client.GET('/api/v1/grc/programs/{id}/audit-links', { params: { path: { id } } })
]);
const inProgram = new Set(frameworks.map((f) => f.versionId));
return {
program: program.data,
Expand All @@ -66,6 +76,7 @@ export const load: PageServerLoad = async (event) => {
signoff: signoff.data ?? null,
requests: requests.data ?? [],
assessments: assessments.data ?? [],
auditLinks: links.data ?? [],
findings: findings.data ?? [],
closedFindings: params.get('closed') === 'on',
canManageRisks: user.grantedPermissions.includes('risk:manage'),
Expand Down Expand Up @@ -103,6 +114,31 @@ async function setFramework(event: Parameters<Actions[string]>[0], form: FormDat
}

export const actions: Actions = {
createAuditLink: async (event) => {
const form = await event.request.formData();
const {
data,
error: problem,
response
} = await api(event).POST('/api/v1/grc/programs/{id}/audit-links', {
params: { path: { id: event.params.id } },
body: { label: formString(form, 'label'), days: Number(formString(form, 'days') || '14') }
});
if (!data) return failed(response.status, problem, 'Could not make the link.');
return {
message: 'Link made. Copy it now: it isn’t shown again.',
auditUrl: `${event.url.origin}/audit/${data.token}`
};
},
revokeAuditLink: async (event) => {
const form = await event.request.formData();
const { error: problem, response } = await api(event).POST(
'/api/v1/grc/audit-links/{id}/revoke',
{ params: { path: { id: formString(form, 'linkId') } } }
);
if (!response.ok) return failed(response.status, problem, 'Could not turn it off.');
return { message: 'Turned off.' };
},
startAssessment: async (event) => {
const form = await event.request.formData();
const {
Expand Down
62 changes: 61 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 @@ -24,7 +24,7 @@
} from '#lib/compliance/labels.ts';
import type { PageProps } from './$types';

let { data }: PageProps = $props();
let { data, form }: PageProps = $props();
let p = $derived(data.program);
const initialTab = () => data.tab;
let tab = $state(initialTab());
Expand Down Expand Up @@ -651,6 +651,66 @@
{/if}
</Card>
{:else if value === 'details'}
<Card
title="Auditor access"
description="A read-only link for an auditor: the frameworks, Statement of Applicability, controls and current evidence. It ends on its date, and every view is recorded."
>
{#if form && 'auditUrl' in form && form.auditUrl}
<p
class="mb-3 rounded-control bg-surface-sunken p-3 font-mono text-xs break-all text-fg"
aria-label="New audit link"
>
{form.auditUrl}
</p>
{/if}
{#if data.auditLinks.length > 0}
<ul class="mb-3 divide-y divide-border" aria-label="Audit links">
{#each data.auditLinks as l (l.id)}
<li class="flex flex-wrap items-center gap-3 py-2 text-sm">
<span class="flex-1 text-fg">{l.label}</span>
<span class="text-xs text-fg-subtle">
until {new Date(l.expiresAt).toLocaleDateString()} · {l.views} view{l.views ===
1
? ''
: 's'}
</span>
{#if l.active}
{#if data.canAssess}
<form method="POST" action="?/revokeAuditLink" use:enhance={toasted()}>
<input type="hidden" name="linkId" value={l.id} />
<Button size="sm" variant="ghost" type="submit">Turn off</Button>
</form>
{/if}
{:else}
<Badge>Ended</Badge>
{/if}
</li>
{/each}
</ul>
{/if}
{#if data.canAssess}
<form
method="POST"
action="?/createAuditLink"
class="flex flex-wrap items-end gap-2"
use:enhance={toasted()}
>
<Field label="For" for="audit-label">
<Input
id="audit-label"
name="label"
required
maxlength={200}
placeholder="Audit firm"
/>
</Field>
<Field label="Days" for="audit-days">
<Input id="audit-days" name="days" type="number" min="1" max="90" value="14" />
</Field>
<Button type="submit">Make a link</Button>
</form>
{/if}
</Card>
<Card title="Details">
<form
method="POST"
Expand Down
13 changes: 13 additions & 0 deletions apps/web/src/routes/audit/[token]/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { error } from '@sveltejs/kit';
import { api } from '#lib/server/api.ts';
import type { PageServerLoad } from './$types';

/** A compliance program opened through an auditor's link: no sign-in. */
export const load: PageServerLoad = async (event) => {
const { data, response } = await api(event).GET('/public/audit/{token}', {
params: { path: { token: event.params.token } }
});
if (response.status === 429) error(429, 'Too many requests. Wait a minute and try again.');
if (!data) error(404, 'This link doesn’t work. It may have expired or been turned off.');
return { view: data, token: event.params.token };
};
157 changes: 157 additions & 0 deletions apps/web/src/routes/audit/[token]/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<script lang="ts">
import { Badge, Card } from '@usehuxley/ui';
import type { PageProps } from './$types';

let { data }: PageProps = $props();
let v = $derived(data.view);
const STATUS: Record<string, string> = {
met: 'Met',
partial: 'Partly met',
not_met: 'Not met',
gap: 'No control',
not_applicable: 'Not applicable'
};
const IMPL: Record<string, string> = {
not_started: 'Not started',
planned: 'Planned',
partial: 'Partly in place',
implemented: 'Implemented',
not_applicable: 'Not applicable'
};
const WHO: Record<string, string> = {
msp: 'MSP',
client: 'Client',
shared: 'Shared',
third_party: 'Third party'
};
const tone = (s: string | null | undefined) =>
s === 'met'
? 'success'
: s === 'partial'
? 'warning'
: s === 'not_met' || s === 'gap'
? 'danger'
: 'neutral';
</script>

<svelte:head>
<title>{v.programName} · Audit view</title>
<meta name="robots" content="noindex" />
</svelte:head>

<main class="mx-auto flex max-w-5xl flex-col gap-5 px-4 py-8">
<div>
<p class="text-sm text-fg-subtle">Read-only audit view for {v.label}</p>
<h1 class="text-[26px] leading-tight font-extrabold tracking-tight text-fg">{v.programName}</h1>
<p class="mt-1 text-sm text-fg-muted">
{v.orgName} · this link works until {new Date(v.expiresAt).toLocaleDateString()}
</p>
{#if v.scope}<p class="mt-2 text-sm text-fg">{v.scope}</p>{/if}
</div>

{#each v.frameworks as f (f.versionId)}
<Card
title="{f.frameworkName} {f.version}"
description="{f.posture.score}% · {f.posture.met} met, {f.posture.partial} partly, of {f
.posture.applicable} that apply"
>
<div class="overflow-x-auto">
<table
class="w-full text-left text-sm"
aria-label="Statement of Applicability: {f.frameworkName}"
>
<thead class="text-xs text-fg-muted">
<tr>
<th class="py-2 pr-3 font-medium">Requirement</th>
<th class="py-2 pr-3 font-medium">Applies</th>
<th class="py-2 pr-3 font-medium">Status</th>
<th class="py-2 font-medium">Controls</th>
</tr>
</thead>
<tbody class="divide-y divide-border">
{#each f.requirements as r (r.ref)}
<tr>
<td class="py-2 pr-3">
<span class="font-mono font-semibold text-fg">{r.ref}</span>
<span class="text-fg">{r.title ?? r.statement ?? ''}</span>
</td>
<td class="py-2 pr-3 text-fg-muted">
{r.applicable ? 'Yes' : `No${r.justification ? `: ${r.justification}` : ''}`}
</td>
<td class="py-2 pr-3">
<Badge tone={tone(r.status)}>{STATUS[r.status ?? ''] ?? '—'}</Badge>
</td>
<td class="py-2 font-mono text-xs text-fg-muted">{r.controls.join(', ')}</td>
</tr>
{/each}
</tbody>
</table>
</div>
</Card>
{/each}

<Card title="Controls and evidence">
<ul class="divide-y divide-border" aria-label="Controls">
{#each v.controls as c (c.id)}
<li class="py-3">
<div class="flex flex-wrap items-center gap-2">
<span class="flex-1 text-sm font-medium text-fg">
<span class="font-mono">{c.ref}</span>
{c.name}
</span>
<Badge>{WHO[c.responsibility]}{c.thirdParty ? `: ${c.thirdParty}` : ''}</Badge>
<Badge tone={c.status === 'implemented' ? 'success' : 'warning'}>
{IMPL[c.status]}
</Badge>
</div>
{#if c.description}<p class="text-sm text-fg-muted">{c.description}</p>{/if}
{#if c.notes}<p class="text-sm text-fg-muted">How: {c.notes}</p>{/if}
{#if c.evidence.length > 0}
<ul class="mt-2 flex flex-col gap-1 text-sm" aria-label="Evidence for {c.ref}">
{#each c.evidence as e (e.id)}
<li>
{#if e.kind === 'file'}
<!-- eslint-disable svelte/no-navigation-without-resolve -->
<a
href="/audit/{data.token}/evidence/{e.id}"
class="text-accent hover:underline"
>
{e.title}
</a>
<!-- eslint-enable svelte/no-navigation-without-resolve -->
{:else if e.kind === 'link' && e.url}
<!-- eslint-disable svelte/no-navigation-without-resolve -->
<a
href={e.url}
class="text-accent hover:underline"
rel="noreferrer noopener"
target="_blank"
>
{e.title}
</a>
<!-- eslint-enable svelte/no-navigation-without-resolve -->
{:else}
<span class="text-fg">{e.title}</span>
{/if}
{#if e.passed !== null && e.passed !== undefined}
<Badge tone={e.passed ? 'success' : 'danger'}>
{e.passed ? 'Passed' : 'Failed'}
</Badge>
{/if}
<span class="text-xs text-fg-subtle">
{new Date(e.collectedAt).toLocaleDateString()}{#if e.validUntil}
· valid until {e.validUntil}{/if}
</span>
{#if e.body}<p class="text-xs whitespace-pre-line text-fg-muted">{e.body}</p>{/if}
</li>
{/each}
</ul>
{:else}
<p class="mt-1 text-xs text-fg-subtle">No current evidence.</p>
{/if}
</li>
{/each}
</ul>
</Card>
<p class="text-xs text-fg-subtle">Every view of this page is recorded.</p>
</main>
21 changes: 21 additions & 0 deletions apps/web/src/routes/audit/[token]/evidence/[id]/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { RequestHandler } from '@sveltejs/kit';
import { apiHeaders, apiUrl } from '#lib/server/api.ts';

/** An evidence file, through an auditor's link. */
export const GET: RequestHandler = async (event) => {
const token = encodeURIComponent(event.params.token ?? '');
const id = encodeURIComponent(event.params.id ?? '');
const upstream = await fetch(`${apiUrl}/public/audit/${token}/evidence/${id}`, {
headers: apiHeaders(event),
signal: event.request.signal
}).catch(() => null);
if (!upstream?.ok || !upstream.body) {
return new Response('Not available.', { 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 });
};
Loading