Browse Source

fix(nocodb): prevent column deletion if it is used in a calendar view

pull/7611/head
DarkPhoenix2704 9 months ago
parent
commit
1d83e22f66
  1. 26
      packages/nocodb/src/models/CalendarRange.ts
  2. 10
      packages/nocodb/src/services/columns.service.ts

26
packages/nocodb/src/models/CalendarRange.ts

@ -112,4 +112,30 @@ export default class CalendarRange implements CalendarRangeType {
return data && new CalendarRange(data);
}
public static async IsColumnBeingUsedAsRange(
columnId: string,
ncMeta = Noco.ncMeta,
) {
return (
(
await ncMeta.metaList2(null, null, MetaTable.CALENDAR_VIEW_RANGE, {
xcCondition: {
_or: [
{
fk_from_column_id: {
eq: columnId,
},
},
{
fk_to_column_id: {
eq: columnId,
},
},
],
},
})
).length > 0
);
}
}

10
packages/nocodb/src/services/columns.service.ts

@ -25,6 +25,7 @@ import type CustomKnex from '~/db/CustomKnex';
import type SqlClient from '~/db/sql-client/lib/SqlClient';
import type { BaseModelSqlv2 } from '~/db/BaseModelSqlv2';
import type { NcRequest } from '~/interface/config';
import { CalendarRange } from '~/models';
import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import formulaQueryBuilderv2 from '~/db/formulav2/formulaQueryBuilderv2';
import ProjectMgrv2 from '~/db/sql-mgr/v2/ProjectMgrv2';
@ -2264,6 +2265,15 @@ export class ColumnsService {
}
/* falls through to default */
}
case UITypes.DateTime:
case UITypes.Date: {
if (await CalendarRange.IsColumnBeingUsedAsRange(column.id, ncMeta)) {
NcError.badRequest(
`The column '${column.column_name}' is being used in Calendar View. Please delete Calendar View first.`,
);
}
break;
}
// on deleting created/last modified columns, keep the column in table and delete the column from meta
case UITypes.CreatedTime:

Loading…
Cancel
Save