diff --git a/messages/en.json b/messages/en.json index e7eded4..365a921 100644 --- a/messages/en.json +++ b/messages/en.json @@ -18,10 +18,10 @@ "adminUserDeleted": "User {email} has been deleted", "adminUserDeleteDescription": "User {email} will be permanently deleted", "adminUserDeleteWarning": "Are you ABSOLUTELY sure? This action cannot be undone.", + "adminUserDisable": "Disable User", "adminUserDisabled": "User is disabled", "adminUserEdit": "Edit User", "adminUserEnabled": "User is enabled", - "adminUserToggle": "Enable / Disable User", "adminUserUpdated": "User updated", "cancel": "Cancel", "close": "Close", @@ -34,7 +34,8 @@ "errorCannotDeleteUser": "Unable to delete user", "errorCreatingRegistrationToken": "Error creating registration token", "errorDatabaseError": "A database error occurred", - "errorDeleteSelf": "Bro, you can't delete yourself", + "errorDeleteSelf": "You can't delete yourself", + "errorDisableSelf": "You can't disable yourself", "errorEmailExists": "Email already exists", "errorPasswordHashing": "Unable to produce reliable password hash", "errorPasswordRequired": "Password is required", diff --git a/src/routes/admin/+page.server.ts b/src/routes/admin/+page.server.ts index 90d7678..bc39877 100644 --- a/src/routes/admin/+page.server.ts +++ b/src/routes/admin/+page.server.ts @@ -140,11 +140,16 @@ export const actions: Actions = { if (!form.data.id) { return setError(form, '', m.errorUserIdRequired()); } + // you cannot disable yourself + if (event.locals.user.id === form.data.id && form.data.disabled) { + return setError(form, '', m.errorDisableSelf()); + } // update the user const updated: { id: number }[] = await db.update(users).set({ firstname: form.data.firstname, lastname: form.data.lastname, email: form.data.email, + disabled: form.data.disabled, }).where(eq(users.id, form.data.id)).returning({ id: users.id}); // make sure the user was updated if (updated.length === 0) { diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte index 241979b..4ea828c 100644 --- a/src/routes/admin/+page.svelte +++ b/src/routes/admin/+page.svelte @@ -33,6 +33,13 @@ let disableRegCloseButton = $state(true); let actuallyDeleteCheckBox = $state(false); let disableDeleteButton = $derived(!actuallyDeleteCheckBox); + let userDisableClass = $derived.by(() => { + if (dialogAction === "update") { + return "visible"; + } else { + return "invisible"; + } + }) let regToken = $state({ value: "", @@ -82,6 +89,7 @@ lastname: "", email: "", id: undefined, + disabled: false, }); } @@ -123,7 +131,7 @@ if ($message.token) { closeDialog(); openRegDialog($message.token); - clearRegToken(); + $message.token = undefined; clearCheckbox(); } } @@ -300,7 +308,16 @@ - + + + +
+ + {m.adminUserDisable()} +
+
+ +
{/if} diff --git a/src/routes/admin/schema.ts b/src/routes/admin/schema.ts index e23163a..41a2566 100644 --- a/src/routes/admin/schema.ts +++ b/src/routes/admin/schema.ts @@ -6,6 +6,7 @@ export const userFormSchema = z.object({ firstname: z.string().min(3).max(50), lastname: z.string().min(3).max(50), email: z.string().email(), + disabled: z.boolean().default(false).optional(), }); export type UserFormSchema = typeof userFormSchema; \ No newline at end of file