21 lines
507 B
TypeScript
21 lines
507 B
TypeScript
import {
|
|||
|
|
ASSIGN_SECTION_PERMISSION,
|
||
|
|
type AssignSection,
|
||
|
|
type RolePermissionKey,
|
||
|
|
} from '@mento/shared';
|
||
|
|
|
||
|
|
export function canAssignToOthers(
|
||
|
|
user:
|
||
|
|
| {
|
||
|
|
role?: string | null;
|
||
|
|
permissions?: Array<RolePermissionKey | string> | null;
|
||
|
|
}
|
||
|
|
| null
|
||
|
|
| undefined,
|
||
|
|
section: AssignSection,
|
||
|
|
): boolean {
|
||
|
|
if (!user) return false;
|
||
|
|
if (user.role === 'owner' || user.role === 'admin') return true;
|
||
|
|
return (user.permissions ?? []).includes(ASSIGN_SECTION_PERMISSION[section]);
|
||
|
|
}
|