fix: avoid create custom entities with the same name (#2791)
* fix: avoid create custom entities with the same name * fix: use exact spelling * fix: validate input as is
This commit is contained in:
@ -1,4 +1,8 @@
|
|||||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
import {
|
||||||
|
ForbiddenException,
|
||||||
|
Injectable,
|
||||||
|
UnauthorizedException,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
BeforeCreateOneHook,
|
BeforeCreateOneHook,
|
||||||
@ -7,6 +11,8 @@ import {
|
|||||||
|
|
||||||
import { CreateObjectInput } from 'src/metadata/object-metadata/dtos/create-object.input';
|
import { CreateObjectInput } from 'src/metadata/object-metadata/dtos/create-object.input';
|
||||||
|
|
||||||
|
const coreObjectNames = ['featureFlag', 'refreshToken', 'workspace', 'user'];
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BeforeCreateOneObject<T extends CreateObjectInput>
|
export class BeforeCreateOneObject<T extends CreateObjectInput>
|
||||||
implements BeforeCreateOneHook<T, any>
|
implements BeforeCreateOneHook<T, any>
|
||||||
@ -21,6 +27,14 @@ export class BeforeCreateOneObject<T extends CreateObjectInput>
|
|||||||
throw new UnauthorizedException();
|
throw new UnauthorizedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
coreObjectNames.includes(instance.input.nameSingular) ||
|
||||||
|
coreObjectNames.includes(instance.input.namePlural)
|
||||||
|
) {
|
||||||
|
throw new ForbiddenException(
|
||||||
|
'You cannot create an object with this name.',
|
||||||
|
);
|
||||||
|
}
|
||||||
instance.input.workspaceId = workspaceId;
|
instance.input.workspaceId = workspaceId;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user