From a20c295ee11143486347babc6751e28f36c2f16f Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 30 May 2023 18:53:41 +0530 Subject: [PATCH 1/7] fix: include lookup related metas in shared view meta api Signed-off-by: Pranav C --- .../src/services/public-metas.service.ts | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/nocodb/src/services/public-metas.service.ts b/packages/nocodb/src/services/public-metas.service.ts index 1ce6605e73..36f4dcc405 100644 --- a/packages/nocodb/src/services/public-metas.service.ts +++ b/packages/nocodb/src/services/public-metas.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'; import { ErrorMessages, RelationTypes, UITypes } from 'nocodb-sdk'; import { NcError } from '../helpers/catchError'; import { Base, Column, Model, Project, View } from '../models'; -import type { LinkToAnotherRecordColumn } from '../models'; +import type { LinkToAnotherRecordColumn, LookupColumn } from '../models'; import type { LinkToAnotherRecordType } from 'nocodb-sdk'; @Injectable() @@ -73,6 +73,11 @@ export class PublicMetasService { id: colOpt.fk_mm_model_id, }); } + } else if (UITypes.Lookup === col.uidt) { + await this.extractLookupRelatedMetas({ + lookupColOption: await col.getColOptions(), + relatedMetas, + }); } } @@ -80,6 +85,40 @@ export class PublicMetasService { return view; } + + private async extractLookupRelatedMetas({ + lookupColOption, + relatedMetas = {}, + }: { + lookupColOption: LookupColumn; + relatedMetas: { [key: string]: Model }; + }) { + const relationCol = await Column.get({ + colId: lookupColOption.fk_relation_column_id, + }); + const lookupCol = await Column.get({ + colId: lookupColOption.fk_lookup_column_id, + }); + + if (!relatedMetas[relationCol.fk_model_id]) { + relatedMetas[relationCol.fk_model_id] = await Model.getWithInfo({ + id: lookupCol.fk_model_id, + }); + } + if (!relatedMetas[lookupCol.fk_model_id]) { + relatedMetas[lookupCol.fk_model_id] = await Model.getWithInfo({ + id: lookupCol.fk_model_id, + }); + } + + if (lookupCol.uidt === UITypes.Lookup) { + await this.extractLookupRelatedMetas({ + lookupColOption: await lookupCol.getColOptions(), + relatedMetas, + }); + } + } + async publicSharedBaseGet(param: { sharedBaseUuid: string }): Promise { const project = await Project.getByUuid(param.sharedBaseUuid); From c56ff5e8dc004df24ab280554c7b449c1c944370 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 31 May 2023 01:33:41 +0530 Subject: [PATCH 2/7] chore: add some comments Signed-off-by: Pranav C --- packages/nocodb/src/services/public-metas.service.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/nocodb/src/services/public-metas.service.ts b/packages/nocodb/src/services/public-metas.service.ts index 36f4dcc405..cb4e3664a4 100644 --- a/packages/nocodb/src/services/public-metas.service.ts +++ b/packages/nocodb/src/services/public-metas.service.ts @@ -100,17 +100,22 @@ export class PublicMetasService { colId: lookupColOption.fk_lookup_column_id, }); + // extract meta for table which belongs the relation column + // if not already extracted if (!relatedMetas[relationCol.fk_model_id]) { relatedMetas[relationCol.fk_model_id] = await Model.getWithInfo({ id: lookupCol.fk_model_id, }); } + // extract meta for table in which looked up column belongs + // if not already extracted if (!relatedMetas[lookupCol.fk_model_id]) { relatedMetas[lookupCol.fk_model_id] = await Model.getWithInfo({ id: lookupCol.fk_model_id, }); } + // if looked up column is a lookup column do the same for it by recursion if (lookupCol.uidt === UITypes.Lookup) { await this.extractLookupRelatedMetas({ lookupColOption: await lookupCol.getColOptions(), From 1d7027f67ac739053a9f29d04c080a5a4b7ae573 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 31 May 2023 11:39:17 +0530 Subject: [PATCH 3/7] fix: handle if lookup column is LTAR Signed-off-by: Pranav C --- .../src/services/public-metas.service.ts | 77 ++++++++++++------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/packages/nocodb/src/services/public-metas.service.ts b/packages/nocodb/src/services/public-metas.service.ts index cb4e3664a4..0073502bba 100644 --- a/packages/nocodb/src/services/public-metas.service.ts +++ b/packages/nocodb/src/services/public-metas.service.ts @@ -63,22 +63,7 @@ export class PublicMetasService { // load related table metas for (const col of view.model.columns) { - if (UITypes.LinkToAnotherRecord === col.uidt) { - const colOpt = await col.getColOptions(); - relatedMetas[colOpt.fk_related_model_id] = await Model.getWithInfo({ - id: colOpt.fk_related_model_id, - }); - if (colOpt.type === 'mm') { - relatedMetas[colOpt.fk_mm_model_id] = await Model.getWithInfo({ - id: colOpt.fk_mm_model_id, - }); - } - } else if (UITypes.Lookup === col.uidt) { - await this.extractLookupRelatedMetas({ - lookupColOption: await col.getColOptions(), - relatedMetas, - }); - } + await this.extractRelatedMetas({ col, relatedMetas }); } view.relatedMetas = relatedMetas; @@ -86,6 +71,43 @@ export class PublicMetasService { return view; } + private async extractRelatedMetas({ + col, + relatedMetas = {}, + }: { + col: Column; + relatedMetas: Record; + }) { + if (UITypes.LinkToAnotherRecord === col.uidt) { + await this.extractLTARRelatedMetas({ + ltarColOption: await col.getColOptions(), + relatedMetas, + }); + } else if (UITypes.Lookup === col.uidt) { + await this.extractLookupRelatedMetas({ + lookupColOption: await col.getColOptions(), + relatedMetas, + }); + } + } + + private async extractLTARRelatedMetas({ + ltarColOption, + relatedMetas = {}, + }: { + ltarColOption: LinkToAnotherRecordColumn; + relatedMetas: { [key: string]: Model }; + }) { + relatedMetas[ltarColOption.fk_related_model_id] = await Model.getWithInfo({ + id: ltarColOption.fk_related_model_id, + }); + if (ltarColOption.type === 'mm') { + relatedMetas[ltarColOption.fk_mm_model_id] = await Model.getWithInfo({ + id: ltarColOption.fk_mm_model_id, + }); + } + } + private async extractLookupRelatedMetas({ lookupColOption, relatedMetas = {}, @@ -96,7 +118,7 @@ export class PublicMetasService { const relationCol = await Column.get({ colId: lookupColOption.fk_relation_column_id, }); - const lookupCol = await Column.get({ + const lookedUpCol = await Column.get({ colId: lookupColOption.fk_lookup_column_id, }); @@ -104,24 +126,23 @@ export class PublicMetasService { // if not already extracted if (!relatedMetas[relationCol.fk_model_id]) { relatedMetas[relationCol.fk_model_id] = await Model.getWithInfo({ - id: lookupCol.fk_model_id, + id: relationCol.fk_model_id, }); } + // extract meta for table in which looked up column belongs // if not already extracted - if (!relatedMetas[lookupCol.fk_model_id]) { - relatedMetas[lookupCol.fk_model_id] = await Model.getWithInfo({ - id: lookupCol.fk_model_id, + if (!relatedMetas[lookedUpCol.fk_model_id]) { + relatedMetas[lookedUpCol.fk_model_id] = await Model.getWithInfo({ + id: lookedUpCol.fk_model_id, }); } - // if looked up column is a lookup column do the same for it by recursion - if (lookupCol.uidt === UITypes.Lookup) { - await this.extractLookupRelatedMetas({ - lookupColOption: await lookupCol.getColOptions(), - relatedMetas, - }); - } + // extract metas related to the looked up column + await this.extractRelatedMetas({ + col: lookedUpCol, + relatedMetas, + }); } async publicSharedBaseGet(param: { sharedBaseUuid: string }): Promise { From 40aeec53a47940ba4559ff4cc505aa9473441e7f Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 31 May 2023 12:05:35 +0530 Subject: [PATCH 4/7] fix: disable expand form in public shared gallery Signed-off-by: Pranav C --- packages/nc-gui/components/smartsheet/Gallery.vue | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/nc-gui/components/smartsheet/Gallery.vue b/packages/nc-gui/components/smartsheet/Gallery.vue index f4f4a160f4..4f94e91973 100644 --- a/packages/nc-gui/components/smartsheet/Gallery.vue +++ b/packages/nc-gui/components/smartsheet/Gallery.vue @@ -7,6 +7,7 @@ import { IsFormInj, IsGalleryInj, IsGridInj, + IsPublicInj, MetaInj, NavigateDir, OpenNewRecordFormHookInj, @@ -62,6 +63,8 @@ provide(IsGridInj, ref(false)) provide(PaginationDataInj, paginationData) provide(ChangePageInj, changePage) +const isPublic = inject(IsPublicInj, ref(false)) + const fields = inject(FieldsInj, ref([])) const route = useRoute() @@ -125,6 +128,10 @@ const attachments = (record: any): Attachment[] => { } const expandForm = (row: RowType, state?: Record) => { + if (isPublic.value) { + return + } + const rowId = extractPkFromRow(row.row, meta.value!.columns!) if (rowId) { From 897cb583074f9cc86364c34d05122ffb561f0ccd Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 31 May 2023 12:19:42 +0530 Subject: [PATCH 5/7] fix: ignore redirection if public page Signed-off-by: Pranav C --- packages/nc-gui/composables/useApi/interceptors.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/nc-gui/composables/useApi/interceptors.ts b/packages/nc-gui/composables/useApi/interceptors.ts index 4c12bc083c..ca95a62243 100644 --- a/packages/nc-gui/composables/useApi/interceptors.ts +++ b/packages/nc-gui/composables/useApi/interceptors.ts @@ -67,9 +67,8 @@ export function addAxiosInterceptors(api: Api) { }) .catch(async (error) => { await state.signOut() - // todo: handle new user - navigateTo('/signIn') + if (!route.meta.public) navigateTo('/signIn') return Promise.reject(error) }) From c427332eea0684c0bc8c8c2d50fb3fb253e8b58e Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 31 May 2023 12:49:05 +0530 Subject: [PATCH 6/7] fix: make cursor in public shared gallery default for card Signed-off-by: Pranav C --- packages/nc-gui/components/smartsheet/Gallery.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/nc-gui/components/smartsheet/Gallery.vue b/packages/nc-gui/components/smartsheet/Gallery.vue index 4f94e91973..5b0a2f5088 100644 --- a/packages/nc-gui/components/smartsheet/Gallery.vue +++ b/packages/nc-gui/components/smartsheet/Gallery.vue @@ -241,6 +241,7 @@ watch(view, async (nextView) => { :data-testid="`nc-gallery-card-${record.row.id}`" @click="expandFormClick($event, record)" @contextmenu="showContextMenu($event, { row: rowIndex })" + :style="isPublic ? { cursor: 'default' } : { cursor: 'pointer' }" > -
+
= Symbol('toggle-dialog-inj export const CellClickHookInj: InjectionKey | undefined> = Symbol('cell-click-injection') export const SaveRowInj: InjectionKey<(() => void) | undefined> = Symbol('save-row-injection') export const CurrentCellInj: InjectionKey> = Symbol('current-cell-injection') +export const IsUnderLookupInj: InjectionKey> = Symbol('is-under-lookup-injection')