Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

on api, prevent duplicated view title

Fendy Heryantofeafad6572be
diff --git a/packages/nocodb-sdk/src/lib/error-handler/nc-error-base.ts b/packages/nocodb-sdk/src/lib/error-handler/nc-error-base.ts
index 250626b4a9..aa32f7cffd 100644
--- a/packages/nocodb-sdk/src/lib/error-handler/nc-error-base.ts
+++ b/packages/nocodb-sdk/src/lib/error-handler/nc-error-base.ts
@@ -362,7 +362,7 @@ export class NcErrorBase {
duplicateAlias(
param: {
- type: 'table' | 'column';
+ type: 'table' | 'column' | 'view';
alias: string;
base: string;
label?: string;
diff --git a/packages/nocodb/src/services/calendars.service.ts b/packages/nocodb/src/services/calendars.service.ts
index 5e72394474..d0cd8722fc 100644
--- a/packages/nocodb/src/services/calendars.service.ts
+++ b/packages/nocodb/src/services/calendars.service.ts
@@ -46,6 +46,26 @@ export class CalendarsService {
const model = await Model.get(context, param.tableId, ncMeta);
+ const existingView = await View.getByTitleOrId(
+ context,
+ {
+ titleOrId: param.calendar.title,
+ fk_model_id: param.tableId,
+ },
+ ncMeta,
+ );
+ if (existingView) {
+ NcError.get(context).duplicateAlias({
+ type: 'view',
+ alias: param.calendar.title,
+ label: 'title',
+ base: context.base_id,
+ additionalTrace: {
+ table: param.tableId,
+ },
+ });
+ }
+
const viewWebhookManager =
param.viewWebhookManager ??
(
diff --git a/packages/nocodb/src/services/forms.service.ts b/packages/nocodb/src/services/forms.service.ts
index 990a561896..62c9cf4ae0 100644
--- a/packages/nocodb/src/services/forms.service.ts
+++ b/packages/nocodb/src/services/forms.service.ts
@@ -59,6 +59,25 @@ export class FormsService {
NcError.sourceDataReadOnly(source.alias);
}
+ const existingView = await View.getByTitleOrId(
+ context,
+ {
+ titleOrId: param.body.title,
+ fk_model_id: param.tableId,
+ },
+ ncMeta,
+ );
+ if (existingView) {
+ NcError.get(context).duplicateAlias({
+ type: 'view',
+ alias: param.body.title,
+ label: 'title',
+ base: context.base_id,
+ additionalTrace: {
+ table: param.tableId,
+ },
+ });
+ }
const viewWebhookManager =
param.viewWebhookManager ??
(
diff --git a/packages/nocodb/src/services/galleries.service.ts b/packages/nocodb/src/services/galleries.service.ts
index 235db7e56d..b3b67b85d4 100644
--- a/packages/nocodb/src/services/galleries.service.ts
+++ b/packages/nocodb/src/services/galleries.service.ts
@@ -45,7 +45,25 @@ export class GalleriesService {
);
const model = await Model.get(context, param.tableId, ncMeta);
-
+ const existingView = await View.getByTitleOrId(
+ context,
+ {
+ titleOrId: param.gallery.title,
+ fk_model_id: param.tableId,
+ },
+ ncMeta,
+ );
+ if (existingView) {
+ NcError.get(context).duplicateAlias({
+ type: 'view',
+ alias: param.gallery.title,
+ label: 'title',
+ base: context.base_id,
+ additionalTrace: {
+ table: param.tableId,
+ },
+ });
+ }
const viewWebhookManager =
param.viewWebhookManager ??
(
diff --git a/packages/nocodb/src/services/grids.service.ts b/packages/nocodb/src/services/grids.service.ts
index 47707d7a24..6f1b8f19ae 100644
--- a/packages/nocodb/src/services/grids.service.ts
+++ b/packages/nocodb/src/services/grids.service.ts
@@ -35,6 +35,27 @@ export class GridsService {
param.grid,
);
+ const model = await Model.get(context, param.tableId, ncMeta);
+ const existingView = await View.getByTitleOrId(
+ context,
+ {
+ titleOrId: param.grid.title,
+ fk_model_id: param.tableId,
+ },
+ ncMeta,
+ );
+ if (existingView) {
+ NcError.get(context).duplicateAlias({
+ type: 'view',
+ alias: param.grid.title,
+ label: 'title',
+ base: context.base_id,
+ additionalTrace: {
+ table: param.tableId,
+ },
+ });
+ }
+
const viewWebhookManager =
param.viewWebhookManager ??
(
@@ -43,8 +64,6 @@ export class GridsService {
)
).forCreate();
- const model = await Model.get(context, param.tableId, ncMeta);
-
const { id } = await View.insertMetaOnly(
context,
{
diff --git a/packages/nocodb/src/services/kanbans.service.ts b/packages/nocodb/src/services/kanbans.service.ts
index 4b7b0157f8..f589a0b8fa 100644
--- a/packages/nocodb/src/services/kanbans.service.ts
+++ b/packages/nocodb/src/services/kanbans.service.ts
@@ -75,6 +75,26 @@ export class KanbansService {
}
}
+ const existingView = await View.getByTitleOrId(
+ context,
+ {
+ titleOrId: param.kanban.title,
+ fk_model_id: param.tableId,
+ },
+ ncMeta,
+ );
+ if (existingView) {
+ NcError.get(context).duplicateAlias({
+ type: 'view',
+ alias: param.kanban.title,
+ label: 'title',
+ base: context.base_id,
+ additionalTrace: {
+ table: param.tableId,
+ },
+ });
+ }
+
const viewWebhookManager =
param.viewWebhookManager ??
(