Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/routes/(admin)/account_transfer/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import { Roles } from '$lib/types/user';

let accountTransferMessages: FloatingMessage[] = [];

/**
* Prepare data for the account transfer page by validating the current session, enforcing admin access, and constructing the transfer form.
*
* @param locals - SvelteKit locals providing `auth` for session validation and services used to fetch user data.
* @returns An object with `success: true`, `form`: the validated account transfer form with its `message` cleared, and `accountTransferMessages`: the module-level messages array related to account transfers.
* @throws Redirects to the login page when the session is missing or the authenticated user is not an admin.
*/
export async function load({ locals }) {
const session = await locals.auth.validate();

Expand Down Expand Up @@ -79,4 +86,4 @@ export const actions: Actions = {
};
}
},
};
};
6 changes: 5 additions & 1 deletion src/routes/workbooks/edit/[slug]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { workBookSchema } from '$lib/zod/schema';
import * as tasksCrud from '$lib/services/tasks';
import * as workBooksCrud from '$lib/services/workbooks';

/**
* Loads workbook and author data, initializes a validation form and task lookups, and enforces edit permissions for the current user.
*
* @returns An object containing the initialized `form` (prefilled with the workbook), `loggedInAsAdmin` flag, the workbook with author data, `tasks`, and `tasksMapByIds`. If a logged-in user exists but is not authorized to edit the workbook, the returned object includes `status: FORBIDDEN` and a `message` describing the access restriction. */
export async function load({ locals, params }) {
const loggedInUser = await getLoggedInUser(locals);
const loggedInAsAdmin = isAdmin(loggedInUser?.role as Roles);
Expand Down Expand Up @@ -97,4 +101,4 @@ export const actions = {

redirect(TEMPORARY_REDIRECT, '/workbooks');
},
};
};
Loading