Skip to content

The open alternative to Salesforce, designed for AI.

Reject changes to non-comparable flat entity properties (#28803)

Paul Rastoin0df696dcff83
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-object-metadata-to-object-manifest.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-object-metadata-to-object-manifest.util.spec.ts
index 9f35a96998d..0c226b8af57 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-object-metadata-to-object-manifest.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-object-metadata-to-object-manifest.util.spec.ts
@@ -66,6 +66,8 @@ describe('fromFlatObjectMetadataToObjectManifest', () => {
description: null,
icon: null,
color: 'red',
+ shortcut: null,
+ targetTableName: 'DEPRECATED',
isLabelSyncedWithName: true,
isSearchable: false,
writability: MetadataWritability.APPLICATION,
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-view-to-view-manifest.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-view-to-view-manifest.util.spec.ts
index 3aa4295c992..28b2e08c3f4 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-view-to-view-manifest.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-view-to-view-manifest.util.spec.ts
@@ -162,10 +162,10 @@ describe('fromFlatViewToViewManifest', () => {
icon: 'IconCalendar',
position: 1,
isCompact: false,
- isCustom: false,
+ isCustom: true,
visibility: ViewVisibility.WORKSPACE,
openRecordIn: ViewOpenRecordIn.SIDE_PANEL,
- key: ViewKey.INDEX,
+ key: null,
kanbanAggregateOperation: null,
kanbanAggregateOperationFieldMetadataUniversalIdentifier: null,
calendarLayout: ViewCalendarLayout.MONTH,
diff --git a/packages/twenty-server/src/engine/core-modules/workflow/services/workflow-version-core-sync.service.ts b/packages/twenty-server/src/engine/core-modules/workflow/services/workflow-version-core-sync.service.ts
index 323849f1ebe..92cc52d7e18 100644
--- a/packages/twenty-server/src/engine/core-modules/workflow/services/workflow-version-core-sync.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/workflow/services/workflow-version-core-sync.service.ts
@@ -200,6 +200,14 @@ export class WorkflowVersionCoreSyncService {
id: string;
} = {
...coreRow,
+ // Non-comparable, so an update must carry the stored values or the builder rejects it
+ ...(isDefined(existingFlatWorkflowVersion)
+ ? {
+ workflowId: existingFlatWorkflowVersion.workflowId,
+ workspaceWorkflowVersionId:
+ existingFlatWorkflowVersion.workspaceWorkflowVersionId,
+ }
+ : {}),
isSystemSideEffect: false,
coreWorkflowId:
coreRow.coreWorkflowId ??
diff --git a/packages/twenty-server/src/engine/metadata-modules/flat-entity/constant/__tests__/__snapshots__/all-universal-flat-entity-properties-to-compare-and-stringify.constant.spec.ts.snap b/packages/twenty-server/src/engine/metadata-modules/flat-entity/constant/__tests__/__snapshots__/all-universal-flat-entity-properties-to-compare-and-stringify.constant.spec.ts.snap
index 7b6e9011c4a..5e6ab98900a 100644
--- a/packages/twenty-server/src/engine/metadata-modules/flat-entity/constant/__tests__/__snapshots__/all-universal-flat-entity-properties-to-compare-and-stringify.constant.spec.ts.snap
+++ b/packages/twenty-server/src/engine/metadata-modules/flat-entity/constant/__tests__/__snapshots__/all-universal-flat-entity-properties-to-compare-and-stringify.constant.spec.ts.snap
@@ -223,6 +223,7 @@ exports[`ALL_UNIVERSAL_FLAT_ENTITY_PROPERTIES_TO_COMPARE_AND_STRINGIFY should ma
"propertiesToStringify": [
"overrides",
"readabilityParentFieldUniversalIdentifiers",
+ "duplicateCriteria",
],
},
"objectPermission": {
@@ -276,6 +277,7 @@ exports[`ALL_UNIVERSAL_FLAT_ENTITY_PROPERTIES_TO_COMPARE_AND_STRINGIFY should ma
"universalOverrides",
],
"propertiesToStringify": [
+ "gridPosition",
"position",
"universalConfiguration",
"conditionalDisplay",
diff --git a/packages/twenty-server/src/engine/metadata-modules/flat-entity/constant/all-entity-properties-configuration-by-metadata-name.constant.ts b/packages/twenty-server/src/engine/metadata-modules/flat-entity/constant/all-entity-properties-configuration-by-metadata-name.constant.ts
index 543d3213985..6f42a61a19a 100644
--- a/packages/twenty-server/src/engine/metadata-modules/flat-entity/constant/all-entity-properties-configuration-by-metadata-name.constant.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/flat-entity/constant/all-entity-properties-configuration-by-metadata-name.constant.ts
@@ -1854,7 +1854,7 @@ export const ALL_ENTITY_PROPERTIES_CONFIGURATION_BY_METADATA_NAME = {
},
value: {
toCompare: false,
- toStringify: true,
+ toStringify: false,
universalProperty: undefined,
},
description: {
diff --git a/packages/twenty-server/src/engine/metadata-modules/flat-entity/constant/all-universal-flat-entity-properties-to-compare-and-stringify.constant.ts b/packages/twenty-server/src/engine/metadata-modules/flat-entity/constant/all-universal-flat-entity-properties-to-compare-and-stringify.constant.ts
index 89d3ca3e0c6..2dcac381e23 100644
--- a/packages/twenty-server/src/engine/metadata-modules/flat-entity/constant/all-universal-flat-entity-properties-to-compare-and-stringify.constant.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/flat-entity/constant/all-universal-flat-entity-properties-to-compare-and-stringify.constant.ts
@@ -53,18 +53,17 @@ const computeUniversalFlatEntityPropertiesToCompareAndStringify = <
};
for (const [property, configuration] of entries) {
- if (!configuration.toCompare) {
- continue;
- }
+ const universalProperty = configuration.universalProperty ?? property;
- const comparedProperty = configuration.universalProperty ?? property;
+ if (configuration.toCompare) {
+ accumulator.propertiesToCompare.push(
+ universalProperty as MetadataUniversalFlatEntityPropertiesToCompare<T>,
+ );
+ }
- accumulator.propertiesToCompare.push(
- comparedProperty as MetadataUniversalFlatEntityPropertiesToCompare<T>,
- );
if (configuration.toStringify === true) {
accumulator.propertiesToStringify.push(
- comparedProperty as MetadataUniversalFlatEntityPropertiesToStringify<T>,
+ universalProperty as MetadataUniversalFlatEntityPropertiesToStringify<T>,
);
}
}
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/metadata-universal-flat-entity-properties-to-stringify.type.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/metadata-universal-flat-entity-properties-to-stringify.type.ts
index 7edb04a688b..e48c348bb6d 100644
--- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/metadata-universal-flat-entity-properties-to-stringify.type.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/metadata-universal-flat-entity-properties-to-stringify.type.ts
@@ -2,14 +2,12 @@ import { type AllMetadataName } from 'twenty-shared/metadata';
import { type ALL_ENTITY_PROPERTIES_CONFIGURATION_BY_METADATA_NAME } from 'src/engine/metadata-modules/flat-entity/constant/all-entity-properties-configuration-by-metadata-name.constant';
-type ExtractComparableKeysWithToStringify<T> = {
- [K in keyof T]: T[K] extends { toCompare: true; toStringify: true }
- ? K
- : never;
+type ExtractKeysWithToStringify<T> = {
+ [K in keyof T]: T[K] extends { toStringify: true } ? K : never;
}[keyof T];
export type MetadataUniversalFlatEntityPropertiesToStringify<
T extends AllMetadataName,
-> = ExtractComparableKeysWithToStringify<
+> = ExtractKeysWithToStringify<
(typeof ALL_ENTITY_PROPERTIES_CONFIGURATION_BY_METADATA_NAME)[T]
>;
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/__tests__/__snapshots__/compare-two-universal-flat-entity.util.spec.ts.snap b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/__tests__/__snapshots__/compare-two-universal-flat-entity.util.spec.ts.snap
index ad7ebb16d01..d71983e30fc 100644
--- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/__tests__/__snapshots__/compare-two-universal-flat-entity.util.spec.ts.snap
+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/__tests__/__snapshots__/compare-two-universal-flat-entity.util.spec.ts.snap
@@ -2,12 +2,18 @@
exports[`compareTwoFlatEntity It should detect flat field metadata isActive diff from true to false 1`] = `
{
- "isActive": false,
+ "nonUpdatablePropertyDivergences": [],
+ "update": {
+ "isActive": false,
+ },
}
`;
exports[`compareTwoFlatEntity It should detect flat field metadata isActive diff from true to false 2`] = `
{
- "isActive": true,
+ "nonUpdatablePropertyDivergences": [],
+ "update": {
+ "isActive": true,
+ },
}
`;
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/__tests__/__snapshots__/universal-flat-entity-deleted-created-updated-matrix-dispatcher.util.spec.ts.snap b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/__tests__/__snapshots__/universal-flat-entity-deleted-created-updated-matrix-dispatcher.util.spec.ts.snap
index 027a0d15760..413b60d3a76 100644
--- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/__tests__/__snapshots__/universal-flat-entity-deleted-created-updated-matrix-dispatcher.util.spec.ts.snap
+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/__tests__/__snapshots__/universal-flat-entity-deleted-created-updated-matrix-dispatcher.util.spec.ts.snap
@@ -149,6 +149,7 @@ exports[`flatEntityDeletedCreatedUpdatedMatrixDispatcher It should detect an upd
"updatedFlatEntityMaps": {
"byUniversalIdentifier": {
"universal-identifier-1": {
+ "nonUpdatablePropertyDivergences": [],
"update": {
"isActive": true,
},
@@ -279,6 +280,7 @@ exports[`flatEntityDeletedCreatedUpdatedMatrixDispatcher It should detect create
"updatedFlatEntityMaps": {
"byUniversalIdentifier": {
"universal-identifier-1": {
+ "nonUpdatablePropertyDivergences": [],
"update": {
"isActive": false,
},
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/__tests__/compare-two-universal-flat-entity.util.spec.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/__tests__/compare-two-universal-flat-entity.util.spec.ts
index c0426a156ce..0afc2c36542 100644
--- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/__tests__/compare-two-universal-flat-entity.util.spec.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/__tests__/compare-two-universal-flat-entity.util.spec.ts
@@ -4,12 +4,54 @@ import {
eachTestingContextFilter,
type EachTestingContext,
} from 'twenty-shared/testing';
-import { FieldMetadataType, type FromTo } from 'twenty-shared/types';
+import {
+ FieldMetadataType,
+ type FromTo,
+ PageLayoutTabLayoutMode,
+} from 'twenty-shared/types';
+import { fromApplicationVariableManifestToUniversalFlatApplicationVariable } from 'src/engine/core-modules/application/application-manifest/converters/from-application-variable-manifest-to-universal-flat-application-variable.util';
+import { fromPageLayoutTabManifestToUniversalFlatPageLayoutTab } from 'src/engine/core-modules/application/application-manifest/converters/from-page-layout-tab-manifest-to-universal-flat-page-layout-tab.util';
+import { type EncryptedString } from 'src/engine/core-modules/secret-encryption/branded-strings/encrypted-string.type';
import { type MetadataUniversalFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/metadata-universal-flat-entity.type';
import { getFlatFieldMetadataMock } from 'src/engine/metadata-modules/flat-field-metadata/__mocks__/get-flat-field-metadata.mock';
import { compareTwoFlatEntity } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/compare-two-universal-flat-entity.util';
+const NOW = '2026-01-01T00:00:00.000Z';
+const APPLICATION_UNIVERSAL_IDENTIFIER = 'application-universal-identifier';
+
+const buildPageLayoutTab = ({
+ pageLayoutUniversalIdentifier,
+ title = 'Overview',
+ now = NOW,
+}: {
+ pageLayoutUniversalIdentifier: string;
+ title?: string;
+ now?: string;
+}) =>
+ fromPageLayoutTabManifestToUniversalFlatPageLayoutTab({
+ pageLayoutTabManifest: {
+ universalIdentifier: 'page-layout-tab-universal-identifier',
+ title,
+ position: 0,
+ layoutMode: PageLayoutTabLayoutMode.GRID,
+ widgets: [],
+ },
+ pageLayoutUniversalIdentifier,
+ applicationUniversalIdentifier: APPLICATION_UNIVERSAL_IDENTIFIER,
+ now,
+ });
+
+const buildApplicationVariable = ({ isSecret }: { isSecret: boolean }) =>
+ fromApplicationVariableManifestToUniversalFlatApplicationVariable({
+ key: 'API_KEY',
+ universalIdentifier: 'application-variable-universal-identifier',
+ defaultValue: null,
+ isSecret,
+ applicationUniversalIdentifier: APPLICATION_UNIVERSAL_IDENTIFIER,
+ now: NOW,
+ });
+
type TestContext<T extends AllMetadataName = AllMetadataName> = FromTo<
MetadataUniversalFlatEntity<T>,
'universalFlatEntity'
@@ -23,6 +65,8 @@ describe('compareTwoFlatEntity', () => {
context: {
fromUniversalFlatEntity: getFlatFieldMetadataMock({
objectMetadataId: 'object-metadata-id',
+ objectMetadataUniversalIdentifier:
+ 'object-metadata-universal-identifier',
type: FieldMetadataType.TEXT,
universalIdentifier: 'universal-identifier',
isActive: true,
@@ -30,6 +74,8 @@ describe('compareTwoFlatEntity', () => {
metadataName: 'fieldMetadata',
toUniversalFlatEntity: getFlatFieldMetadataMock({
objectMetadataId: 'object-metadata-id',
+ objectMetadataUniversalIdentifier:
+ 'object-metadata-universal-identifier',
type: FieldMetadataType.TEXT,
universalIdentifier: 'universal-identifier',
isActive: false,
@@ -42,6 +88,8 @@ describe('compareTwoFlatEntity', () => {
context: {
fromUniversalFlatEntity: getFlatFieldMetadataMock({
objectMetadataId: 'object-metadata-id',
+ objectMetadataUniversalIdentifier:
+ 'object-metadata-universal-identifier',
type: FieldMetadataType.TEXT,
universalIdentifier: 'universal-identifier',
isActive: false,
@@ -49,6 +97,8 @@ describe('compareTwoFlatEntity', () => {
metadataName: 'fieldMetadata',
toUniversalFlatEntity: getFlatFieldMetadataMock({
objectMetadataId: 'object-metadata-id',
+ objectMetadataUniversalIdentifier:
+ 'object-metadata-universal-identifier',
type: FieldMetadataType.TEXT,
universalIdentifier: 'universal-identifier',
isActive: true,
@@ -73,4 +123,78 @@ describe('compareTwoFlatEntity', () => {
);
},
);
+
+ describe('non-updatable property divergences', () => {
+ it('should report a page layout tab moved to another page layout', () => {
+ expect(
+ compareTwoFlatEntity({
+ fromUniversalFlatEntity: buildPageLayoutTab({
+ pageLayoutUniversalIdentifier: 'page-layout-a',
+ }),
+ toUniversalFlatEntity: buildPageLayoutTab({
+ pageLayoutUniversalIdentifier: 'page-layout-b',
+ }),
+ metadataName: 'pageLayoutTab',
+ }),
+ ).toEqual({
+ update: {},
+ nonUpdatablePropertyDivergences: ['pageLayoutUniversalIdentifier'],
+ });
+ });
+
+ it.each([
+ { fromIsSecret: true, toIsSecret: false },
+ { fromIsSecret: false, toIsSecret: true },
+ ])(
+ 'should report an application variable isSecret change from $fromIsSecret to $toIsSecret',
+ ({ fromIsSecret, toIsSecret }) => {
+ expect(
+ compareTwoFlatEntity({
+ fromUniversalFlatEntity: buildApplicationVariable({
+ isSecret: fromIsSecret,
+ }),
+ toUniversalFlatEntity: buildApplicationVariable({
+ isSecret: toIsSecret,
+ }),
+ metadataName: 'applicationVariable',
+ }),
+ ).toEqual({
+ update: {},
+ nonUpdatablePropertyDivergences: ['isSecret'],
+ });
+ },
+ );
+
+ it('should ignore a stored value the incoming entity does not define', () => {
+ expect(
+ compareTwoFlatEntity({
+ fromUniversalFlatEntity: {
+ ...buildApplicationVariable({ isSecret: true }),
+ value: 'enc:v2:stored' as EncryptedString,
+ },
+ toUniversalFlatEntity: buildApplicationVariable({ isSecret: true }),
+ metadataName: 'applicationVariable',
+ }),
+ ).toBeUndefined();
+ });
+
+ it('should ignore server-managed timestamps', () => {
+ expect(
+ compareTwoFlatEntity({
+ fromUniversalFlatEntity: buildPageLayoutTab({
+ pageLayoutUniversalIdentifier: 'page-layout-a',
+ }),
+ toUniversalFlatEntity: buildPageLayoutTab({
+ pageLayoutUniversalIdentifier: 'page-layout-a',
+ title: 'Renamed',
+ now: '2027-01-01T00:00:00.000Z',
+ }),
+ metadataName: 'pageLayoutTab',
+ }),
+ ).toEqual({
+ update: { title: 'Renamed' },
+ nonUpdatablePropertyDivergences: [],
+ });
+ });
+ });
});
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/compare-two-universal-flat-entity.util.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/compare-two-universal-flat-entity.util.ts
index b2ed47fbb50..1c07d932914 100644
--- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/compare-two-universal-flat-entity.util.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/compare-two-universal-flat-entity.util.ts
@@ -1,78 +1,67 @@
-import diff from 'microdiff';
import { type AllMetadataName } from 'twenty-shared/metadata';
import { type FromTo } from 'twenty-shared/types';
-import { parseJson } from 'twenty-shared/utils';
+import { isEmptyObject } from 'twenty-shared/utils';
+import { ALL_ENTITY_PROPERTIES_CONFIGURATION_BY_METADATA_NAME } from 'src/engine/metadata-modules/flat-entity/constant/all-entity-properties-configuration-by-metadata-name.constant';
import { ALL_UNIVERSAL_FLAT_ENTITY_PROPERTIES_TO_COMPARE_AND_STRINGIFY } from 'src/engine/metadata-modules/flat-entity/constant/all-universal-flat-entity-properties-to-compare-and-stringify.constant';
import { type MetadataUniversalFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/metadata-universal-flat-entity.type';
-import { type MetadataUniversalFlatEntityPropertiesToStringify } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/metadata-universal-flat-entity-properties-to-stringify.type';
import { type UniversalFlatEntityUpdate } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-entity-update.type';
-import { transformUniversalFlatEntityForComparison } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/transform-universal-flat-entity-for-comparison.util';
+import { diffUniversalFlatEntityProperties } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/diff-universal-flat-entity-properties.util';
+
+const SERVER_MANAGED_PROPERTIES = new Set(['createdAt', 'updatedAt']);
type CompareTwoUniversalFlatEntityArgs<T extends AllMetadataName> = FromTo<
MetadataUniversalFlatEntity<T>,
'universalFlatEntity'
> & { metadataName: T };
+export type UniversalFlatEntityComparison<T extends AllMetadataName> = {
+ update: UniversalFlatEntityUpdate<T>;
+ nonUpdatablePropertyDivergences: string[];
+};
+
export const compareTwoFlatEntity = <T extends AllMetadataName>({
fromUniversalFlatEntity,
toUniversalFlatEntity,
metadataName,
}: CompareTwoUniversalFlatEntityArgs<T>):
- | UniversalFlatEntityUpdate<T>
+ | UniversalFlatEntityComparison<T>
| undefined => {
- const { propertiesToStringify, propertiesToCompare } =
- ALL_UNIVERSAL_FLAT_ENTITY_PROPERTIES_TO_COMPARE_AND_STRINGIFY[metadataName];
+ const update: UniversalFlatEntityUpdate<T> =
+ diffUniversalFlatEntityProperties({
+ fromUniversalFlatEntity,
+ toUniversalFlatEntity,
+ metadataName,
+ properties:
+ ALL_UNIVERSAL_FLAT_ENTITY_PROPERTIES_TO_COMPARE_AND_STRINGIFY[
+ metadataName
+ ].propertiesToCompare,
+ });
- const [transformedFromUniversalFlatEntity, transformedToUniversalFlatEntity] =
- [fromUniversalFlatEntity, toUniversalFlatEntity].map(
- (universalFlatEntity) =>
- transformUniversalFlatEntityForComparison({
- metadataName,
- universalFlatEntity,
- propertiesToCompare,
- propertiesToStringify,
- }),
+ const nonComparableProperties = Object.entries(
+ ALL_ENTITY_PROPERTIES_CONFIGURATION_BY_METADATA_NAME[metadataName],
+ )
+ .filter(
+ ([property, { toCompare }]) =>
+ !toCompare && !SERVER_MANAGED_PROPERTIES.has(property),
+ )
+ .map(
+ ([property, { universalProperty }]) =>
+ (universalProperty ?? property) as keyof MetadataUniversalFlatEntity<T>,
);
- const flatEntityDifferences = diff(
- transformedFromUniversalFlatEntity,
- transformedToUniversalFlatEntity,
+ const nonUpdatablePropertyDivergences = Object.keys(
+ diffUniversalFlatEntityProperties({
+ fromUniversalFlatEntity,
+ toUniversalFlatEntity,
+ metadataName,
+ properties: nonComparableProperties,
+ }),
);
- if (flatEntityDifferences.length === 0) {
+ if (isEmptyObject(update) && nonUpdatablePropertyDivergences.length === 0) {
return undefined;
}
- const initialAccumulator: UniversalFlatEntityUpdate<T> = {};
-
- return flatEntityDifferences.reduce((accumulator, difference) => {
- switch (difference.type) {
- case 'CHANGE': {
- const { path, value } = difference;
- const property = path[0];
- const isJsonb = propertiesToStringify.includes(
- property as MetadataUniversalFlatEntityPropertiesToStringify<T>,
- );
-
- if (isJsonb) {
- return {
- ...accumulator,
- [property]: parseJson(value),
- };
- }
-
- return {
- ...accumulator,
- [property]: value,
- };
- }
- case 'CREATE':
- case 'REMOVE':
- default: {
- // Should never occur, we should only provide null never undefined and so on
- return accumulator;
- }
- }
- }, initialAccumulator);
+ return { update, nonUpdatablePropertyDivergences };
};
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/diff-universal-flat-entity-properties.util.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/diff-universal-flat-entity-properties.util.ts
new file mode 100644
index 00000000000..2cccc5d0ece
--- /dev/null
+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/diff-universal-flat-entity-properties.util.ts
@@ -0,0 +1,53 @@
+import { isUndefined } from '@sniptt/guards';
+import diff from 'microdiff';
+import { type AllMetadataName } from 'twenty-shared/metadata';
+import { type FromTo } from 'twenty-shared/types';
+import { parseJson } from 'twenty-shared/utils';
+
+import { ALL_UNIVERSAL_FLAT_ENTITY_PROPERTIES_TO_COMPARE_AND_STRINGIFY } from 'src/engine/metadata-modules/flat-entity/constant/all-universal-flat-entity-properties-to-compare-and-stringify.constant';
+import { type MetadataUniversalFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/metadata-universal-flat-entity.type';
+import { type MetadataUniversalFlatEntityPropertiesToStringify } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/metadata-universal-flat-entity-properties-to-stringify.type';
+import { transformUniversalFlatEntityForComparison } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/transform-universal-flat-entity-for-comparison.util';
+
+// An undefined incoming property (removed column, workspace-owned value) is not part of the change
+export const diffUniversalFlatEntityProperties = <T extends AllMetadataName>({
+ fromUniversalFlatEntity,
+ toUniversalFlatEntity,
+ metadataName,
+ properties,
+}: FromTo<MetadataUniversalFlatEntity<T>, 'universalFlatEntity'> & {
+ metadataName: T;
+ properties: (keyof MetadataUniversalFlatEntity<T>)[];
+}): Partial<MetadataUniversalFlatEntity<T>> => {
+ const { propertiesToStringify } =
+ ALL_UNIVERSAL_FLAT_ENTITY_PROPERTIES_TO_COMPARE_AND_STRINGIFY[metadataName];
+
+ const [transformedFromUniversalFlatEntity, transformedToUniversalFlatEntity] =
+ [fromUniversalFlatEntity, toUniversalFlatEntity].map(
+ (universalFlatEntity) =>
+ transformUniversalFlatEntityForComparison({
+ metadataName,
+ universalFlatEntity,
+ propertiesToCompare: properties.filter(
+ (property) => !isUndefined(toUniversalFlatEntity[property]),
+ ),
+ propertiesToStringify,
+ }) as Record<string, unknown>,
+ );
+
+ return diff(
+ transformedFromUniversalFlatEntity,
+ transformedToUniversalFlatEntity,
+ ).reduce((accumulator, { path }) => {
+ const property = String(path[0]);
+ const value = transformedToUniversalFlatEntity[property];
+ const isJsonb = propertiesToStringify.includes(
+ property as MetadataUniversalFlatEntityPropertiesToStringify<T>,
+ );
+
+ return {
+ ...accumulator,
+ [property]: isJsonb ? parseJson(value as string) : value,
+ };
+ }, {});
+};
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/transform-universal-flat-entity-for-comparison.util.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/transform-universal-flat-entity-for-comparison.util.ts
index a081907d5f0..9b6a2630988 100644
--- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/transform-universal-flat-entity-for-comparison.util.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/transform-universal-flat-entity-for-comparison.util.ts
@@ -2,7 +2,6 @@ import { type AllMetadataName } from 'twenty-shared/metadata';
import { type MetadataUniversalFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/metadata-universal-flat-entity.type';
import { orderObjectProperties } from 'src/engine/metadata-modules/flat-entity/utils/order-object-properties.util';
-import { type MetadataUniversalFlatEntityPropertiesToCompare } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/metadata-universal-flat-entity-properties-to-compare.type';
import { type MetadataUniversalFlatEntityPropertiesToStringify } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/metadata-universal-flat-entity-properties-to-stringify.type';
export function transformUniversalFlatEntityForComparison<
@@ -15,7 +14,7 @@ export function transformUniversalFlatEntityForComparison<
}: {
metadataName: T;
universalFlatEntity: MetadataUniversalFlatEntity<T>;
- propertiesToCompare: MetadataUniversalFlatEntityPropertiesToCompare<T>[];
+ propertiesToCompare: (keyof MetadataUniversalFlatEntity<T>)[];
propertiesToStringify: MetadataUniversalFlatEntityPropertiesToStringify<T>[];
}) {
return propertiesToCompare.reduce(
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/universal-flat-entity-deleted-created-updated-matrix-dispatcher.util.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/universal-flat-entity-deleted-created-updated-matrix-dispatcher.util.ts
index 29639079df0..70d879cd011 100644
--- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/universal-flat-entity-deleted-created-updated-matrix-dispatcher.util.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/universal-flat-entity-deleted-created-updated-matrix-dispatcher.util.ts
@@ -4,8 +4,10 @@ import { isDefined } from 'twenty-shared/utils';
import { type MetadataUniversalFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/metadata-universal-flat-entity.type';
import { type MetadataUniversalFlatEntityMaps } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/metadata-universal-flat-entity-maps.type';
-import { type UniversalFlatEntityUpdate } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-entity-update.type';
-import { compareTwoFlatEntity } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/compare-two-universal-flat-entity.util';
+import {
+ compareTwoFlatEntity,
+ type UniversalFlatEntityComparison,
+} from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/compare-two-universal-flat-entity.util';
import { addUniversalFlatEntityToUniversalFlatEntityMapsThroughMutationOrThrow } from 'src/engine/workspace-manager/workspace-migration/utils/add-universal-flat-entity-to-universal-flat-entity-maps-through-mutation-or-throw.util';
import { shouldInferDeletionFromMissingEntities } from 'src/engine/workspace-manager/workspace-migration/utils/should-infer-deletion-from-missing-entities.util';
import { type WorkspaceMigrationBuilderOptions } from 'src/engine/workspace-manager/workspace-migration/workspace-migration-builder/types/workspace-migration-builder-options.type';
@@ -14,12 +16,7 @@ export type DeletedCreatedUpdatedMatrix<T extends AllMetadataName> = {
createdFlatEntityMaps: MetadataUniversalFlatEntityMaps<T>;
deletedFlatEntityMaps: MetadataUniversalFlatEntityMaps<T>;
updatedFlatEntityMaps: {
- byUniversalIdentifier: Record<
- string,
- {
- update: UniversalFlatEntityUpdate<T>;
- }
- >;
+ byUniversalIdentifier: Record<string, UniversalFlatEntityComparison<T>>;
};
};
@@ -81,21 +78,19 @@ export const flatEntityDeletedCreatedUpdatedMatrixDispatcher = <
if (!isDefined(toUniversalFlatEntity)) {
continue;
}
- const update = compareTwoFlatEntity({
+ const comparison = compareTwoFlatEntity({
fromUniversalFlatEntity,
toUniversalFlatEntity,
metadataName,
});
- if (!isDefined(update)) {
+ if (!isDefined(comparison)) {
continue;
}
initialDispatcher.updatedFlatEntityMaps.byUniversalIdentifier[
fromUniversalFlatEntity.universalIdentifier
- ] = {
- update,
- };
+ ] = comparison;
}
return initialDispatcher;
diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-builder/services/workspace-entity-migration-builder.service.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-builder/services/workspace-entity-migration-builder.service.ts
index d60bec41c8b..f7eb9619b61 100644
--- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-builder/services/workspace-entity-migration-builder.service.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-builder/services/workspace-entity-migration-builder.service.ts
@@ -1,5 +1,6 @@
import { Inject } from '@nestjs/common';
+import { msg } from '@lingui/core/macro';
import {
isValidUniversalIdentifier,
MINIMUM_UNIVERSAL_IDENTIFIER_UUID_VERSION,
@@ -341,9 +342,27 @@ export abstract class WorkspaceEntityMigrationBuilderService<
additionalCacheDataMaps,
universalIdentifier: flatEntityToUpdateUniversalIdentifier,
});
+ const divergenceErrors = this.validateNoNonUpdatablePropertyDivergence(
+ flatEntityUpdate.nonUpdatablePropertyDivergences,
+ );
if (validationResult.status === 'fail') {
- allValidationResult.push(validationResult);
+ allValidationResult.push({
+ ...validationResult,
+ errors: [...validationResult.errors, ...divergenceErrors],
+ });
+ continue;
+ }
+
+ if (divergenceErrors.length > 0) {
+ allValidationResult.push({
+ flatEntityMinimalInformation: {
+ universalIdentifier: flatEntityToUpdateUniversalIdentifier,
+ } as Partial<MetadataFlatEntity<T>>,
+ errors: divergenceErrors,
+ metadataName: this.metadataName,
+ type: 'update',
+ });
continue;
}
@@ -476,6 +495,16 @@ export abstract class WorkspaceEntityMigrationBuilderService<
});
}
+ private validateNoNonUpdatablePropertyDivergence(
+ nonUpdatablePropertyDivergences: string[],
+ ): FlatEntityValidationError[] {
+ return nonUpdatablePropertyDivergences.map((property) => ({
+ code: 'NON_UPDATABLE_PROPERTY_DIVERGENCE',
+ message: `${this.metadataName} property "${property}" cannot be updated`,
+ userFriendlyMessage: msg`Property ${property} cannot be updated`,
+ }));
+ }
+
private validateUniversalIdentifier({
flatEntityToValidate: { universalIdentifier },
}: UniversalFlatEntityValidationArgs<T>): FlatEntityValidationError[] {
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/application-variable-is-secret-manifest-sync.integration-spec.ts.snap b/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/application-variable-is-secret-manifest-sync.integration-spec.ts.snap
new file mode 100644
index 00000000000..e09ad52ef52
--- /dev/null
+++ b/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/application-variable-is-secret-manifest-sync.integration-spec.ts.snap
@@ -0,0 +1,69 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Manifest sync - variable isSecret should refuse changing isSecret of application variable PUBLIC_SETTING 1`] = `
+{
+ "extensions": {
+ "code": "METADATA_VALIDATION_FAILED",
+ "errors": {
+ "applicationVariable": [
+ {
+ "errors": [
+ {
+ "code": "NON_UPDATABLE_PROPERTY_DIVERGENCE",
+ "message": "applicationVariable property "isSecret" cannot be updated",
+ "userFriendlyMessage": "Property isSecret cannot be updated",
+ },
+ ],
+ "flatEntityMinimalInformation": {
+ "universalIdentifier": Any<String>,
+ },
+ "metadataName": "applicationVariable",
+ "type": "update",
+ },
+ ],
+ },
+ "message": "Validation failed for 1 applicationVariable",
+ "summary": {
+ "applicationVariable": 1,
+ "totalErrors": 1,
+ },
+ "userFriendlyMessage": "Property isSecret cannot be updated",
+ },
+ "message": "Validation errors occurred while syncing application manifest metadata",
+ "name": "GraphQLError",
+}
+`;
+
+exports[`Manifest sync - variable isSecret should refuse changing isSecret of application variable SECRET_SETTING 1`] = `
+{
+ "extensions": {
+ "code": "METADATA_VALIDATION_FAILED",
+ "errors": {
+ "applicationVariable": [
+ {
+ "errors": [
+ {
+ "code": "NON_UPDATABLE_PROPERTY_DIVERGENCE",
+ "message": "applicationVariable property "isSecret" cannot be updated",
+ "userFriendlyMessage": "Property isSecret cannot be updated",
+ },
+ ],
+ "flatEntityMinimalInformation": {
+ "universalIdentifier": Any<String>,
+ },
+ "metadataName": "applicationVariable",
+ "type": "update",
+ },
+ ],
+ },
+ "message": "Validation failed for 1 applicationVariable",
+ "summary": {
+ "applicationVariable": 1,
+ "totalErrors": 1,
+ },
+ "userFriendlyMessage": "Property isSecret cannot be updated",
+ },
+ "message": "Validation errors occurred while syncing application manifest metadata",
+ "name": "GraphQLError",
+}
+`;
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/failing-sync-application-page-layout-tab-reparent.integration-spec.ts.snap b/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/failing-sync-application-page-layout-tab-reparent.integration-spec.ts.snap
new file mode 100644
index 00000000000..16ccbdfb21e
--- /dev/null
+++ b/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/failing-sync-application-page-layout-tab-reparent.integration-spec.ts.snap
@@ -0,0 +1,35 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Manifest sync should refuse moving a page layout tab to another page layout should keep the tab on its original page layout 1`] = `
+{
+ "extensions": {
+ "code": "METADATA_VALIDATION_FAILED",
+ "errors": {
+ "pageLayoutTab": [
+ {
+ "errors": [
+ {
+ "code": "NON_UPDATABLE_PROPERTY_DIVERGENCE",
+ "message": "pageLayoutTab property "pageLayoutUniversalIdentifier" cannot be updated",
+ "userFriendlyMessage": "Property pageLayoutUniversalIdentifier cannot be updated",
+ },
+ ],
+ "flatEntityMinimalInformation": {
+ "universalIdentifier": Any<String>,
+ },
+ "metadataName": "pageLayoutTab",
+ "type": "update",
+ },
+ ],
+ },
+ "message": "Validation failed for 1 pageLayoutTab",
+ "summary": {
+ "pageLayoutTab": 1,
+ "totalErrors": 1,
+ },
+ "userFriendlyMessage": "Property pageLayoutUniversalIdentifier cannot be updated",
+ },
+ "message": "Validation errors occurred while syncing application manifest metadata",
+ "name": "GraphQLError",
+}
+`;
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/failing-sync-application-search-vector-identifier-hijack.integration-spec.ts.snap b/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/failing-sync-application-search-vector-identifier-hijack.integration-spec.ts.snap
index e305ba99e8b..6bf709276d5 100644
--- a/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/failing-sync-application-search-vector-identifier-hijack.integration-spec.ts.snap
+++ b/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/failing-sync-application-search-vector-identifier-hijack.integration-spec.ts.snap
@@ -19,6 +19,16 @@ exports[`Sync application should reject hijacking the searchVector system field
"userFriendlyMessage": "Field type TS_VECTOR must have SYSTEM writability",
"value": "OPEN",
},
+ {
+ "code": "NON_UPDATABLE_PROPERTY_DIVERGENCE",
+ "message": "fieldMetadata property "isSystemSideEffect" cannot be updated",
+ "userFriendlyMessage": "Property isSystemSideEffect cannot be updated",
+ },
+ {
+ "code": "NON_UPDATABLE_PROPERTY_DIVERGENCE",
+ "message": "fieldMetadata property "isSystem" cannot be updated",
+ "userFriendlyMessage": "Property isSystem cannot be updated",
+ },
],
"flatEntityMinimalInformation": {
"name": "searchVector",
@@ -143,6 +153,21 @@ exports[`Sync application should reject hijacking the searchVector system field
"userFriendlyMessage": "Field type TS_VECTOR must have SYSTEM writability",
"value": "OPEN",
},
+ {
+ "code": "NON_UPDATABLE_PROPERTY_DIVERGENCE",
+ "message": "fieldMetadata property "isSystemSideEffect" cannot be updated",
+ "userFriendlyMessage": "Property isSystemSideEffect cannot be updated",
+ },
+ {
+ "code": "NON_UPDATABLE_PROPERTY_DIVERGENCE",
+ "message": "fieldMetadata property "type" cannot be updated",
+ "userFriendlyMessage": "Property type cannot be updated",
+ },
+ {
+ "code": "NON_UPDATABLE_PROPERTY_DIVERGENCE",
+ "message": "fieldMetadata property "isSystem" cannot be updated",
+ "userFriendlyMessage": "Property isSystem cannot be updated",
+ },
],
"flatEntityMinimalInformation": {
"name": "stolenSearchVector",
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/application-variable-is-secret-manifest-sync.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/application-variable-is-secret-manifest-sync.integration-spec.ts
index db3cb350fc8..e0b3708f2a5 100644
--- a/packages/twenty-server/test/integration/metadata/suites/application/application-variable-is-secret-manifest-sync.integration-spec.ts
+++ b/packages/twenty-server/test/integration/metadata/suites/application/application-variable-is-secret-manifest-sync.integration-spec.ts
@@ -1,5 +1,6 @@
import crypto from 'crypto';
+import { expectOneNotInternalServerErrorSnapshot } from 'test/integration/graphql/utils/expect-one-not-internal-server-error-snapshot.util';
import { buildBaseManifest } from 'test/integration/metadata/suites/application/utils/build-base-manifest.util';
import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';
import { setupApplicationForSync } from 'test/integration/metadata/suites/application/utils/setup-application-for-sync.util';
@@ -90,6 +91,14 @@ const readVariablesByKey = async () => {
);
};
+const buildExpectedVariablesByKey = (description: string) =>
+ Object.fromEntries(
+ Object.entries(INITIAL_IS_SECRET_BY_KEY).map(([key, isSecret]) => [
+ key,
+ { description, isSecret },
+ ]),
+ );
+
describe('Manifest sync - variable isSecret', () => {
beforeAll(async () => {
await setupApplicationForSync({
@@ -114,12 +123,32 @@ describe('Manifest sync - variable isSecret', () => {
});
});
- it('should ignore isSecret changes on existing variables', async () => {
+ it.each([
+ { key: 'SECRET_SETTING', isSecret: false },
+ { key: 'PUBLIC_SETTING', isSecret: true },
+ ] as const)(
+ 'should refuse changing isSecret of application variable $key',
+ async ({ key, isSecret }) => {
+ const { errors } = await syncApplication({
+ manifest: buildManifest({
+ isSecretByKey: { ...INITIAL_IS_SECRET_BY_KEY, [key]: isSecret },
+ description: 'Initial description',
+ }),
+ expectToFail: true,
+ });
+
+ expectOneNotInternalServerErrorSnapshot({ errors });
+ expect(await readVariablesByKey()).toEqual(
+ buildExpectedVariablesByKey('Initial description'),
+ );
+ },
+ );
+
+ it('should ignore isSecret changes on server variables', async () => {
await syncApplication({
manifest: buildManifest({
isSecretByKey: {
- SECRET_SETTING: false,
- PUBLIC_SETTING: true,
+ ...INITIAL_IS_SECRET_BY_KEY,
SECRET_SERVER_KEY: false,
PUBLIC_SERVER_KEY: true,
},
@@ -129,12 +158,7 @@ describe('Manifest sync - variable isSecret', () => {
});
expect(await readVariablesByKey()).toEqual(
- Object.fromEntries(
- Object.entries(INITIAL_IS_SECRET_BY_KEY).map(([key, isSecret]) => [
- key,
- { description: 'Updated description', isSecret },
- ]),
- ),
+ buildExpectedVariablesByKey('Updated description'),
);
});
});
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/failing-sync-application-page-layout-tab-reparent.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/failing-sync-application-page-layout-tab-reparent.integration-spec.ts
new file mode 100644
index 00000000000..c1393afd132
--- /dev/null
+++ b/packages/twenty-server/test/integration/metadata/suites/application/failing-sync-application-page-layout-tab-reparent.integration-spec.ts
@@ -0,0 +1,83 @@
+import { expectOneNotInternalServerErrorSnapshot } from 'test/integration/graphql/utils/expect-one-not-internal-server-error-snapshot.util';
+import { buildBaseManifest } from 'test/integration/metadata/suites/application/utils/build-base-manifest.util';
+import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';
+import { setupApplicationForSync } from 'test/integration/metadata/suites/application/utils/setup-application-for-sync.util';
+import { syncApplication } from 'test/integration/metadata/suites/application/utils/sync-application.util';
+import { type Manifest } from 'twenty-shared/application';
+import { STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS } from 'twenty-shared/metadata';
+import { PageLayoutTabLayoutMode } from 'twenty-shared/types';
+import { v4 as uuidv4 } from 'uuid';
+
+const TEST_APP_ID = uuidv4();
+const TEST_ROLE_ID = uuidv4();
+const TEST_TAB_ID = uuidv4();
+
+const PERSON_PAGE_LAYOUT_UNIVERSAL_IDENTIFIER =
+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.personRecordPage
+ .universalIdentifier;
+const COMPANY_PAGE_LAYOUT_UNIVERSAL_IDENTIFIER =
+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.companyRecordPage
+ .universalIdentifier;
+
+const buildManifest = (pageLayoutUniversalIdentifier: string): Manifest =>
+ buildBaseManifest({
+ appId: TEST_APP_ID,
+ roleId: TEST_ROLE_ID,
+ overrides: {
+ pageLayoutTabs: [
+ {
+ universalIdentifier: TEST_TAB_ID,
+ pageLayoutUniversalIdentifier,
+ title: 'Insights',
+ position: 1000,
+ layoutMode: PageLayoutTabLayoutMode.CANVAS,
+ },
+ ],
+ },
+ });
+
+const readTabPageLayoutUniversalIdentifier = async () => {
+ const [row] = await globalThis.testDataSource.query(
+ `SELECT pageLayout."universalIdentifier"
+ FROM core."pageLayoutTab" tab
+ JOIN core."pageLayout" pageLayout ON pageLayout.id = tab."pageLayoutId"
+ WHERE tab."universalIdentifier" = $1`,
+ [TEST_TAB_ID],
+ );
+
+ return row?.universalIdentifier;
+};
+
+describe('Manifest sync should refuse moving a page layout tab to another page layout', () => {
+ beforeAll(async () => {
+ await setupApplicationForSync({
+ applicationUniversalIdentifier: TEST_APP_ID,
+ name: 'Test Page Layout Tab Reparent App',
+ description: 'App for testing page layout tab reparenting',
+ sourcePath: 'test-page-layout-tab-reparent',
+ });
+
+ await syncApplication({
+ manifest: buildManifest(PERSON_PAGE_LAYOUT_UNIVERSAL_IDENTIFIER),
+ expectToFail: false,
+ });
+ }, 60000);
+
+ afterAll(async () => {
+ await cleanupApplicationAndAppRegistration({
+ applicationUniversalIdentifier: TEST_APP_ID,
+ });
+ });
+
+ it('should keep the tab on its original page layout', async () => {
+ const { errors } = await syncApplication({
+ manifest: buildManifest(COMPANY_PAGE_LAYOUT_UNIVERSAL_IDENTIFIER),
+ expectToFail: true,
+ });
+
+ expectOneNotInternalServerErrorSnapshot({ errors });
+ expect(await readTabPageLayoutUniversalIdentifier()).toBe(
+ PERSON_PAGE_LAYOUT_UNIVERSAL_IDENTIFIER,
+ );
+ }, 60000);
+});
diff --git a/packages/twenty-server/test/integration/metadata/suites/command-menu-item/__snapshots__/failing-command-menu-item-update.integration-spec.ts.snap b/packages/twenty-server/test/integration/metadata/suites/command-menu-item/__snapshots__/failing-command-menu-item-update.integration-spec.ts.snap
index 160623c9839..489fe3867dd 100644
--- a/packages/twenty-server/test/integration/metadata/suites/command-menu-item/__snapshots__/failing-command-menu-item-update.integration-spec.ts.snap
+++ b/packages/twenty-server/test/integration/metadata/suites/command-menu-item/__snapshots__/failing-command-menu-item-update.integration-spec.ts.snap
@@ -125,3 +125,37 @@ exports[`CommandMenuItem update should fail when changing engineComponentKey to
"name": "GraphQLError",
}
`;
+
+exports[`CommandMenuItem update should fail when changing the page layout 1`] = `
+{
+ "extensions": {
+ "code": "METADATA_VALIDATION_FAILED",
+ "errors": {
+ "commandMenuItem": [
+ {
+ "errors": [
+ {
+ "code": "NON_UPDATABLE_PROPERTY_DIVERGENCE",
+ "message": "commandMenuItem property "pageLayoutUniversalIdentifier" cannot be updated",
+ "userFriendlyMessage": "Property pageLayoutUniversalIdentifier cannot be updated",
+ },
+ ],
+ "flatEntityMinimalInformation": {
+ "universalIdentifier": Any<String>,
+ },
+ "metadataName": "commandMenuItem",
+ "type": "update",
+ },
+ ],
+ },
+ "message": "Validation failed for 1 commandMenuItem",
+ "summary": {
+ "commandMenuItem": 1,
+ "totalErrors": 1,
+ },
+ "userFriendlyMessage": "Property pageLayoutUniversalIdentifier cannot be updated",
+ },
+ "message": "Multiple validation errors occurred while updating command menu item",
+ "name": "GraphQLError",
+}
+`;
diff --git a/packages/twenty-server/test/integration/metadata/suites/command-menu-item/failing-command-menu-item-update.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/command-menu-item/failing-command-menu-item-update.integration-spec.ts
index c03a7a000ee..442be95410d 100644
--- a/packages/twenty-server/test/integration/metadata/suites/command-menu-item/failing-command-menu-item-update.integration-spec.ts
+++ b/packages/twenty-server/test/integration/metadata/suites/command-menu-item/failing-command-menu-item-update.integration-spec.ts
@@ -5,6 +5,8 @@ import { expectOneNotInternalServerErrorSnapshot } from 'test/integration/graphq
import { createCommandMenuItem } from 'test/integration/metadata/suites/command-menu-item/utils/create-command-menu-item.util';
import { deleteCommandMenuItem } from 'test/integration/metadata/suites/command-menu-item/utils/delete-command-menu-item.util';
import { updateCommandMenuItem } from 'test/integration/metadata/suites/command-menu-item/utils/update-command-menu-item.util';
+import { createOnePageLayout } from 'test/integration/metadata/suites/page-layout/utils/create-one-page-layout.util';
+import { destroyOnePageLayout } from 'test/integration/metadata/suites/page-layout/utils/destroy-one-page-layout.util';
import {
eachTestingContextFilter,
type EachTestingContext,
@@ -127,6 +129,26 @@ describe('CommandMenuItem update should fail', () => {
},
);
+ it('when changing the page layout', async () => {
+ const { data: layoutData } = await createOnePageLayout({
+ expectToFail: false,
+ input: { name: 'Test Page Layout For Command Menu Item' },
+ });
+ const pageLayoutId = layoutData.createPageLayout.id;
+
+ const { errors } = await updateCommandMenuItem({
+ expectToFail: true,
+ input: { id: testCommandMenuItemId, pageLayoutId },
+ });
+
+ await destroyOnePageLayout({
+ expectToFail: false,
+ input: { id: pageLayoutId },
+ });
+
+ expectOneNotInternalServerErrorSnapshot({ errors });
+ });
+
it('when the caller lacks the LAYOUTS permission', async () => {
const { errors } = await updateCommandMenuItem({
expectToFail: true,