feat: ReqACL
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import type { SessionCtx } from "@sammo/server_util";
|
||||
import type { ProcDecorator } from "@strpc/express/proc_decorator";
|
||||
import type { ServerActionType } from "@sammo/gateway_server/exports"
|
||||
import { loginCtxSessionKey } from "./ReqLogin.js";
|
||||
|
||||
export type LoginCtx = {
|
||||
userID: number;
|
||||
userName: string;
|
||||
userLevel: number;
|
||||
allowServerAction?: Set<ServerActionType>;
|
||||
loginDate: Date;
|
||||
}
|
||||
|
||||
export function ReqACL<Q extends LoginCtx & SessionCtx>(action: ServerActionType): ProcDecorator<Q, Q> {
|
||||
return (ctx) => {
|
||||
if(ctx.allowServerAction?.has(action)){
|
||||
return [{
|
||||
result: true,
|
||||
}, ctx];
|
||||
}
|
||||
|
||||
return [{
|
||||
result: false,
|
||||
type: 'Required ACL',
|
||||
info: `NotEnoughPermission: ${action}`
|
||||
}, ctx];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user