feat(isac): add moderated data contributions
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import type { Handle } from '@sveltejs/kit';
|
||||
import { getSessionUser } from '$lib/server/auth/session';
|
||||
import { DATA_MODULES, queueDataProposal, shouldModerateDataMutation, type DataModule } from '$lib/server/data-moderation';
|
||||
|
||||
export const handle: Handle = async ({ event, resolve }) => {
|
||||
if (event.request.method === 'POST') {
|
||||
const match = event.url.pathname.match(/^\/admin\/([^/]+)$/);
|
||||
const module = match?.[1] as DataModule | undefined;
|
||||
const action = event.url.search.startsWith('?/') ? event.url.search.slice(2) : '';
|
||||
if (module && DATA_MODULES.includes(module) && action) {
|
||||
const user = await getSessionUser(event.cookies);
|
||||
const access = await shouldModerateDataMutation(user);
|
||||
if (!access.canManage && access.canPropose && user) {
|
||||
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}` } });
|
||||
}
|
||||
}
|
||||
}
|
||||
return resolve(event);
|
||||
};
|
||||
Reference in New Issue
Block a user