feat(rbac): added org permission context for pulling permission from api

This commit is contained in:
Akhil Mohan
2023-09-08 21:21:43 +05:30
parent e342e88499
commit 34fb7be1c4
11 changed files with 166 additions and 18 deletions
@@ -13,8 +13,10 @@ import {
CreateRoleSchema,
DeleteRoleSchema,
GetRoleSchema,
GetUserPermission,
UpdateRoleSchema
} from "../../validation";
import { packRules } from "@casl/ability/extra";
export const createRole = async (req: Request, res: Response) => {
const {
@@ -160,3 +162,16 @@ export const getRoles = async (req: Request, res: Response) => {
}
});
};
export const getUserPermissions = async (req: Request, res: Response) => {
const {
params: { orgId }
} = await validateRequest(GetUserPermission, req);
const { permission } = await getUserOrgPermissions(req.user.id, orgId);
res.status(200).json({
data: {
permissions: packRules(permission.rules)
}
});
};