From 9ab599eff63fa362f2881cfa63bf5ec66a965456 Mon Sep 17 00:00:00 2001 From: Anbarasu Date: Fri, 17 May 2024 16:11:38 +0530 Subject: [PATCH 1/2] fix: Cmd K not working for viewer roles (#8411) * fix(nocodb): command palette acl * fix(nocodb): fetch only projects user have access * fix(nocodb): remove root scope as it is required only for ee to load workspaces list in root level * fix(nocodb): prevent signing out on update org role * fix(nc-gui): cmdk scope remove --- .../composables/useCommandPalette/index.ts | 14 +- .../src/services/command-palette.service.ts | 136 ++++++++---------- .../nocodb/src/services/org-users.service.ts | 1 - packages/nocodb/src/utils/acl.ts | 1 + 4 files changed, 61 insertions(+), 91 deletions(-) diff --git a/packages/nc-gui/composables/useCommandPalette/index.ts b/packages/nc-gui/composables/useCommandPalette/index.ts index 92f96816ab..edcdb1ba5e 100644 --- a/packages/nc-gui/composables/useCommandPalette/index.ts +++ b/packages/nc-gui/composables/useCommandPalette/index.ts @@ -169,19 +169,11 @@ export const useCommandPalette = createSharedComposable(() => { } } } else { - if (route.value.path.startsWith('/account')) { - if (activeScope.value.scope === 'account_settings') return + if (activeScope.value.scope === 'root') return - activeScope.value = { scope: 'account_settings', data: {} } + activeScope.value = { scope: 'root', data: {} } - loadScope() - } else { - if (activeScope.value.scope === 'root') return - - activeScope.value = { scope: 'root', data: {} } - - loadScope() - } + loadScope() } }, { immediate: true, deep: true }, diff --git a/packages/nocodb/src/services/command-palette.service.ts b/packages/nocodb/src/services/command-palette.service.ts index 8822ac468b..3f2565d5dd 100644 --- a/packages/nocodb/src/services/command-palette.service.ts +++ b/packages/nocodb/src/services/command-palette.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { type UserType, ViewTypes } from 'nocodb-sdk'; -import { Base } from '~/models'; +import { BaseUser } from '~/models'; import { TablesService } from '~/services/tables.service'; import { deserializeJSON } from '~/utils/serialize'; @@ -20,95 +20,73 @@ export class CommandPaletteService { async commandPalette(param: { body: any; user: UserType }) { const cmdData = []; try { - const { scope } = param.body; + const allBases = []; - if (scope === 'root') { - const bases = await Base.list({ user: param.user }); + const bases = await BaseUser.getProjectsList(param.user.id, param); - for (const base of bases) { - cmdData.push({ - id: `p-${base.id}`, - title: base.title, - icon: 'project', - iconColor: deserializeJSON(base.meta)?.iconColor, - section: 'Bases', - scopePayload: { - scope: `p-${base.id}`, - data: { - base_id: base.id, - }, - }, - }); - } - } else if (scope.startsWith('p-')) { - const allBases = []; - - const bases = await Base.list({ user: param.user }); + allBases.push(...bases); - allBases.push(...bases); + const viewList = []; - const viewList = []; - - for (const base of bases) { - viewList.push( - ...( - (await this.tablesService.xcVisibilityMetaGet( - base.id, - null, - false, - )) as any[] - ).filter((v) => { - return Object.keys(param.user.roles).some( - (role) => param.user.roles[role] && !v.disabled[role], - ); - }), - ); - } + for (const base of bases) { + viewList.push( + ...( + (await this.tablesService.xcVisibilityMetaGet( + base.id, + null, + false, + )) as any[] + ).filter((v) => { + return Object.keys(param.user.roles).some( + (role) => param.user.roles[role] && !v.disabled[role], + ); + }), + ); + } - const tableList = []; - const vwList = []; + const tableList = []; + const vwList = []; - for (const b of allBases) { - cmdData.push({ - id: `p-${b.id}`, - title: b.title, - icon: 'project', - iconColor: deserializeJSON(b.meta)?.iconColor, - section: 'Bases', - }); - } + for (const b of allBases) { + cmdData.push({ + id: `p-${b.id}`, + title: b.title, + icon: 'project', + iconColor: deserializeJSON(b.meta)?.iconColor, + section: 'Bases', + }); + } - for (const v of viewList) { - if (!tableList.find((el) => el.id === `tbl-${v.fk_model_id}`)) { - tableList.push({ - id: `tbl-${v.fk_model_id}`, - title: v._ptn, - parent: `p-${v.base_id}`, - icon: v?.table_meta?.icon || v.ptype, - projectName: bases.find((el) => el.id === v.base_id)?.title, - section: 'Tables', - }); - } - vwList.push({ - id: `vw-${v.id}`, - title: `${v.title}`, - parent: `tbl-${v.fk_model_id}`, - icon: v?.meta?.icon || viewTypeAlias[v.type] || 'table', + for (const v of viewList) { + if (!tableList.find((el) => el.id === `tbl-${v.fk_model_id}`)) { + tableList.push({ + id: `tbl-${v.fk_model_id}`, + title: v._ptn, + parent: `p-${v.base_id}`, + icon: v?.table_meta?.icon || v.ptype, projectName: bases.find((el) => el.id === v.base_id)?.title, - section: 'Views', - is_default: v?.is_default, - handler: { - type: 'navigate', - payload: `/nc/${v.base_id}/${v.fk_model_id}/${encodeURIComponent( - v.id, - )}`, - }, + section: 'Tables', }); } - - cmdData.push(...tableList); - cmdData.push(...vwList); + vwList.push({ + id: `vw-${v.id}`, + title: `${v.title}`, + parent: `tbl-${v.fk_model_id}`, + icon: v?.meta?.icon || viewTypeAlias[v.type] || 'table', + projectName: bases.find((el) => el.id === v.base_id)?.title, + section: 'Views', + is_default: v?.is_default, + handler: { + type: 'navigate', + payload: `/nc/${v.base_id}/${v.fk_model_id}/${encodeURIComponent( + v.id, + )}`, + }, + }); } + + cmdData.push(...tableList); + cmdData.push(...vwList); } catch (e) { console.log(e); return []; diff --git a/packages/nocodb/src/services/org-users.service.ts b/packages/nocodb/src/services/org-users.service.ts index 4b49ca734d..fb8a27e04c 100644 --- a/packages/nocodb/src/services/org-users.service.ts +++ b/packages/nocodb/src/services/org-users.service.ts @@ -52,7 +52,6 @@ export class OrgUsersService { return await User.update(param.userId, { ...updateBody, - token_version: randomTokenString(), }); } diff --git a/packages/nocodb/src/utils/acl.ts b/packages/nocodb/src/utils/acl.ts index 5d0fde924e..0a12e1ec8c 100644 --- a/packages/nocodb/src/utils/acl.ts +++ b/packages/nocodb/src/utils/acl.ts @@ -276,6 +276,7 @@ const rolePermissions: baseList: true, testConnection: true, isPluginActive: true, + commandPalette: true, }, }, [OrgUserRoles.CREATOR]: { From 67158a2d267c258045dbf636dc53ba814051b5ec Mon Sep 17 00:00:00 2001 From: Mert E Date: Fri, 17 May 2024 14:10:45 +0300 Subject: [PATCH 2/2] fix: typo on definition (#8511) Signed-off-by: mertmit --- .../nc-gui/components/virtual-cell/Lookup.vue | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/packages/nc-gui/components/virtual-cell/Lookup.vue b/packages/nc-gui/components/virtual-cell/Lookup.vue index d5df4293bd..72fd57a471 100644 --- a/packages/nc-gui/components/virtual-cell/Lookup.vue +++ b/packages/nc-gui/components/virtual-cell/Lookup.vue @@ -20,22 +20,12 @@ const rowHeight = inject(RowHeightInj, ref(1) as any) provide(RowHeightInj, providedHeightRef) -const relationColumn = computed( - () => -const relationColumn = computed( - () => - meta.value?.id ? metas.value[meta.value?.id]?.columns?.find( - (c: ColumnType) => c.id === (column.value?.colOptions as LookupType)?.fk_relation_column_id, - ) : undefined as - | (ColumnType & { - colOptions: LinkToAnotherRecordType | undefined - }) - | undefined, -) - | (ColumnType & { - colOptions: LinkToAnotherRecordType | undefined - }) - | undefined, +const relationColumn = computed(() => + meta.value?.id + ? metas.value[meta.value?.id]?.columns?.find( + (c: ColumnType) => c.id === (column.value?.colOptions as LookupType)?.fk_relation_column_id, + ) + : undefined, ) watch(