feat(isac): add moderated contributor mode

This commit is contained in:
JB
2026-07-25 13:59:45 -04:00
parent d495cd585a
commit 32dbef822b
20 changed files with 353 additions and 36 deletions
+12 -2
View File
@@ -1,4 +1,4 @@
import type { Handle } from '@sveltejs/kit';
import { json, type Handle } from '@sveltejs/kit';
import { getSessionUser } from '$lib/server/auth/session';
import { DATA_MODULES, queueDataProposal, shouldModerateDataMutation, type DataModule } from '$lib/server/data-moderation';
@@ -11,10 +11,20 @@ export const handle: Handle = async ({ event, resolve }) => {
const user = await getSessionUser(event.cookies);
const access = await shouldModerateDataMutation(user);
if (!access.canManage && access.canPropose && user) {
if (!access.contributorEnabled) {
if (event.request.headers.get('accept')?.includes('application/json')) {
return json({ type: 'failure', status: 403, data: { contributorModeRequired: true } }, { status: 403 });
}
return new Response('Contributor mode must be enabled before submitting data changes.', { status: 403 });
}
const proposalId = await queueDataProposal(user, module, action, await event.request.formData());
const target = new URL(event.url.pathname, event.url);
target.searchParams.set('proposal', proposalId);
return new Response(null, { status: 303, headers: { location: `${target.pathname}${target.search}` } });
const location = `${target.pathname}${target.search}`;
if (event.request.headers.get('accept')?.includes('application/json')) {
return json({ type: 'redirect', status: 303, location });
}
return new Response(null, { status: 303, headers: { location } });
}
}
}