Browse Source

refactor(gui): linting and type correction

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3796/head
Pranav C 2 years ago
parent
commit
ae73504def
  1. 2
      packages/nc-gui/components/dashboard/settings/AppStore.vue
  2. 6
      packages/nc-gui/composables/useUIPermission/index.ts
  3. 17
      packages/nc-gui/composables/useUIPermission/rolePermissions.ts

2
packages/nc-gui/components/dashboard/settings/AppStore.vue

@ -115,7 +115,7 @@ onMounted(async () => {
:body-style="{ width: '100%' }" :body-style="{ width: '100%' }"
> >
<div class="install-btn flex flex-row justify-end space-x-1"> <div class="install-btn flex flex-row justify-end space-x-1">
<a-button v-if="app.parsedInput" size="small" type="primary" @click="showInstallPluginModal(app)"> <a-button v-if="app.parsedInput" size="small" type="primary" @click="showInstallPluginModal(app)">
<div class="flex flex-row justify-center items-center caption capitalize nc-app-store-card-edit"> <div class="flex flex-row justify-center items-center caption capitalize nc-app-store-card-edit">
<MdiEditIcon class="pr-0.5" :height="12" /> <MdiEditIcon class="pr-0.5" :height="12" />
Edit Edit

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

@ -11,12 +11,12 @@ const hasPermission = (role: Role | ProjectRole, hasRole: boolean, permission: P
if (isString(rolePermission) && rolePermission === '*') return true if (isString(rolePermission) && rolePermission === '*') return true
// todo: type correction
if ('include' in rolePermission && rolePermission.include) { if ('include' in rolePermission && rolePermission.include) {
return rolePermission.include[permission] return !!rolePermission.include[permission as keyof typeof rolePermission.include]
} }
if ('exclude' in rolePermission && rolePermission.exclude) { if ('exclude' in rolePermission && rolePermission.exclude) {
return !rolePermission.exclude[permission] return !rolePermission.exclude[permission as keyof typeof rolePermission.exclude]
} }
return rolePermission[permission as keyof typeof rolePermission] return rolePermission[permission as keyof typeof rolePermission]

17
packages/nc-gui/composables/useUIPermission/rolePermissions.ts

@ -1,7 +1,16 @@
import { ProjectRole, Role } from '~/lib' import { ProjectRole, Role } from '~/lib'
const rolePermissions: Record<Role | ProjectRole, '*' | Partial<Record<'include' | 'exclude', Record<string, boolean>>>> = { const rolePermissions = {
// general role permissions // general role permissions
/**
* Each permission value means the following
* `*` - which is wildcard, means all permissions are allowed
* `include` - which is an object, means only the permissions listed in the object are allowed
* `exclude` - which is an object, means all permissions are allowed except the ones listed in the object
* `undefined` or `{}` - which is the default value, means no permissions are allowed
* */
/** todo: enable wildcard permission /** todo: enable wildcard permission
* limited permission due to unexpected behaviour in shared base if opened in same window */ * limited permission due to unexpected behaviour in shared base if opened in same window */
[Role.Super]: '*', [Role.Super]: '*',
@ -63,11 +72,11 @@ const rolePermissions: Record<Role | ProjectRole, '*' | Partial<Record<'include'
}, },
} as const } as const
type RolePermissions = Omit<typeof rolePermissions, 'creator' | 'owner' | 'guest' | 'admin'> type RolePermissions = Omit<typeof rolePermissions, 'guest' | 'admin' | 'super'>
type GetKeys<T> = T extends Record<string, any> ? keyof T : never type GetKeys<T> = T extends Record<any, Record<infer Key, boolean>> ? Key : never
export type Permission<K extends keyof RolePermissions = keyof RolePermissions> = RolePermissions[K] extends Record<string, any> export type Permission<K extends keyof RolePermissions = keyof RolePermissions> = RolePermissions[K] extends Record<any, any>
? GetKeys<RolePermissions[K]> ? GetKeys<RolePermissions[K]>
: never : never

Loading…
Cancel
Save