|
|
@ -29,24 +29,26 @@ export function useUIPermission() { |
|
|
|
}), |
|
|
|
}), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const isUIAllowed = (permission: Permission | string, skipPreviewAs = false) => { |
|
|
|
const hasPermission = (role: Role | ProjectRole, hasRole: boolean, permission: Permission | string) => { |
|
|
|
let roles = { ...allRoles.value } |
|
|
|
const rolePermission = rolePermissions[role] |
|
|
|
|
|
|
|
|
|
|
|
if (previewAs.value && !skipPreviewAs) { |
|
|
|
|
|
|
|
roles = { |
|
|
|
|
|
|
|
[previewAs.value]: true, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Object.entries(roles).some(([role, hasRole]) => { |
|
|
|
|
|
|
|
const rolePermission = rolePermissions[role as Role | ProjectRole] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
hasRole && |
|
|
|
hasRole && |
|
|
|
rolePermission && |
|
|
|
rolePermission && |
|
|
|
((isString(rolePermission) && rolePermission === '*') || rolePermission[permission as keyof typeof rolePermission]) |
|
|
|
((isString(rolePermission) && rolePermission === '*') || rolePermission[permission as keyof typeof rolePermission]) |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isUIAllowed = (permission: Permission | string, skipPreviewAs = false) => { |
|
|
|
|
|
|
|
let hasPreviewPermission = false |
|
|
|
|
|
|
|
if (previewAs.value && !skipPreviewAs) { |
|
|
|
|
|
|
|
hasPreviewPermission = hasPermission(previewAs.value, true, permission) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
hasPreviewPermission || |
|
|
|
|
|
|
|
Object.entries(allRoles.value).some(([role, hasRole]) => hasPermission(role as Role | ProjectRole, hasRole, permission)) |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { isUIAllowed } |
|
|
|
return { isUIAllowed } |
|
|
|