Compare commits

..

4 Commits

Author SHA1 Message Date
djalim 49bcc3083a fix: faculty users are now recognized as employees
Check Deno code / Check Deno code (push) Has been cancelled
Tests / Unit tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
2026-05-05 15:29:02 +02:00
djalim 0f87bc18c3 refactor(fresh.config): change server port to 80 and remove cert/key
Check Deno code / Check Deno code (push) Has been cancelled
Tests / Unit tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Check Deno code / Check Deno code (pull_request) Has been cancelled
Tests / Unit tests (pull_request) Has been cancelled
Tests / Integration tests (pull_request) Has been cancelled
2026-05-05 12:51:38 +00:00
djalim e719e5129f feat: added logs
Check Deno code / Check Deno code (pull_request) Has been cancelled
Tests / Unit tests (pull_request) Has been cancelled
Tests / Integration tests (pull_request) Has been cancelled
Check Deno code / Check Deno code (push) Has been cancelled
Tests / Unit tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
2026-05-05 14:50:17 +02:00
djalim 951c9c1fea test : changed test format + added playwright support
Check Deno code / Check Deno code (pull_request) Has been cancelled
Tests / Unit tests (pull_request) Has been cancelled
Tests / Integration tests (pull_request) Has been cancelled
Check Deno code / Check Deno code (push) Has been cancelled
Tests / Unit tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
2026-05-03 21:52:02 +02:00
19 changed files with 62 additions and 58 deletions
+5
View File
@@ -63,6 +63,11 @@ export interface LoginJWT {
user: CasContent; user: CasContent;
} }
export function isEmployee(session: CasContent): boolean {
return session.eduPersonPrimaryAffiliation === "employee" ||
session.eduPersonPrimaryAffiliation === "faculty";
}
export type EmptyObject = Record<string | number | symbol, never>; export type EmptyObject = Record<string | number | symbol, never>;
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
+3 -3
View File
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { enseignements } from "$root/databases/schema.ts"; import { enseignements } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { and, eq } from "npm:drizzle-orm@0.45.2"; import { and, eq } from "npm:drizzle-orm@0.45.2";
const _NOT_FOUND = () => const _NOT_FOUND = () =>
@@ -24,7 +24,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return new Response(JSON.stringify([]), { return new Response(JSON.stringify([]), {
headers: { "content-type": "application/json" }, headers: { "content-type": "application/json" },
}); });
@@ -40,7 +40,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { enseignements } from "$root/databases/schema.ts"; import { enseignements } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { and, eq } from "npm:drizzle-orm@0.45.2"; import { and, eq } from "npm:drizzle-orm@0.45.2";
const NOT_FOUND = () => const NOT_FOUND = () =>
@@ -18,7 +18,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -50,7 +50,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
+2 -2
View File
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { modules } from "$root/databases/schema.ts"; import { modules } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { eq } from "npm:drizzle-orm@0.45.2"; import { eq } from "npm:drizzle-orm@0.45.2";
export const handler: Handlers<null, AuthenticatedState> = { export const handler: Handlers<null, AuthenticatedState> = {
@@ -21,7 +21,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return new Response(null, { status: 403 }); return new Response(null, { status: 403 });
} }
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { ueModules } from "$root/databases/schema.ts"; import { ueModules } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { and, eq } from "npm:drizzle-orm@0.45.2"; import { and, eq } from "npm:drizzle-orm@0.45.2";
const NOT_FOUND = () => const NOT_FOUND = () =>
@@ -24,7 +24,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -58,7 +58,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -111,7 +111,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
+3 -4
View File
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { mobilites } from "$root/databases/schema.ts"; import { mobilites } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { eq } from "npm:drizzle-orm@0.45.2"; import { eq } from "npm:drizzle-orm@0.45.2";
const VALID_STATUSES = [ const VALID_STATUSES = [
@@ -46,15 +46,14 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
const isEmployee = const employeeCheck = isEmployee(context.state.session);
context.state.session.eduPersonPrimaryAffiliation === "employee";
try { try {
const body = await request.json(); const body = await request.json();
const { numEtud, duree, ecole, pays, status, idStage } = body; const { numEtud, duree, ecole, pays, status, idStage } = body;
// Students can only create mobilites for themselves // Students can only create mobilites for themselves
if (!isEmployee && numEtud !== undefined) { if (!employeeCheck && numEtud !== undefined) {
// Students cannot set idStage or status // Students cannot set idStage or status
if (idStage || (status && status !== "contracts_received")) { if (idStage || (status && status !== "contracts_received")) {
return new Response(null, { status: 403 }); return new Response(null, { status: 403 });
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { mobilites } from "$root/databases/schema.ts"; import { mobilites } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { eq } from "npm:drizzle-orm@0.45.2"; import { eq } from "npm:drizzle-orm@0.45.2";
const VALID_STATUSES = [ const VALID_STATUSES = [
@@ -49,7 +49,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -115,7 +115,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { mobilites } from "$root/databases/schema.ts"; import { mobilites } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { eq } from "npm:drizzle-orm@0.45.2"; import { eq } from "npm:drizzle-orm@0.45.2";
const CONTRACTS_DIR = "uploads/contracts"; const CONTRACTS_DIR = "uploads/contracts";
@@ -118,7 +118,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return new Response(null, { status: 403 }); return new Response(null, { status: 403 });
} }
+2 -2
View File
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { ajustements } from "$root/databases/schema.ts"; import { ajustements } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { eq } from "npm:drizzle-orm@0.45.2"; import { eq } from "npm:drizzle-orm@0.45.2";
export const handler: Handlers<null, AuthenticatedState> = { export const handler: Handlers<null, AuthenticatedState> = {
@@ -47,7 +47,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return new Response(null, { status: 403 }); return new Response(null, { status: 403 });
} }
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { ajustements } from "$root/databases/schema.ts"; import { ajustements } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { and, eq } from "npm:drizzle-orm@0.45.2"; import { and, eq } from "npm:drizzle-orm@0.45.2";
const NOT_FOUND = () => const NOT_FOUND = () =>
@@ -18,7 +18,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -47,7 +47,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -100,7 +100,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
+5 -5
View File
@@ -3,16 +3,16 @@ import {
makePartials, makePartials,
} from "$root/defaults/makePartials.tsx"; } from "$root/defaults/makePartials.tsx";
import { FreshContext } from "$fresh/server.ts"; import { FreshContext } from "$fresh/server.ts";
import { State } from "$root/defaults/interfaces.ts"; import { isEmployee, State } from "$root/defaults/interfaces.ts";
// deno-lint-ignore require-await // deno-lint-ignore require-await
export async function Index( export async function Index(
_request: Request, _request: Request,
context: FreshContext<State>, context: FreshContext<State>,
) { ) {
const isEmployee = const employeeCheck = isEmployee(
(context.state as unknown as { session: Record<string, string> }).session (context.state as unknown as { session: Record<string, string> }).session,
.eduPersonPrimaryAffiliation === "employee"; );
return ( return (
<div class="page-content"> <div class="page-content">
@@ -25,7 +25,7 @@ export async function Index(
</strong> </strong>
. .
</p> </p>
{isEmployee {employeeCheck
? ( ? (
<p> <p>
Consultez les{" "} Consultez les{" "}
+2 -2
View File
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { stages } from "$root/databases/schema.ts"; import { stages } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { eq } from "npm:drizzle-orm@0.45.2"; import { eq } from "npm:drizzle-orm@0.45.2";
export const handler: Handlers<null, AuthenticatedState> = { export const handler: Handlers<null, AuthenticatedState> = {
@@ -38,7 +38,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return new Response(null, { status: 403 }); return new Response(null, { status: 403 });
} }
+3 -3
View File
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { mobilites, stages } from "$root/databases/schema.ts"; import { mobilites, stages } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { eq } from "npm:drizzle-orm@0.45.2"; import { eq } from "npm:drizzle-orm@0.45.2";
const NOT_FOUND = () => const NOT_FOUND = () =>
@@ -41,7 +41,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -98,7 +98,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
+3 -3
View File
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { promotions } from "$root/databases/schema.ts"; import { promotions } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
export const handler: Handlers<null, AuthenticatedState> = { export const handler: Handlers<null, AuthenticatedState> = {
// #13 GET /promotions // #13 GET /promotions
@@ -9,7 +9,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return new Response(JSON.stringify([]), { return new Response(JSON.stringify([]), {
headers: { "content-type": "application/json" }, headers: { "content-type": "application/json" },
}); });
@@ -26,7 +26,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return new Response(null, { status: 403 }); return new Response(null, { status: 403 });
} }
@@ -10,7 +10,7 @@ import {
ueModules, ueModules,
ues, ues,
} from "$root/databases/schema.ts"; } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { eq } from "npm:drizzle-orm@0.45.2"; import { eq } from "npm:drizzle-orm@0.45.2";
const NOT_FOUND = () => const NOT_FOUND = () =>
@@ -27,7 +27,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -49,7 +49,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -76,7 +76,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
+3 -3
View File
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { students } from "$root/databases/schema.ts"; import { students } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { eq } from "npm:drizzle-orm@0.45.2"; import { eq } from "npm:drizzle-orm@0.45.2";
export const handler: Handlers<null, AuthenticatedState> = { export const handler: Handlers<null, AuthenticatedState> = {
@@ -10,7 +10,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return new Response(JSON.stringify([]), { return new Response(JSON.stringify([]), {
headers: { "content-type": "application/json" }, headers: { "content-type": "application/json" },
}); });
@@ -33,7 +33,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return new Response(null, { status: 403 }); return new Response(null, { status: 403 });
} }
@@ -7,7 +7,7 @@ import {
stages, stages,
students, students,
} from "$root/databases/schema.ts"; } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
import { eq } from "npm:drizzle-orm@0.45.2"; import { eq } from "npm:drizzle-orm@0.45.2";
const NOT_FOUND = () => const NOT_FOUND = () =>
@@ -24,7 +24,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -47,7 +47,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -86,7 +86,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
_request: Request, _request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return FORBIDDEN(); return FORBIDDEN();
} }
@@ -1,7 +1,7 @@
import { FreshContext, Handlers } from "$fresh/server.ts"; import { FreshContext, Handlers } from "$fresh/server.ts";
import { db } from "$root/databases/db.ts"; import { db } from "$root/databases/db.ts";
import { students } from "$root/databases/schema.ts"; import { students } from "$root/databases/schema.ts";
import { AuthenticatedState } from "$root/defaults/interfaces.ts"; import { AuthenticatedState, isEmployee } from "$root/defaults/interfaces.ts";
// #9 POST /students/import-csv // #9 POST /students/import-csv
export const handler: Handlers<null, AuthenticatedState> = { export const handler: Handlers<null, AuthenticatedState> = {
@@ -9,7 +9,7 @@ export const handler: Handlers<null, AuthenticatedState> = {
request: Request, request: Request,
context: FreshContext<AuthenticatedState>, context: FreshContext<AuthenticatedState>,
): Promise<Response> { ): Promise<Response> {
if (context.state.session.eduPersonPrimaryAffiliation !== "employee") { if (!isEmployee(context.state.session)) {
return new Response(null, { status: 403 }); return new Response(null, { status: 403 });
} }
+5 -5
View File
@@ -3,16 +3,16 @@ import {
makePartials, makePartials,
} from "$root/defaults/makePartials.tsx"; } from "$root/defaults/makePartials.tsx";
import { FreshContext } from "$fresh/server.ts"; import { FreshContext } from "$fresh/server.ts";
import { State } from "$root/defaults/interfaces.ts"; import { isEmployee, State } from "$root/defaults/interfaces.ts";
// deno-lint-ignore require-await // deno-lint-ignore require-await
export async function Index( export async function Index(
_request: Request, _request: Request,
context: FreshContext<State>, context: FreshContext<State>,
) { ) {
const isEmployee = const employeeStatus = isEmployee(
(context.state as unknown as { session: Record<string, string> }).session (context.state as unknown as { session: Record<string, string> }).session,
.eduPersonPrimaryAffiliation === "employee"; );
return ( return (
<div class="page-content"> <div class="page-content">
@@ -25,7 +25,7 @@ export async function Index(
</strong> </strong>
. .
</p> </p>
{isEmployee && ( {employeeStatus && (
<p> <p>
Consultez la{" "} Consultez la{" "}
<a href="/students/consult" f-partial="/students/partials/consult"> <a href="/students/consult" f-partial="/students/partials/consult">