19 lines
666 B
TypeScript
19 lines
666 B
TypeScript
export const canRead = (roles: string[] | undefined, resource: string): boolean => {
|
|
if (!roles || roles.length === 0) return false;
|
|
return (
|
|
roles.includes("admin") ||
|
|
roles.includes(`${resource}_ro`) ||
|
|
roles.includes(`${resource}_rw`)
|
|
);
|
|
};
|
|
|
|
export const canWrite = (roles: string[] | undefined, resource: string): boolean => {
|
|
if (!roles || roles.length === 0) return false;
|
|
return roles.includes("admin") || roles.includes(`${resource}_rw`);
|
|
};
|
|
|
|
export const createPermissions = (roles: string[] | undefined) => ({
|
|
canRead: (resource: string) => canRead(roles, resource),
|
|
canWrite: (resource: string) => canWrite(roles, resource),
|
|
});
|