Create inactivity api middleware
This commit is contained in:
parent
769c47c4c7
commit
c6c129715d
29
functions/api/inactivity/_middleware.ts
Normal file
29
functions/api/inactivity/_middleware.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
function makeResponse(body: string, status: number): Response {
|
||||||
|
return new Response(body, {
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
status,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function onRequest(context: RequestContext) {
|
||||||
|
if (!context.data.current_user)
|
||||||
|
return makeResponse('{"error":"You are not logged in"}', 401);
|
||||||
|
|
||||||
|
const { permissions } = context.data.current_user;
|
||||||
|
const departments = {
|
||||||
|
DM: 1 << 2,
|
||||||
|
ET: 1 << 3,
|
||||||
|
FM: 1 << 10,
|
||||||
|
WM: 1 << 9,
|
||||||
|
};
|
||||||
|
const userDepartments = [];
|
||||||
|
|
||||||
|
for (const [dept, permission] of Object.entries(departments))
|
||||||
|
if (permissions & permission) userDepartments.push(dept);
|
||||||
|
|
||||||
|
context.data.departments = userDepartments;
|
||||||
|
|
||||||
|
return await context.next();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user