55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
|
|
export const PERMISSION_MAP = {
|
|
// Invoices
|
|
"invoices:read": "invoices:read",
|
|
"invoices:create": "invoices:create",
|
|
|
|
// Proforma
|
|
"proforma:read": "proforma:read",
|
|
"proforma:create": "proforma:create",
|
|
|
|
// Payments
|
|
"payments:read": "payments:read",
|
|
"payments:create": "payments:create",
|
|
|
|
// Users
|
|
"users:read": "users:read",
|
|
"users:create": "users:create",
|
|
|
|
// News
|
|
"news:read": "news:read",
|
|
|
|
// Company
|
|
"company:read": "company:read",
|
|
|
|
// Notifications
|
|
"notifications:read": "notifications:read",
|
|
|
|
// Profile
|
|
"profile:update": "profile:update",
|
|
|
|
// Scan
|
|
"scan:create": "scan:create",
|
|
} as const;
|
|
|
|
/**
|
|
* Utility function to check if user has a specific permission.
|
|
*/
|
|
export function hasPermission(userPermissions: string[], permission: string): boolean {
|
|
return userPermissions.includes(permission);
|
|
}
|
|
|
|
/**
|
|
* Utility function to check if user has any of the permissions.
|
|
*/
|
|
export function hasAnyPermission(userPermissions: string[], permissions: string[]): boolean {
|
|
return permissions.some(perm => userPermissions.includes(perm));
|
|
}
|
|
|
|
/**
|
|
* Utility function to check if user has all permissions.
|
|
*/
|
|
export function hasAllPermissions(userPermissions: string[], permissions: string[]): boolean {
|
|
return permissions.every(perm => userPermissions.includes(perm));
|
|
}
|