-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUGFIX] ObjectMetadata item server validation #10699
Conversation
...ges/twenty-server/src/engine/metadata-modules/relation-metadata/relation-metadata.service.ts
Outdated
Show resolved
Hide resolved
@@ -199,7 +215,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt | |||
input: UpdateOneObjectInput, | |||
workspaceId: string, | |||
): Promise<ObjectMetadataEntity> { | |||
validateObjectMetadataInputOrThrow(input.update); | |||
validateObjectMetadataInputNamesOrThrow(input.update); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Will pass on update in an other PR
0a59f34
to
6a33e9b
Compare
8a2f744
to
cdccc57
Compare
8231668
to
f789324
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR!
FYI I had the idea of using class-validator (which is more standard with nestjs backend) with custom validation decorators over our input classes but I think with your implementation it's a bit less important, will see how it scales 👍
...metadata-modules/object-metadata/utils/__tests__/validate-object-metadata-input.util.spec.ts
Show resolved
Hide resolved
...ges/twenty-server/src/engine/metadata-modules/relation-metadata/relation-metadata.service.ts
Outdated
Show resolved
Hide resolved
...twenty-server/src/engine/metadata-modules/utils/validate-database-identifier-length.utils.ts
Outdated
Show resolved
Hide resolved
...-server/test/integration/utils/object-metadata/generate-mock-create-object-metadata-input.ts
Show resolved
Hide resolved
...ty-server/src/engine/metadata-modules/utils/exceptions/name-is-reserved-keyword.exception.ts
Outdated
Show resolved
Hide resolved
@greptileai trigger |
9560ce2
to
99ca95f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
(updates since last review)
Based on the provided information, I'll summarize the key changes in this PR focusing on the most recent updates without repeating previous points:
Enhanced server-side validation for ObjectMetadata with new utility functions:
- Added
validateMetadataNameIsCamelCaseOrThrow
to enforce camelCase naming convention - Implemented
validateMetadataNameIsNotTooShort/LongOrThrow
to enforce length constraints (1-63 chars) - Created
validateMetadataNameContainsWhitelistedCharacters
to restrict to alphanumeric characters - Introduced
validateLowerCasedAndTrimmedStringsAreDifferentOrThrow
to ensure unique singular/plural names
The changes consolidate error handling by:
- Replacing multiple specific exceptions with unified
InvalidMetadataNameException
- Improving error messages with detailed validation failure reasons
- Adding case-insensitive comparison for name uniqueness checks
These updates provide a more robust validation system while maintaining clean code organization and improved error handling.
24 file(s) reviewed, 12 comment(s)
Edit PR Review Bot Settings | Greptile
...ges/twenty-server/src/engine/metadata-modules/relation-metadata/relation-metadata.service.ts
Show resolved
Hide resolved
...ver/src/engine/metadata-modules/object-metadata/utils/validate-object-metadata-input.util.ts
Outdated
Show resolved
Hide resolved
...wenty-server/src/engine/metadata-modules/utils/exceptions/invalid-metadata-name.exception.ts
Show resolved
Hide resolved
...ges/twenty-server/src/engine/metadata-modules/utils/__tests__/validate-metadata-name.spec.ts
Show resolved
Hide resolved
...ges/twenty-server/src/engine/metadata-modules/utils/__tests__/validate-metadata-name.spec.ts
Show resolved
Hide resolved
...ngine/metadata-modules/utils/validate-metadata-name-contains-whitelisted-characters.utils.ts
Outdated
Show resolved
Hide resolved
...wenty-server/src/engine/metadata-modules/utils/validate-metadata-name-is-camel-case.utils.ts
Show resolved
Hide resolved
...ty-server/src/engine/metadata-modules/utils/validate-metadata-name-is-not-too-short.utils.ts
Show resolved
Hide resolved
...y-server/src/engine/metadata-modules/utils/validate-metadata-name-is-not-reserved-keyword.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/metadata-modules/utils/validate-metadata-name.utils.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job @prastoin!! LGTM
Introduction
This PR contains several SNAPSHOT files explaining big +
While refactoring the Object Model settings page in #10653, encountered a critical issue when submitting either one or both names with
""
empty string hard corrupting a workspace.This motivate this PR reviewing server side validation
I feel like we could share zod schema between front and back
Refactored server validation
What to expect from Names:
What to expect from Labels:
close #10694
Creation integrations tests
Created new integrations tests, following EachTesting pattern and uses snapshot to assert errors message. These tests cover several failing use cases and started to implement ones for the happy path but object metadata item deletion is currently broken unless I'm mistaken @Weiko is on it
Notes