check on label metadata (#12852)

Better catching label input

- there were absolutely no check on label when creating the target field
while doing a relation : we crearted these checks here.

- We keep the label quite open to special char as discussed with Felix.
so mostly checking length of label.
  - We check that label does not already exists on the targetted object


- making sure the Target fieldinput label is checked before we create
it. The previous checks are not enough since the label goes through
anoteher merthod before going in the database

- validate-metadata-name-is-camel-case.utils.ts : making sure we can use
this error message for metadata name and for target label

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
Co-authored-by: prastoin <paul@twenty.com>
This commit is contained in:
Guillim
2025-06-24 20:20:37 +02:00
committed by GitHub
parent 02ce53bd2f
commit fb0cf11499
6 changed files with 40 additions and 15 deletions

View File

@ -1,12 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`validateMetadataNameOrThrow throw error when string is not in camel case 1`] = `"Name should be in camelCase: TestName"`;
exports[`validateMetadataNameOrThrow throw error when string is not in camel case 1`] = `"TestName should be in camelCase"`;
exports[`validateMetadataNameOrThrow throws error when starts with digits 1`] = `"Name should be in camelCase: 123string"`;
exports[`validateMetadataNameOrThrow throws error when starts with digits 1`] = `"123string should be in camelCase"`;
exports[`validateMetadataNameOrThrow throws error when string has non latin characters 1`] = `"String "בְרִבְרִ" is not valid: must start with lowercase letter and contain only alphanumeric letters"`;
exports[`validateMetadataNameOrThrow throws error when string has spaces 1`] = `"Name should be in camelCase: name with spaces"`;
exports[`validateMetadataNameOrThrow throws error when string has spaces 1`] = `"name with spaces should be in camelCase"`;
exports[`validateMetadataNameOrThrow throws error when string is a reserved word 1`] = `"The name "role" is not available"`;
@ -14,4 +14,4 @@ exports[`validateMetadataNameOrThrow throws error when string is above 63 charac
exports[`validateMetadataNameOrThrow throws error when string is empty 1`] = `"Input is too short: """`;
exports[`validateMetadataNameOrThrow throws error when string starts with capital letter 1`] = `"Name should be in camelCase: StringStartingWithCapitalLetter"`;
exports[`validateMetadataNameOrThrow throws error when string starts with capital letter 1`] = `"StringStartingWithCapitalLetter should be in camelCase"`;

View File

@ -12,6 +12,7 @@ export enum InvalidMetadataExceptionCode {
EXCEEDS_MAX_LENGTH = 'Exceeds max length',
RESERVED_KEYWORD = 'Reserved keyword',
NOT_CAMEL_CASE = 'Not camel case',
NOT_FIRST_LETTER_UPPER_CASE = 'Not first letter upper case',
INVALID_LABEL = 'Invalid label',
NAME_NOT_SYNCED_WITH_LABEL = 'Name not synced with label',
INVALID_STRING = 'Invalid string',

View File

@ -8,7 +8,7 @@ import {
export const validateMetadataNameIsCamelCaseOrThrow = (name: string) => {
if (name !== camelCase(name)) {
throw new InvalidMetadataException(
`Name should be in camelCase: ${name}`,
`${name} should be in camelCase`,
InvalidMetadataExceptionCode.NOT_CAMEL_CASE,
);
}