mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
855 B
30 lines
855 B
import rolePermissions from './rolePermissions' |
|
|
|
export default () => { |
|
const { $state } = useNuxtApp() |
|
|
|
const isUIAllowed = (permission: keyof typeof rolePermissions[keyof typeof rolePermissions], _skipPreviewAs = false) => { |
|
const user = $state.user |
|
const roles = { |
|
...(user?.value?.roles || {}), |
|
// todo: load project specific roles |
|
// ...(state.projectRole || {}), |
|
} |
|
|
|
// todo: handle preview as |
|
// if (state.previewAs && !skipPreviewAs) { |
|
// roles = { |
|
// [state.previewAs]: true |
|
// }; |
|
// } |
|
return Object.entries(roles).some(([role, hasRole]) => { |
|
return ( |
|
hasRole && |
|
(rolePermissions[role as keyof typeof rolePermissions] === '*' || |
|
rolePermissions[role as keyof typeof rolePermissions]?.[permission]) |
|
) |
|
}) |
|
} |
|
|
|
return { isUIAllowed } |
|
}
|
|
|