mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 07:27:58 +00:00
feat(rbac): added org permission context for pulling permission from api
This commit is contained in:
@@ -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)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -17,4 +17,11 @@ router.delete(
|
||||
|
||||
router.get("/", requireAuth({ acceptedAuthModes: [AuthMode.JWT] }), roleController.getRoles);
|
||||
|
||||
// get a user permissions in an org
|
||||
router.get(
|
||||
"/:orgId/permissions",
|
||||
requireAuth({ acceptedAuthModes: [AuthMode.JWT] }),
|
||||
roleController.getUserPermissions
|
||||
);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -40,13 +40,19 @@ export const UpdateRoleSchema = z.object({
|
||||
|
||||
export const DeleteRoleSchema = z.object({
|
||||
params: z.object({
|
||||
id: z.string()
|
||||
id: z.string().trim()
|
||||
})
|
||||
});
|
||||
|
||||
export const GetRoleSchema = z.object({
|
||||
query: z.object({
|
||||
workspaceId: z.string().optional(),
|
||||
orgId: z.string()
|
||||
workspaceId: z.string().trim().optional(),
|
||||
orgId: z.string().trim()
|
||||
})
|
||||
});
|
||||
|
||||
export const GetUserPermission = z.object({
|
||||
params: z.object({
|
||||
orgId: z.string().trim()
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user