diff --git a/packages/nc-gui/composables/useUIPermission/index.ts b/packages/nc-gui/composables/useUIPermission/index.ts index fcac173c89..806b006d02 100644 --- a/packages/nc-gui/composables/useUIPermission/index.ts +++ b/packages/nc-gui/composables/useUIPermission/index.ts @@ -24,14 +24,32 @@ export const useUIPermission = createSharedComposable(() => { const { previewAs } = useGlobal() const { allRoles } = useRoles() - const isUIAllowed = (permission: Permission | string, skipPreviewAs = false) => { + const isUIAllowed = ( + permission: Permission | string, + skipPreviewAs = false, + userRoles?: string | Record | string[], + ) => { if (previewAs.value && !skipPreviewAs) { return hasPermission(previewAs.value, true, permission) } - return Object.entries(allRoles.value).some(([role, hasRole]) => - hasPermission(role as Role | ProjectRole, hasRole, permission), - ) + let roles: Record = {} + + if (!userRoles) { + roles = allRoles.value + } else if (Array.isArray(userRoles) || typeof userRoles === 'string') { + roles = (Array.isArray(userRoles) ? userRoles : userRoles.split(',')) + // filter out any empty-string/null/undefined values + .filter(Boolean) + .reduce>((acc, role) => { + acc[role] = true + return acc + }, {}) + } else if (typeof userRoles === 'object') { + roles = userRoles + } + + return Object.entries(roles).some(([role, hasRole]) => hasPermission(role as Role | ProjectRole, hasRole, permission)) } return { isUIAllowed } diff --git a/packages/nc-gui/pages/index/index/index.vue b/packages/nc-gui/pages/index/index/index.vue index 8aeedb8bc6..4a3b8789c2 100644 --- a/packages/nc-gui/pages/index/index/index.vue +++ b/packages/nc-gui/pages/index/index/index.vue @@ -247,9 +247,9 @@ const copyProjectMeta = async () => {