Browse Source

refactor(nc-gui): use shared composable instead of injection state for permissions

pull/3703/head
braks 2 years ago
parent
commit
95095c67c8
  1. 7
      packages/nc-gui/composables/useUIPermission/index.ts

7
packages/nc-gui/composables/useUIPermission/index.ts

@ -1,7 +1,7 @@
import { isString } from '@vueuse/core'
import type { Permission } from './rolePermissions'
import rolePermissions from './rolePermissions'
import { useGlobal, useRoles } from '#imports'
import { createSharedComposable, useGlobal, useRoles } from '#imports'
import type { ProjectRole, Role } from '~/lib'
const hasPermission = (role: Role | ProjectRole, hasRole: boolean, permission: Permission | string) => {
@ -14,9 +14,8 @@ const hasPermission = (role: Role | ProjectRole, hasRole: boolean, permission: P
return rolePermission[permission as keyof typeof rolePermission]
}
export function useUIPermission() {
export const useUIPermission = createSharedComposable(() => {
const { previewAs } = useGlobal()
const { allRoles } = useRoles()
const isUIAllowed = (permission: Permission | string, skipPreviewAs = false) => {
@ -32,4 +31,4 @@ export function useUIPermission() {
}
return { isUIAllowed }
}
})

Loading…
Cancel
Save