feat: ACL 관련 정리

This commit is contained in:
2024-03-09 15:07:10 +00:00
parent 5928655bc1
commit 99238636e6
4 changed files with 103 additions and 11 deletions
+26 -9
View File
@@ -11,18 +11,35 @@ export type LoginCtx = {
loginDate: Date;
}
export function ReqACL<Q extends LoginCtx & SessionCtx>(action: ServerActionType): ProcDecorator<Q, Q> {
return (ctx) => {
if(ctx.allowServerAction?.has(action)){
export function ReqACL<Q extends LoginCtx & SessionCtx>(...actions: ServerActionType[]): ()=>ProcDecorator<Q, Q> {
return () => {
return (ctx) => {
if (actions.length === 0) {
return [{
result: true,
}, ctx];
}
if(!ctx.allowServerAction){
return [{
result: false,
type: 'Required ACL',
info: 'No Server ACL in session context.'
}, ctx];
}
for (const action of actions) {
if (!ctx.allowServerAction.has(action)) {
return [{
result: false,
type: 'Required ACL',
info: `NotEnoughPermission: ${action}`
}, ctx];
}
}
return [{
result: true,
}, ctx];
}
return [{
result: false,
type: 'Required ACL',
info: `NotEnoughPermission: ${action}`
}, ctx];
}
}