You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
557 B
TypeScript
19 lines
557 B
TypeScript
import { BaseContext } from "koa";
|
|
import { ActionName, Collection } from "sealious";
|
|
|
|
export function peopleWhoCan(action: ActionName, collection: Collection) {
|
|
return async function (ctx: BaseContext) {
|
|
const policy = collection.getPolicy(action);
|
|
const result = await policy.check(ctx.$context);
|
|
if (!result) {
|
|
ctx.status = 403;
|
|
return { canAccess: false, message: "Not allowed" };
|
|
}
|
|
if (!result.allowed) {
|
|
ctx.status = 403;
|
|
return { canAccess: false, message: result.reason };
|
|
}
|
|
return { canAccess: true, message: "" };
|
|
};
|
|
}
|