Browse Source

chore(gui-v2): cleanup typecheck issues

pull/3158/head
braks 2 years ago
parent
commit
fb07bbacea
  1. 2
      packages/nc-gui-v2/components/dashboard/TreeView.vue
  2. 7
      packages/nc-gui-v2/composables/useUIPermission/index.ts

2
packages/nc-gui-v2/components/dashboard/TreeView.vue

@ -3,7 +3,7 @@ import type { TableType } from 'nocodb-sdk'
import Sortable from 'sortablejs' import Sortable from 'sortablejs'
import { Empty } from 'ant-design-vue' import { Empty } from 'ant-design-vue'
import { useNuxtApp } from '#app' import { useNuxtApp } from '#app'
import { computed, useProject, useTable, useTabs, watchEffect } from '#imports' import { computed, useProject, useTable, useTabs, useUIPermission, watchEffect } from '#imports'
import { TabType } from '~/composables' import { TabType } from '~/composables'
import MdiView from '~icons/mdi/eye-circle-outline' import MdiView from '~icons/mdi/eye-circle-outline'
import MdiTableLarge from '~icons/mdi/table-large' import MdiTableLarge from '~icons/mdi/table-large'

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

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

Loading…
Cancel
Save