|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
import type { RolePermissions } from './rolePermissions' |
|
|
|
|
import type { Permission } from './rolePermissions' |
|
|
|
|
import rolePermissions from './rolePermissions' |
|
|
|
|
import { useState } from '#app' |
|
|
|
|
import { USER_PROJECT_ROLES } from '~/lib/constants' |
|
|
|
@ -7,7 +7,7 @@ export function useUIPermission() {
|
|
|
|
|
const { $state } = useNuxtApp() |
|
|
|
|
const projectRoles = useState<Record<string, boolean>>(USER_PROJECT_ROLES, () => ({})) |
|
|
|
|
|
|
|
|
|
const isUIAllowed = (permission: RolePermissions, _skipPreviewAs = false) => { |
|
|
|
|
const isUIAllowed = (permission: Permission, _skipPreviewAs = false) => { |
|
|
|
|
const user = $state.user |
|
|
|
|
let userRoles = user?.value?.roles || {} |
|
|
|
|
|
|
|
|
@ -32,14 +32,13 @@ export function useUIPermission() {
|
|
|
|
|
// };
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
return Object.entries(roles).some(([role, hasRole]) => { |
|
|
|
|
const rolePermission = rolePermissions[role as keyof typeof rolePermissions] |
|
|
|
|
return Object.entries<boolean>(roles).some(([role, hasRole]) => { |
|
|
|
|
const rolePermission = rolePermissions[role as keyof typeof rolePermissions] as Permission |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
hasRole && |
|
|
|
|
(rolePermission === '*' || typeof rolePermission === 'object' |
|
|
|
|
? rolePermission[permission as keyof typeof rolePermission] === true |
|
|
|
|
: false) |
|
|
|
|
(rolePermission === '*' || |
|
|
|
|
(typeof rolePermission === 'object' && rolePermission[permission as keyof typeof rolePermission])) |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|