04be659d6b
Add routes for modules, users, notes import, recap, and islands edit. Update middleware to filter pages based on user role. feat(admin): add modal for assigning teaching, replace delete icon with SVG refactor(server): rename port variable to uppercase and add env support feat(admin): add enseignants, users, filtering and role colors refactor(AdminRoles): improve role UI and add permission mapping feat(admin-users): add role colors, role filter, and modal for creating users feat(admin): add EditModule component for module editing feat(admin): add EditUser page for editing users and managing enseignements feat(promo-select): display id and name in options for promo dropdown feat: add edit module/user routes, inline coeff editing, UI tweaks refactor: UI – icons, modal overlay, grid, subtitles, import margin
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { FreshContext, MiddlewareHandler } from "$fresh/server.ts";
|
|
import {
|
|
AppProperties,
|
|
AuthenticatedState,
|
|
} from "$root/defaults/interfaces.ts";
|
|
|
|
export const handler: MiddlewareHandler<AuthenticatedState>[] = [
|
|
/**
|
|
* Get all available pages for current user.
|
|
* @param request The HTTP incomming request.
|
|
* @param context The Fresh context object with custom `AuthenticatedState`.
|
|
* @returns The response from the next middleware.
|
|
*/
|
|
async function getAllAvailablePages(
|
|
request: Request,
|
|
context: FreshContext<AuthenticatedState>,
|
|
): Promise<Response> {
|
|
const pathname = new URL(request.url).pathname;
|
|
const currentApp = pathname.split("/")[1];
|
|
const properties: AppProperties = (await import(
|
|
`./${currentApp}/(_props)/props.ts`
|
|
)).default;
|
|
|
|
context.state.availablePages = properties.pages;
|
|
const isStudent =
|
|
context.state.session.eduPersonPrimaryAffiliation == "student" &&
|
|
Deno.env.get("LOCAL") != "true";
|
|
|
|
if (isStudent) {
|
|
properties.adminOnly.forEach((page) =>
|
|
delete context.state.availablePages[page]
|
|
);
|
|
} else {
|
|
properties.studentOnly?.forEach((page) =>
|
|
delete context.state.availablePages[page]
|
|
);
|
|
}
|
|
|
|
return await context.next();
|
|
},
|
|
];
|