31 lines
810 B
TypeScript
31 lines
810 B
TypeScript
export const rolePermissions: Record<string, string[]> =
|
|
{
|
|
superadmin: [ 'manage-users', 'manage-roles', 'manage-products', 'access-all' ],
|
|
admin: [ 'manage-users', 'manage-products', 'access-all' ],
|
|
user: [ 'access-own' ]
|
|
};
|
|
|
|
export function permissionsForRoles( roles: string[] ): string[]
|
|
{
|
|
const perms = new Set<string>();
|
|
for ( const role of roles )
|
|
for ( const p of rolePermissions[ role ] ?? [] )
|
|
perms.add( p );
|
|
return [ ...perms ];
|
|
}
|
|
|
|
export function hasRole( roles: string[], role: string ): boolean
|
|
{
|
|
return roles.includes( role );
|
|
}
|
|
|
|
export function isAdmin( roles: string[] ): boolean
|
|
{
|
|
return roles.includes( 'admin' ) || roles.includes( 'superadmin' );
|
|
}
|
|
|
|
export function isSuperAdmin( roles: string[] ): boolean
|
|
{
|
|
return roles.includes( 'superadmin' );
|
|
}
|