Skip to content

Commit

Permalink
Remove UserTasks for deleted author
Browse files Browse the repository at this point in the history
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?
  • Loading branch information
FyreByrd committed Oct 18, 2024
1 parent 0f1fb9b commit 95bb408
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 };
},
Expand Down

0 comments on commit 95bb408

Please sign in to comment.