From 1baa9771560df864132922e7ec9e2855860f7860 Mon Sep 17 00:00:00 2001 From: Aidan Jones Date: Tue, 15 Oct 2024 10:56:32 -0400 Subject: [PATCH] Remove UserTasks for deleted author Will this result in the desired behavior if a user has multiple roles? What if, for some unfathomable reason, a user is both a project owner and an Author on the same project? As of right now, all tasks for that user in that project will be deleted, regardless of role. Should a user be prevented from having more than one role for a project? --- .../projects/[id=idNumber]/+page.server.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/source/SIL.AppBuilder.Portal/src/routes/(authenticated)/projects/[id=idNumber]/+page.server.ts b/source/SIL.AppBuilder.Portal/src/routes/(authenticated)/projects/[id=idNumber]/+page.server.ts index f54a72c58..85cdb6778 100644 --- a/source/SIL.AppBuilder.Portal/src/routes/(authenticated)/projects/[id=idNumber]/+page.server.ts +++ b/source/SIL.AppBuilder.Portal/src/routes/(authenticated)/projects/[id=idNumber]/+page.server.ts @@ -1,6 +1,6 @@ import { idSchema } from '$lib/valibot'; import { error } from '@sveltejs/kit'; -import { DatabaseWrites, prisma } from 'sil.appbuilder.portal.common'; +import { BullMQ, DatabaseWrites, prisma, queues } from 'sil.appbuilder.portal.common'; import { RoleId, WorkflowType } from 'sil.appbuilder.portal.common/prisma'; import { fail, superValidate } from 'sveltekit-superforms'; import { valibot } from 'sveltekit-superforms/adapters'; @@ -255,7 +255,20 @@ export const actions = { return fail(403); const form = await superValidate(event.request, valibot(deleteAuthorSchema)); if (!form.valid) return fail(400, { form, ok: false }); - // TODO: Update user tasks... + // TODO: Will this result in the desired behavior if a user has multiple roles? + // What if, for some unfathomable reason, a user is both a project owner + // and an Author on the same project? As of right now, all tasks for that user + // in that project will be deleted, regardless of role. Should a user be prevented from having more than one role for a project? + await queues.scriptoria.add(`Remove UserTasks for Author #${form.data.id}`, { + type: BullMQ.ScriptoriaJobType.UserTasks_Modify, + scope: 'Project', + projectId: parseInt(event.params.id), + operation: { + type: BullMQ.UserTasks.OpType.Delete, + by: 'UserId', + users: [form.data.id] + } + }); await DatabaseWrites.authors.delete({ where: { Id: form.data.id } }); return { form, ok: true }; },