Skip to content

The open alternative to Salesforce, designed for AI.

Stop provisioning navigation commands for SYSTEM-readable objects (#26469)

martmull8ef5c3154b51
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/2-43-upgrade-version-command.module.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/2-43-upgrade-version-command.module.ts
index 406fb3cde71..2f56b3e32ac 100644
--- a/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/2-43-upgrade-version-command.module.ts
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/2-43-upgrade-version-command.module.ts
@@ -4,13 +4,21 @@ import { AgentHistoryMigrationModule } from 'src/database/commands/agent-history
import { WorkspaceIteratorModule } from 'src/database/commands/command-runners/workspace-iterator.module';
import { AgentHistoryModule } from 'src/engine/metadata-modules/ai/ai-history/ai-history.module';
import { AttributeChatMessageSendersCommand } from 'src/database/commands/upgrade-version-command/2-43/2-43-workspace-command-1790171503075-attribute-chat-message-senders.command';
+import { DeleteSystemReadableObjectNavigationCommandMenuItemsCommand } from 'src/database/commands/upgrade-version-command/2-43/2-43-workspace-command-1790180964414-delete-system-readable-object-navigation-command-menu-items.command';
+import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache.module';
+import { WorkspaceMigrationModule } from 'src/engine/workspace-manager/workspace-migration/workspace-migration.module';
@Module({
imports: [
AgentHistoryMigrationModule,
AgentHistoryModule,
+ WorkspaceCacheModule,
WorkspaceIteratorModule,
+ WorkspaceMigrationModule,
+ ],
+ providers: [
+ AttributeChatMessageSendersCommand,
+ DeleteSystemReadableObjectNavigationCommandMenuItemsCommand,
],
- providers: [AttributeChatMessageSendersCommand],
})
export class V2_43_UpgradeVersionCommandModule {}
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/2-43-workspace-command-1790180964414-delete-system-readable-object-navigation-command-menu-items.command.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/2-43-workspace-command-1790180964414-delete-system-readable-object-navigation-command-menu-items.command.ts
new file mode 100644
index 00000000000..e8ea68e3a34
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/2-43-workspace-command-1790180964414-delete-system-readable-object-navigation-command-menu-items.command.ts
@@ -0,0 +1,83 @@
+import { Command } from 'nest-commander';
+import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';
+
+import { ProvisionedWorkspaceCommandRunner } from 'src/database/commands/command-runners/provisioned-workspace.command-runner';
+import { WorkspaceIteratorService } from 'src/database/commands/command-runners/workspace-iterator.service';
+import { type RunOnWorkspaceArgs } from 'src/database/commands/command-runners/workspace.command-runner';
+import { findSystemReadableObjectNavigationCommandMenuItems } from 'src/database/commands/upgrade-version-command/2-43/utils/find-system-readable-object-navigation-command-menu-items.util';
+import { RegisteredWorkspaceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-workspace-command.decorator';
+import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
+import { WorkspaceMigrationBuilderException } from 'src/engine/workspace-manager/workspace-migration/exceptions/workspace-migration-builder-exception';
+import { WorkspaceMigrationValidateBuildAndRunService } from 'src/engine/workspace-manager/workspace-migration/services/workspace-migration-validate-build-and-run-service';
+
+@RegisteredWorkspaceCommand('2.43.0', 1790180964414)
+@Command({
+ name: 'upgrade:2-43:delete-system-readable-object-navigation-command-menu-items',
+ description:
+ 'Delete the "Go to" navigation command menu items targeting SYSTEM-readable objects',
+})
+export class DeleteSystemReadableObjectNavigationCommandMenuItemsCommand extends ProvisionedWorkspaceCommandRunner {
+ constructor(
+ protected readonly workspaceIteratorService: WorkspaceIteratorService,
+ private readonly workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService,
+ private readonly workspaceCacheService: WorkspaceCacheService,
+ ) {
+ super(workspaceIteratorService);
+ }
+
+ override async runOnWorkspace({
+ workspaceId,
+ options,
+ }: RunOnWorkspaceArgs): Promise<void> {
+ const { flatCommandMenuItemMaps, flatObjectMetadataMaps } =
+ await this.workspaceCacheService.getOrRecompute(workspaceId, [
+ 'flatCommandMenuItemMaps',
+ 'flatObjectMetadataMaps',
+ ]);
+
+ const commandMenuItemsToDelete =
+ findSystemReadableObjectNavigationCommandMenuItems({
+ flatCommandMenuItems: Object.values(
+ flatCommandMenuItemMaps.byUniversalIdentifier,
+ ),
+ flatObjectMetadataMaps,
+ });
+
+ if (commandMenuItemsToDelete.length === 0) {
+ return;
+ }
+
+ if (options.dryRun) {
+ this.logger.log(
+ `Would delete ${commandMenuItemsToDelete.length} SYSTEM-readable object navigation command menu item(s) for workspace ${workspaceId}`,
+ );
+
+ return;
+ }
+
+ const validateAndBuildResult =
+ await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunLegacyWorkspaceMigration(
+ {
+ allFlatEntityOperationByMetadataName: {
+ commandMenuItem: {
+ flatEntityToCreate: [],
+ flatEntityToDelete: commandMenuItemsToDelete,
+ flatEntityToUpdate: [],
+ },
+ },
+ workspaceId,
+ isSystemBuild: true,
+ applicationUniversalIdentifier:
+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,
+ },
+ );
+
+ if (validateAndBuildResult.status === 'fail') {
+ throw new WorkspaceMigrationBuilderException(validateAndBuildResult);
+ }
+
+ this.logger.log(
+ `Deleted ${commandMenuItemsToDelete.length} SYSTEM-readable object navigation command menu item(s) for workspace ${workspaceId}`,
+ );
+ }
+}
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/utils/__tests__/find-system-readable-object-navigation-command-menu-items.util.spec.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/utils/__tests__/find-system-readable-object-navigation-command-menu-items.util.spec.ts
new file mode 100644
index 00000000000..d10657d770a
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/utils/__tests__/find-system-readable-object-navigation-command-menu-items.util.spec.ts
@@ -0,0 +1,88 @@
+import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';
+import { MetadataReadability } from 'twenty-shared/types';
+
+import { findSystemReadableObjectNavigationCommandMenuItems } from 'src/database/commands/upgrade-version-command/2-43/utils/find-system-readable-object-navigation-command-menu-items.util';
+import { EngineComponentKey } from 'src/engine/metadata-modules/command-menu-item/enums/engine-component-key.enum';
+import { type FlatCommandMenuItem } from 'src/engine/metadata-modules/flat-command-menu-item/types/flat-command-menu-item.type';
+import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';
+import { type FlatObjectMetadata } from 'src/engine/metadata-modules/flat-object-metadata/types/flat-object-metadata.type';
+
+const SYSTEM_OBJECT_ID = 'system-object-id';
+const OPEN_OBJECT_ID = 'open-object-id';
+
+const buildFlatObjectMetadataMaps = (): FlatEntityMaps<FlatObjectMetadata> =>
+ ({
+ byUniversalIdentifier: {
+ 'system-object': {
+ id: SYSTEM_OBJECT_ID,
+ universalIdentifier: 'system-object',
+ readability: MetadataReadability.SYSTEM,
+ },
+ 'open-object': {
+ id: OPEN_OBJECT_ID,
+ universalIdentifier: 'open-object',
+ readability: MetadataReadability.OPEN,
+ },
+ },
+ universalIdentifierById: {
+ [SYSTEM_OBJECT_ID]: 'system-object',
+ [OPEN_OBJECT_ID]: 'open-object',
+ },
+ }) as unknown as FlatEntityMaps<FlatObjectMetadata>;
+
+const buildFlatCommandMenuItem = (
+ overrides: Partial<FlatCommandMenuItem>,
+): FlatCommandMenuItem =>
+ ({
+ id: 'command-menu-item-id',
+ universalIdentifier: 'command-menu-item',
+ engineComponentKey: EngineComponentKey.NAVIGATION,
+ applicationUniversalIdentifier:
+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,
+ navigationTargetObjectMetadataId: SYSTEM_OBJECT_ID,
+ ...overrides,
+ }) as FlatCommandMenuItem;
+
+describe('findSystemReadableObjectNavigationCommandMenuItems', () => {
+ it('returns standard navigation items targeting a SYSTEM-readable object', () => {
+ const result = findSystemReadableObjectNavigationCommandMenuItems({
+ flatCommandMenuItems: [
+ buildFlatCommandMenuItem({ id: 'system' }),
+ buildFlatCommandMenuItem({
+ id: 'open',
+ navigationTargetObjectMetadataId: OPEN_OBJECT_ID,
+ }),
+ undefined,
+ ],
+ flatObjectMetadataMaps: buildFlatObjectMetadataMaps(),
+ });
+
+ expect(result.map(({ id }) => id)).toEqual(['system']);
+ });
+
+ it('ignores items that are not standard navigation items', () => {
+ const result = findSystemReadableObjectNavigationCommandMenuItems({
+ flatCommandMenuItems: [
+ buildFlatCommandMenuItem({
+ id: 'not-navigation',
+ engineComponentKey: EngineComponentKey.ADD_TO_FAVORITES,
+ }),
+ buildFlatCommandMenuItem({
+ id: 'other-application',
+ applicationUniversalIdentifier: 'other-application',
+ }),
+ buildFlatCommandMenuItem({
+ id: 'no-target',
+ navigationTargetObjectMetadataId: null,
+ }),
+ buildFlatCommandMenuItem({
+ id: 'unknown-target',
+ navigationTargetObjectMetadataId: 'unknown-object-id',
+ }),
+ ],
+ flatObjectMetadataMaps: buildFlatObjectMetadataMaps(),
+ });
+
+ expect(result).toEqual([]);
+ });
+});
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/utils/find-system-readable-object-navigation-command-menu-items.util.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/utils/find-system-readable-object-navigation-command-menu-items.util.ts
new file mode 100644
index 00000000000..93faddf4903
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-43/utils/find-system-readable-object-navigation-command-menu-items.util.ts
@@ -0,0 +1,40 @@
+import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';
+import { MetadataReadability } from 'twenty-shared/types';
+import { isDefined } from 'twenty-shared/utils';
+
+import { EngineComponentKey } from 'src/engine/metadata-modules/command-menu-item/enums/engine-component-key.enum';
+import { type FlatCommandMenuItem } from 'src/engine/metadata-modules/flat-command-menu-item/types/flat-command-menu-item.type';
+import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';
+import { findFlatEntityByIdInFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps.util';
+import { type FlatObjectMetadata } from 'src/engine/metadata-modules/flat-object-metadata/types/flat-object-metadata.type';
+
+export const findSystemReadableObjectNavigationCommandMenuItems = ({
+ flatCommandMenuItems,
+ flatObjectMetadataMaps,
+}: {
+ flatCommandMenuItems: (FlatCommandMenuItem | undefined)[];
+ flatObjectMetadataMaps: FlatEntityMaps<FlatObjectMetadata>;
+}): FlatCommandMenuItem[] =>
+ flatCommandMenuItems.filter(
+ (flatCommandMenuItem): flatCommandMenuItem is FlatCommandMenuItem => {
+ if (
+ !isDefined(flatCommandMenuItem) ||
+ flatCommandMenuItem.engineComponentKey !==
+ EngineComponentKey.NAVIGATION ||
+ flatCommandMenuItem.applicationUniversalIdentifier !==
+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER ||
+ !isDefined(flatCommandMenuItem.navigationTargetObjectMetadataId)
+ ) {
+ return false;
+ }
+
+ const targetFlatObjectMetadata = findFlatEntityByIdInFlatEntityMaps({
+ flatEntityId: flatCommandMenuItem.navigationTargetObjectMetadataId,
+ flatEntityMaps: flatObjectMetadataMaps,
+ });
+
+ return (
+ targetFlatObjectMetadata?.readability === MetadataReadability.SYSTEM
+ );
+ },
+ );
diff --git a/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/object-metadata/services/__tests__/object-navigation-command-on-create-side-effect-handler.service.spec.ts b/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/object-metadata/services/__tests__/object-navigation-command-on-create-side-effect-handler.service.spec.ts
index 9db6b5ee530..c92abb28e09 100644
--- a/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/object-metadata/services/__tests__/object-navigation-command-on-create-side-effect-handler.service.spec.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/object-metadata/services/__tests__/object-navigation-command-on-create-side-effect-handler.service.spec.ts
@@ -1,4 +1,5 @@
import { getSystemNavigationCommandMenuItemUniversalIdentifier } from 'twenty-shared/application';
+import { MetadataReadability } from 'twenty-shared/types';
import { EngineComponentKey } from 'src/engine/metadata-modules/command-menu-item/enums/engine-component-key.enum';
import { type AllFlatEntityOperationRecordByMetadataName } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-operation-record-by-metadata-name.type';
@@ -28,6 +29,7 @@ type ObjectMetadataOverrides = Partial<{
isActive: boolean;
nameSingular: string;
shortcut: string | null;
+ readability: MetadataReadability;
commandMenuItemUniversalIdentifiers: string[];
}>;
@@ -38,6 +40,7 @@ const buildFlatObjectMetadata = (overrides: ObjectMetadataOverrides = {}) => ({
isActive: true,
nameSingular: 'ticket',
shortcut: 'T',
+ readability: MetadataReadability.OPEN,
commandMenuItemUniversalIdentifiers: [],
...overrides,
});
@@ -208,6 +211,18 @@ describe('ObjectNavigationCommandOnCreateSideEffectHandlerService', () => {
expect(result.status).toBe('noop');
});
+ it('noops when the object is SYSTEM-readable', () => {
+ const result = handler.buildSideEffects(
+ buildArgs({
+ flatObjectMetadata: buildFlatObjectMetadata({
+ readability: MetadataReadability.SYSTEM,
+ }),
+ }),
+ );
+
+ expect(result.status).toBe('noop');
+ });
+
it('appends after the synced maximum position', () => {
const result = expectSuccess(
handler.buildSideEffects(
diff --git a/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/object-metadata/services/object-navigation-command-on-create-side-effect-handler.service.ts b/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/object-metadata/services/object-navigation-command-on-create-side-effect-handler.service.ts
index d1ab765c613..ece106f1f7e 100644
--- a/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/object-metadata/services/object-navigation-command-on-create-side-effect-handler.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/metadata-side-effect/handlers/object-metadata/services/object-navigation-command-on-create-side-effect-handler.service.ts
@@ -1,5 +1,6 @@
import { Injectable } from '@nestjs/common';
+import { MetadataReadability } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { buildObjectNavigationUniversalFlatCommandMenuItem } from 'src/engine/metadata-modules/flat-command-menu-item/utils/build-object-navigation-universal-flat-command-menu-item.util';
@@ -18,7 +19,7 @@ export class ObjectNavigationCommandOnCreateSideEffectHandlerService extends Met
metadataName: 'objectMetadata',
name: 'objectNavigationCommandOnCreate',
description:
- 'When an object is created, provision its singleton "Go to" navigation command menu item (engineComponentKey NAVIGATION, a null payload and the target in navigationTargetObjectMetadataId), isSystemSideEffect so the engine owns its lifecycle, and isActive mirrors the object so an object created inactive gets a disabled command rather than none. Label, shortLabel and icon are interpolation templates resolved from the object at render time, the availability expression gates on the object read permission plus a feature flag for gated standard objects, and hotKeys derive from the object shortcut. The identifier is name-free and keyed on (application, object), so an object rename keeps the same command. Position is derived from the synced maximum plus the object index in the creation batch, so batch object creation never double-books a position. Noops when the object create carries no workspace id (the manifest sync path mints entity ids after side-effect expansion). twenty-standard is not concerned: it synchronizes through the from/to migration path, which never runs the side-effect engine, and seeds one navigation command per active object itself.',
+ 'When an object is created, provision its singleton "Go to" navigation command menu item (engineComponentKey NAVIGATION, a null payload and the target in navigationTargetObjectMetadataId), isSystemSideEffect so the engine owns its lifecycle, and isActive mirrors the object so an object created inactive gets a disabled command rather than none. Label, shortLabel and icon are interpolation templates resolved from the object at render time, the availability expression gates on the object read permission plus a feature flag for gated standard objects, and hotKeys derive from the object shortcut. The identifier is name-free and keyed on (application, object), so an object rename keeps the same command. Position is derived from the synced maximum plus the object index in the creation batch, so batch object creation never double-books a position. Noops when the object create carries no workspace id (the manifest sync path mints entity ids after side-effect expansion), and for SYSTEM-readable objects, whose records the API never serves. twenty-standard is not concerned: it synchronizes through the from/to migration path, which never runs the side-effect engine, and seeds one navigation command per active, non-SYSTEM-readable object itself.',
},
) {
buildSideEffects({
@@ -29,7 +30,10 @@ export class ObjectNavigationCommandOnCreateSideEffectHandlerService extends Met
const sourceFlatObjectMetadata = flatEntity as UniversalFlatObjectMetadata &
Partial<{ id: string }>;
- if (!isDefined(sourceFlatObjectMetadata.id)) {
+ if (
+ !isDefined(sourceFlatObjectMetadata.id) ||
+ sourceFlatObjectMetadata.readability === MetadataReadability.SYSTEM
+ ) {
return { status: 'noop' };
}
diff --git a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/command-menu-item/build-standard-flat-command-menu-item-maps.util.ts b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/command-menu-item/build-standard-flat-command-menu-item-maps.util.ts
index ccf0a778399..1d1957983f8 100644
--- a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/command-menu-item/build-standard-flat-command-menu-item-maps.util.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/command-menu-item/build-standard-flat-command-menu-item-maps.util.ts
@@ -1,4 +1,5 @@
import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';
+import { MetadataReadability } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { v4 } from 'uuid';
@@ -54,7 +55,11 @@ export const buildStandardFlatCommandMenuItemMaps = ({
flatObjectMetadataMaps.byUniversalIdentifier,
)
.filter(isDefined)
- .filter((flatObject) => flatObject.isActive)
+ .filter(
+ (flatObject) =>
+ flatObject.isActive &&
+ flatObject.readability !== MetadataReadability.SYSTEM,
+ )
.sort(seedCompareObjectMetadataForNavigationPosition);
const maxStandardPosition = Object.values(