36 lines
854 B
TypeScript
36 lines
854 B
TypeScript
import { CommunityRole } from '../global/database/schema';
|
|
|
|
export type Permission =
|
|
| 'community:edit'
|
|
| 'community:delete'
|
|
| 'community:transfer'
|
|
| 'user:role:manage'
|
|
| 'match:create'
|
|
| 'match:edit'
|
|
| 'match:delete'
|
|
| 'auction:manage';
|
|
|
|
type PermissionSet = readonly Permission[] | readonly ['*'];
|
|
|
|
export const ROLE_PERMISSIONS: Record<CommunityRole, PermissionSet> = {
|
|
owner: ['*'] as const,
|
|
admin: [
|
|
'community:edit',
|
|
'user:role:manage',
|
|
'match:create',
|
|
'match:edit',
|
|
'match:delete',
|
|
'auction:manage',
|
|
] as const,
|
|
member: [] as const,
|
|
};
|
|
|
|
export function roleHasPermission(
|
|
role: CommunityRole,
|
|
permission: Permission,
|
|
): boolean {
|
|
const perms = ROLE_PERMISSIONS[role];
|
|
if (perms.length === 1 && perms[0] === '*') return true;
|
|
return (perms as readonly Permission[]).includes(permission);
|
|
}
|