Prevent relation update from settings (#13099)

## Expected behavior

Described behavior regarding: (update | create) x (custom | standard) x
(icon, label, name, isSynced)

**Custom:**
- Field RELATION create: name, label, isSynced, icon should be editable
- Field RELATION update: name should not, icon label, isSynced should
- For other fields, icon, label, name, isSynced should be editable at
field creation | update

To simplify: Field RELATION name should not be editable at update

**Standards**
- Field: create does not makes sense
- Field: name should not, icon label, isSynced should (this will end up
in overrides)

To simplify, no Field RELATION edge case, name should not be editable at
update

**Note:** the FE logic is quite different as the UI is hiding some
details behind the syncWithLabel. See my comments and TODO there


## What I've tested:
(update | create) x (custom | standard) x (icon, label, name, isSynced,
description)
This commit is contained in:
Charles Bochet
2025-07-08 21:03:38 +02:00
committed by GitHub
parent c8ec44eeaf
commit 39f6f3c4bb
13 changed files with 615 additions and 150 deletions

View File

@ -9,10 +9,10 @@ import {
Max,
Min,
ValidationError,
isDefined,
validateOrReject,
} from 'class-validator';
import { FieldMetadataType } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { FieldMetadataSettings } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-settings.interface';
import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface';
@ -187,5 +187,20 @@ export class FieldMetadataValidationService {
settings: fieldMetadataInput.settings,
});
}
const isRelationField =
fieldMetadataType === FieldMetadataType.RELATION ||
fieldMetadataType === FieldMetadataType.MORPH_RELATION;
if (
isRelationField &&
isDefined(existingFieldMetadata) &&
fieldMetadataInput.name !== existingFieldMetadata.name
) {
throw new FieldMetadataException(
'Name cannot be changed for relation fields',
FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
);
}
}
}