From fe6f1282e4f5e01ed6b2a1f7eda123f3c6fb17ad Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 18 Aug 2022 17:22:08 +0800 Subject: [PATCH 01/18] refactor(gui-v2): isUIAllowed --- .../composables/useUIPermission/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/nc-gui-v2/composables/useUIPermission/index.ts b/packages/nc-gui-v2/composables/useUIPermission/index.ts index 9ac28afbe4..48e3caaae6 100644 --- a/packages/nc-gui-v2/composables/useUIPermission/index.ts +++ b/packages/nc-gui-v2/composables/useUIPermission/index.ts @@ -7,7 +7,7 @@ export function useUIPermission() { const projectRoles = useState>(USER_PROJECT_ROLES, () => ({})) - const getRoles = (skipPreviewAs = false) => { + const baseRoles = computed(() => { let userRoles = user.value?.roles || {} // if string populate key-value paired object @@ -19,24 +19,24 @@ export function useUIPermission() { } // merge user role and project specific user roles - let roles = { + const roles = { ...userRoles, ...projectRoles.value, } + return roles + }) + + const isUIAllowed = (permission: Permission | string, skipPreviewAs = false) => { + let roles = baseRoles.value if (previewAs.value && !skipPreviewAs) { roles = { [previewAs.value]: true, } } - return roles - } - - const isUIAllowed = (permission: Permission | string, skipPreviewAs = false) => { - return Object.entries(getRoles(skipPreviewAs)).some(([role, hasRole]) => { + return Object.entries(roles).some(([role, hasRole]) => { const rolePermission = rolePermissions[role as keyof typeof rolePermissions] as '*' | Record - return hasRole && (rolePermission === '*' || rolePermission?.[permission as Permission]) }) } From b49e7dedb6a9c8e676047c6803cfb6ffdc0abb39 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 18 Aug 2022 17:22:38 +0800 Subject: [PATCH 02/18] fix(gui-v2): add missing share base logic in loadProjectRoles --- packages/nc-gui-v2/composables/useProject.ts | 32 ++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/nc-gui-v2/composables/useProject.ts b/packages/nc-gui-v2/composables/useProject.ts index 31cf3e2eb7..90e418c622 100644 --- a/packages/nc-gui-v2/composables/useProject.ts +++ b/packages/nc-gui-v2/composables/useProject.ts @@ -18,6 +18,14 @@ export function useProject(projectId?: MaybeRef) { // todo: refactor path param name and variable name const projectType = $computed(() => route.params.projectType as string) + const projectBaseType = $computed(() => project.value?.bases?.[0]?.type || '') + const isMysql = computed(() => ['mysql', 'mysql2'].includes(projectBaseType)) + const isPg = computed(() => projectBaseType === 'pg') + const sqlUi = computed( + () => SqlUiFactory.create({ client: projectBaseType }) as Exclude, typeof OracleUi>, + ) + const isSharedBase = computed(() => projectType === 'base') + async function loadProjectMetaInfo(force?: boolean) { if (!projectMetaInfo.value || force) { const data = await $api.project.metaGet(project.value.id!, {}, {}) @@ -28,7 +36,17 @@ export function useProject(projectId?: MaybeRef) { async function loadProjectRoles() { projectRoles.value = {} - if (project.value.id) { + if (isSharedBase.value) { + const user = await $api.auth.me( + {}, + { + headers: { + 'xc-shared-base-id': route.params.projectId, + }, + }, + ) + projectRoles.value = user.roles + } else if (project.value.id) { const user = await $api.auth.me({ project_id: project.value.id }) projectRoles.value = user.roles } @@ -37,8 +55,7 @@ export function useProject(projectId?: MaybeRef) { async function loadTables() { if (project.value.id) { const tablesResponse = await $api.dbTable.list(project.value.id, { - // FIXME: type - includeM2M: includeM2M.value || '', + includeM2M: includeM2M.value, }) if (tablesResponse.list) tables.value = tablesResponse.list } @@ -58,15 +75,6 @@ export function useProject(projectId?: MaybeRef) { await loadTables() } - const projectBaseType = $computed(() => project.value?.bases?.[0]?.type || '') - - const isMysql = computed(() => ['mysql', 'mysql2'].includes(projectBaseType)) - const isPg = computed(() => projectBaseType === 'pg') - const sqlUi = computed( - () => SqlUiFactory.create({ client: projectBaseType }) as Exclude, typeof OracleUi>, - ) - const isSharedBase = computed(() => projectType === 'base') - return { project, tables, From 9aa8f9e506befeffe0f476c3d02df0a5024b4374 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 18 Aug 2022 17:23:03 +0800 Subject: [PATCH 03/18] fix(gui-v2): add missing isSharedBase --- .../nc-gui-v2/components/dashboard/TreeView.vue | 4 ++-- .../components/smartsheet-toolbar/ShareView.vue | 12 +++++++++--- packages/nc-gui-v2/layouts/base.vue | 2 +- .../[projectType]/[projectId]/index/index.vue | 15 +++++++++++++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/nc-gui-v2/components/dashboard/TreeView.vue b/packages/nc-gui-v2/components/dashboard/TreeView.vue index d7999e4251..bb7515d7df 100644 --- a/packages/nc-gui-v2/components/dashboard/TreeView.vue +++ b/packages/nc-gui-v2/components/dashboard/TreeView.vue @@ -202,7 +202,7 @@ const activeTable = computed(() => {
{{ table.title }}
@@ -244,7 +244,7 @@ const activeTable = computed(() => { -