Browse Source

fix: check column is associated with any link before deleting

pull/8367/head
Pranav C 5 months ago
parent
commit
d967388881
  1. 1
      packages/nocodb-sdk/src/lib/globals.ts
  2. 7
      packages/nocodb/src/helpers/catchError.ts
  3. 23
      packages/nocodb/src/models/Column.ts

1
packages/nocodb-sdk/src/lib/globals.ts

@ -190,6 +190,7 @@ export enum NcErrorType {
UNKNOWN_ERROR = 'UNKNOWN_ERROR',
BAD_JSON = 'BAD_JSON',
INVALID_PK_VALUE = 'INVALID_PK_VALUE',
COLUMN_ASSOCIATED_WITH_LINK = 'COLUMN_ASSOCIATED_WITH_LINK',
}
type Roles = OrgUserRoles | ProjectRoles | WorkspaceUserRoles;

7
packages/nocodb/src/helpers/catchError.ts

@ -558,6 +558,10 @@ const errorHelpers: {
message: 'Invalid JSON in request body',
code: 400,
},
[NcErrorType.COLUMN_ASSOCIATED_WITH_LINK]: {
message: 'Column is associated with a link, please remove the link first',
code: 400,
},
};
function generateError(
@ -630,6 +634,9 @@ export class NcError {
...args,
});
}
static columnAssociatedWithLink(id: string) {
throw new NcBaseErrorv2(NcErrorType.COLUMN_ASSOCIATED_WITH_LINK);
}
static baseNotFound(id: string, args?: NcErrorArgs) {
throw new NcBaseErrorv2(NcErrorType.BASE_NOT_FOUND, {

23
packages/nocodb/src/models/Column.ts

@ -1,6 +1,7 @@
import {
AllowedColumnTypesForQrAndBarcodes,
isLinksOrLTAR,
isVirtualCol,
UITypes,
} from 'nocodb-sdk';
import { Logger } from '@nestjs/common';
@ -674,6 +675,28 @@ export default class Column<T = any> implements ColumnType {
return;
}
// check column association with any custom links or LTAR
if (!isVirtualCol(col)) {
const links = await ncMeta.metaList2(
null,
null,
MetaTable.COL_RELATIONS,
{
xcCondition: {
_or: [
{ fk_child_column_id: { eq: id } },
{ fk_parent_column_id: { eq: id } },
{ fk_mm_child_column_id: { eq: id } },
{ fk_mm_parent_column_id: { eq: id } },
],
},
},
);
if (links.length) {
NcError.columnAssociatedWithLink(id);
}
}
// todo: or instead of delete reset related foreign key value to null and handle in BaseModel
// get qr code columns and delete

Loading…
Cancel
Save