From 0d2505ebcb5f7b96b44426f0cd065ba59ad80700 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 18 Jun 2024 19:06:17 +0000 Subject: [PATCH 01/28] fix: save readonly state in source meta column --- .../dashboard/settings/data-sources/CreateBase.vue | 13 +++++++++++++ .../dashboard/settings/data-sources/EditBase.vue | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue b/packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue index c559ee3b04..854ccdbaf8 100644 --- a/packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue +++ b/packages/nc-gui/components/dashboard/settings/data-sources/CreateBase.vue @@ -55,6 +55,10 @@ const formState = ref({ }, sslUse: SSLUsage.No, extraParameters: [], + meta: { + readOnlySchema: true, + readOnlyData: false, + }, }) const customFormState = ref({ @@ -244,6 +248,7 @@ const createSource = async () => { config, inflection_column: formState.value.inflection.inflectionColumn, inflection_table: formState.value.inflection.inflectionTable, + meta: formState.value.meta, }) $poller.subscribe( @@ -508,6 +513,14 @@ const toggleModal = (val: boolean) => { > + + + + + + + +
diff --git a/packages/nc-gui/components/dashboard/settings/data-sources/EditBase.vue b/packages/nc-gui/components/dashboard/settings/data-sources/EditBase.vue index 3a12b83bcc..fafe7fa8c2 100644 --- a/packages/nc-gui/components/dashboard/settings/data-sources/EditBase.vue +++ b/packages/nc-gui/components/dashboard/settings/data-sources/EditBase.vue @@ -71,6 +71,10 @@ const customFormState = ref({ }, sslUse: SSLUsage.No, extraParameters: [], + meta: { + readOnlySchema: true, + readOnlyData: false, + }, }) const validators = computed(() => { @@ -524,6 +528,14 @@ watch( > + + + + + + + +
From 4e641f3fd2fcb51ae407a696e81d1db599751b4a Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 18 Jun 2024 19:06:17 +0000 Subject: [PATCH 02/28] feat: extract source id in middleware and remove unnecessary optional chaining --- .../extract-ids/extract-ids.middleware.ts | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts b/packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts index 80a50fd08b..e2a825b42b 100644 --- a/packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts +++ b/packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts @@ -85,7 +85,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.tableNotFound(params.tableId || params.modelId); } - req.ncBaseId = model?.base_id; + req.ncBaseId = model.base_id; + req.ncSourceId = model.source_id; } else if (params.viewId) { const view = (await View.get(context, params.viewId)) || @@ -95,7 +96,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.viewNotFound(params.viewId); } - req.ncBaseId = view?.base_id; + req.ncBaseId = view.base_id; + req.ncSourceId = view.source_id; } else if ( params.formViewId || params.gridViewId || @@ -122,7 +124,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { ); } - req.ncBaseId = view?.base_id; + req.ncBaseId = view.base_id; + req.ncSourceId = view.source_id; } else if (params.publicDataUuid) { const view = await View.getByUUID(context, req.params.publicDataUuid); @@ -130,7 +133,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.viewNotFound(params.publicDataUuid); } - req.ncBaseId = view?.base_id; + req.ncBaseId = view.base_id; + req.ncSourceId = view.source_id; } else if (params.sharedViewUuid) { const view = await View.getByUUID(context, req.params.sharedViewUuid); @@ -138,7 +142,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.viewNotFound(req.params.sharedViewUuid); } - req.ncBaseId = view?.base_id; + req.ncBaseId = view.base_id; + req.ncSourceId = view.source_id; } else if (params.sharedBaseUuid) { const base = await Base.getByUuid(context, req.params.sharedBaseUuid); @@ -154,7 +159,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.genericNotFound('Webhook', params.hookId); } - req.ncBaseId = hook?.base_id; + req.ncBaseId = hook.base_id; + req.ncSourceId = hook.source_id; } else if (params.gridViewColumnId) { const gridViewColumn = await GridViewColumn.get( context, @@ -165,7 +171,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.fieldNotFound(params.gridViewColumnId); } - req.ncBaseId = gridViewColumn?.base_id; + req.ncBaseId = gridViewColumn.base_id; + req.ncSourceId = gridViewColumn.source_id; } else if (params.formViewColumnId) { const formViewColumn = await FormViewColumn.get( context, @@ -176,7 +183,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.fieldNotFound(params.formViewColumnId); } - req.ncBaseId = formViewColumn?.base_id; + req.ncBaseId = formViewColumn.base_id; + req.ncSourceId = formViewColumn.source_id; } else if (params.galleryViewColumnId) { const galleryViewColumn = await GalleryViewColumn.get( context, @@ -187,7 +195,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.fieldNotFound(params.galleryViewColumnId); } - req.ncBaseId = galleryViewColumn?.base_id; + req.ncBaseId = galleryViewColumn.base_id; + req.ncSourceId = galleryViewColumn.source_id; } else if (params.columnId) { const column = await Column.get(context, { colId: params.columnId }); @@ -195,7 +204,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.fieldNotFound(params.columnId); } - req.ncBaseId = column?.base_id; + req.ncBaseId = column.base_id; + req.ncSourceId = column.source_id; } else if (params.filterId) { const filter = await Filter.get(context, params.filterId); @@ -203,7 +213,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.genericNotFound('Filter', params.filterId); } - req.ncBaseId = filter?.base_id; + req.ncBaseId = filter.base_id; + req.ncSourceId = filter.source_id; } else if (params.filterParentId) { const filter = await Filter.get(context, params.filterParentId); @@ -211,7 +222,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.genericNotFound('Filter', params.filterParentId); } - req.ncBaseId = filter?.base_id; + req.ncBaseId = filter.base_id; + req.ncSourceId = filter.source_id; } else if (params.sortId) { const sort = await Sort.get(context, params.sortId); @@ -219,7 +231,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.genericNotFound('Sort', params.sortId); } - req.ncBaseId = sort?.base_id; + req.ncBaseId = sort.base_id; + req.ncSourceId = sort.source_id; } else if (params.syncId) { const syncSource = await SyncSource.get(context, req.params.syncId); @@ -228,6 +241,7 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { } req.ncBaseId = syncSource.base_id; + req.ncSourceId = syncSource.source_id; } else if (params.extensionId) { const extension = await Extension.get(context, req.params.extensionId); @@ -258,7 +272,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.tableNotFound(req.body.fk_model_id); } - req.ncBaseId = model?.base_id; + req.ncBaseId = model.base_id; + req.ncSourceId = model.source_id; } // extract fk_model_id from query params only if it's audit get endpoint else if ( @@ -281,7 +296,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.tableNotFound(req.query?.fk_model_id); } - req.ncBaseId = model?.base_id; + req.ncBaseId = model.base_id; + req.ncSourceId = model.source_id; } else if ( [ '/api/v1/db/meta/comment/:commentId', @@ -296,7 +312,8 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { NcError.genericNotFound('Comment', params.commentId); } - req.ncBaseId = comment?.base_id; + req.ncBaseId = comment.base_id; + req.ncSourceId = comment.source_id; } // extract base id from query params only if it's userMe endpoint or webhook plugin list else if ( From 5d8b1fc55ab639a8effd84907b360afdfbf33473 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 18 Jun 2024 19:06:17 +0000 Subject: [PATCH 03/28] feat: restrict data/meta operations in gui --- .../nc-gui/components/cell/MultiSelect.vue | 3 +- .../nc-gui/components/cell/SingleSelect.vue | 3 +- .../components/cell/attachment/Modal.vue | 3 +- .../components/cell/attachment/index.vue | 3 +- .../dashboard/Sidebar/TopSection.vue | 4 +- .../dashboard/TreeView/AddNewTableNode.vue | 3 +- .../dashboard/TreeView/BaseOptions.vue | 6 +-- .../dashboard/TreeView/ProjectNode.vue | 2 +- .../dashboard/TreeView/TableNode.vue | 19 ++++++--- .../settings/data-sources/CreateBase.vue | 9 +++-- .../settings/data-sources/EditBase.vue | 8 ++-- .../nc-gui/components/project/AllTables.vue | 4 +- .../nc-gui/components/smartsheet/Details.vue | 3 +- .../nc-gui/components/smartsheet/Form.vue | 3 +- .../nc-gui/components/smartsheet/Gallery.vue | 3 +- .../nc-gui/components/smartsheet/Kanban.vue | 3 +- .../smartsheet/calendar/DayView/DateField.vue | 3 +- .../calendar/DayView/DateTimeField.vue | 3 +- .../smartsheet/calendar/MonthView.vue | 3 +- .../smartsheet/calendar/SideMenu.vue | 3 +- .../calendar/WeekView/DateField.vue | 3 +- .../calendar/WeekView/DateTimeField.vue | 2 +- .../smartsheet/expanded-form/Comments.vue | 3 +- .../smartsheet/expanded-form/index.vue | 3 +- .../components/smartsheet/grid/Table.vue | 2 +- .../components/smartsheet/header/Cell.vue | 3 +- .../smartsheet/header/VirtualCell.vue | 3 +- .../smartsheet/sidebar/RenameableMenuItem.vue | 3 +- .../toolbar/KanbanStackEditOrAdd.vue | 4 +- .../smartsheet/toolbar/MoreActions.vue | 3 +- .../smartsheet/toolbar/ShareView.vue | 3 +- .../smartsheet/toolbar/ViewActionMenu.vue | 3 +- .../smartsheet/toolbar/ViewActions.vue | 3 +- .../smartsheet/topbar/SelectMode.vue | 4 +- .../nc-gui/components/tabs/Smartsheet.vue | 14 ++++++- .../components/virtual-cell/BelongsTo.vue | 3 +- .../components/virtual-cell/HasMany.vue | 3 +- .../nc-gui/components/virtual-cell/Links.vue | 3 +- .../components/virtual-cell/ManyToMany.vue | 3 +- .../components/virtual-cell/OneToOne.vue | 3 +- .../virtual-cell/components/ItemChip.vue | 3 +- .../composables/useCalendarViewStore.ts | 3 +- .../composables/useExpandedFormStore.ts | 3 +- .../nc-gui/composables/useKanbanViewStore.ts | 3 +- .../nc-gui/composables/useMapViewDataStore.ts | 3 +- packages/nc-gui/composables/useRoles/index.ts | 39 ++++++++++++++++++- packages/nc-gui/composables/useViewColumns.ts | 3 +- packages/nc-gui/composables/useViewData.ts | 3 +- packages/nc-gui/composables/useViewFilters.ts | 3 +- packages/nc-gui/composables/useViewGroupBy.ts | 3 +- packages/nc-gui/composables/useViewSorts.ts | 2 +- packages/nc-gui/context/index.ts | 9 ++++- packages/nocodb-sdk/src/lib/enums.ts | 8 ++++ .../src/services/public-datas.service.ts | 7 +++- packages/nocodb/src/utils/acl.ts | 16 ++++++++ 55 files changed, 202 insertions(+), 68 deletions(-) diff --git a/packages/nc-gui/components/cell/MultiSelect.vue b/packages/nc-gui/components/cell/MultiSelect.vue index 3a625e8c24..fee5afe43a 100644 --- a/packages/nc-gui/components/cell/MultiSelect.vue +++ b/packages/nc-gui/components/cell/MultiSelect.vue @@ -5,6 +5,7 @@ import type { Select as AntSelect } from 'ant-design-vue' import type { SelectOptionType, SelectOptionsType } from 'nocodb-sdk' import type { FormFieldsLimitOptionsType } from '~/lib/types' import MdiCloseCircle from '~icons/mdi/close-circle' +import {useRolesWrapper} from "~/composables/useRoles"; interface Props { modelValue?: string | string[] @@ -57,7 +58,7 @@ const { $api } = useNuxtApp() const { getMeta } = useMetas() -const { isUIAllowed } = useRoles() +const { isUIAllowed } = useRolesWrapper() const { isPg, isMysql } = useBase() diff --git a/packages/nc-gui/components/cell/SingleSelect.vue b/packages/nc-gui/components/cell/SingleSelect.vue index 5852a9dcbf..e61ac988dd 100644 --- a/packages/nc-gui/components/cell/SingleSelect.vue +++ b/packages/nc-gui/components/cell/SingleSelect.vue @@ -4,6 +4,7 @@ import { message } from 'ant-design-vue' import tinycolor from 'tinycolor2' import type { SelectOptionType } from 'nocodb-sdk' import type { FormFieldsLimitOptionsType } from '~/lib/types' +import {useRolesWrapper} from "~/composables/useRoles"; interface Props { modelValue?: string | undefined @@ -49,7 +50,7 @@ const searchVal = ref() const { getMeta } = useMetas() -const { isUIAllowed } = useRoles() +const { isUIAllowed } = useRolesWrapper() const { isPg, isMysql } = useBase() diff --git a/packages/nc-gui/components/cell/attachment/Modal.vue b/packages/nc-gui/components/cell/attachment/Modal.vue index 4af4ec4526..82944f27ae 100644 --- a/packages/nc-gui/components/cell/attachment/Modal.vue +++ b/packages/nc-gui/components/cell/attachment/Modal.vue @@ -2,8 +2,9 @@ import { onKeyDown, useEventListener } from '@vueuse/core' import { useAttachmentCell } from './utils' import { useSortable } from './sort' +import {useRolesWrapper} from "~/composables/useRoles"; -const { isUIAllowed } = useRoles() +const { isUIAllowed } = useRolesWrapper() const { open, diff --git a/packages/nc-gui/components/cell/attachment/index.vue b/packages/nc-gui/components/cell/attachment/index.vue index a95f1c4da8..8335952e9a 100644 --- a/packages/nc-gui/components/cell/attachment/index.vue +++ b/packages/nc-gui/components/cell/attachment/index.vue @@ -2,6 +2,7 @@ import { onKeyDown } from '@vueuse/core' import { useProvideAttachmentCell } from './utils' import { useSortable } from './sort' +import {useRolesWrapper} from "~/composables/useRoles"; interface Props { modelValue?: string | Record[] | null @@ -175,7 +176,7 @@ const keydownSpace = (e: KeyboardEvent) => { } } -const { isUIAllowed } = useRoles() +const { isUIAllowed } = useRolesWrapper() const isConfirmModalOpen = ref(false) const filetoDelete = reactive({ title: '', diff --git a/packages/nc-gui/components/dashboard/Sidebar/TopSection.vue b/packages/nc-gui/components/dashboard/Sidebar/TopSection.vue index 28f94f6a0c..57fe869023 100644 --- a/packages/nc-gui/components/dashboard/Sidebar/TopSection.vue +++ b/packages/nc-gui/components/dashboard/Sidebar/TopSection.vue @@ -1,8 +1,10 @@