From 7ca091faa565162252c01d9c8c9fe1da7a007ff1 Mon Sep 17 00:00:00 2001 From: "gitstart-app[bot]" <57568882+gitstart-app[bot]@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:37:06 +0200 Subject: [PATCH] Add isInactive to FieldMetadata decorator (#6623) This PR was created by [GitStart](https://gitstart.com/) to address the requirements from this ticket: [TWNTY-4145](https://clients.gitstart.com/twenty/5449/tickets/TWNTY-4145). This ticket was imported from: [TWNTY-4145](https://github.com/twentyhq/twenty/issues/4145) --- ### Description This PR introduces the @isInActive() decorator to the standard field metadata. \ - This gives the ability to allow workspaces to be able to be created with standard fields as inactive *Helps prevent polluting existing workspaces - A new standard field can be added to* eg company-workspace-entity.ts and the @WorkspaceIsInActive() decorator can be added to create it in deactivated mode sync-metadata command: `yarn command:prod workspace:sync-metadata -f` ### Refs #4145 ### Demo \ \ Fixes: #4145 --------- Co-authored-by: gitstart-twenty Co-authored-by: Charles Bochet --- .../decorators/workspace-field.decorator.ts | 2 ++ .../workspace-field-metadata-args.interface.ts | 5 +++++ .../workspace-relation-metadata-args.interface.ts | 5 +++++ .../factories/standard-field.factory.ts | 3 +++ .../interfaces/partial-field-metadata.interface.ts | 1 + .../services/workspace-metadata-updater.service.ts | 11 +++++------ 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/twenty-server/src/engine/twenty-orm/decorators/workspace-field.decorator.ts b/packages/twenty-server/src/engine/twenty-orm/decorators/workspace-field.decorator.ts index 64505b9c585d..83285f1c449e 100644 --- a/packages/twenty-server/src/engine/twenty-orm/decorators/workspace-field.decorator.ts +++ b/packages/twenty-server/src/engine/twenty-orm/decorators/workspace-field.decorator.ts @@ -19,6 +19,7 @@ export interface WorkspaceFieldOptions< defaultValue?: FieldMetadataDefaultValue; options?: FieldMetadataOptions; settings?: FieldMetadataSettings; + isActive?: boolean; } export function WorkspaceField( @@ -75,6 +76,7 @@ export function WorkspaceField( isSystem, gate, isDeprecated, + isActive: options.isActive, }); }; } diff --git a/packages/twenty-server/src/engine/twenty-orm/interfaces/workspace-field-metadata-args.interface.ts b/packages/twenty-server/src/engine/twenty-orm/interfaces/workspace-field-metadata-args.interface.ts index 0574fb7922cf..862d72a25117 100644 --- a/packages/twenty-server/src/engine/twenty-orm/interfaces/workspace-field-metadata-args.interface.ts +++ b/packages/twenty-server/src/engine/twenty-orm/interfaces/workspace-field-metadata-args.interface.ts @@ -78,4 +78,9 @@ export interface WorkspaceFieldMetadataArgs { * Is deprecated field. */ readonly isDeprecated?: boolean; + + /** + * Is active field. + */ + readonly isActive?: boolean; } diff --git a/packages/twenty-server/src/engine/twenty-orm/interfaces/workspace-relation-metadata-args.interface.ts b/packages/twenty-server/src/engine/twenty-orm/interfaces/workspace-relation-metadata-args.interface.ts index 861b1e7d44d4..40de6f318d0c 100644 --- a/packages/twenty-server/src/engine/twenty-orm/interfaces/workspace-relation-metadata-args.interface.ts +++ b/packages/twenty-server/src/engine/twenty-orm/interfaces/workspace-relation-metadata-args.interface.ts @@ -81,4 +81,9 @@ export interface WorkspaceRelationMetadataArgs { * Field gate. */ readonly gate?: Gate; + + /** + * Is active field. + */ + readonly isActive?: boolean; } diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/factories/standard-field.factory.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/factories/standard-field.factory.ts index a54b77c38b96..9012a590033d 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/factories/standard-field.factory.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/factories/standard-field.factory.ts @@ -172,6 +172,7 @@ export class StandardFieldFactory { isNullable: workspaceFieldMetadataArgs.isNullable, isCustom: workspaceFieldMetadataArgs.isDeprecated ? true : false, isSystem: workspaceFieldMetadataArgs.isSystem ?? false, + isActive: workspaceFieldMetadataArgs.isActive ?? true, }, ]; } @@ -222,6 +223,7 @@ export class StandardFieldFactory { isCustom: false, isSystem: true, isNullable: workspaceRelationMetadataArgs.isNullable, + isActive: workspaceRelationMetadataArgs.isActive ?? true, }); } @@ -239,6 +241,7 @@ export class StandardFieldFactory { workspaceEntityMetadataArgs?.isSystem || workspaceRelationMetadataArgs.isSystem, isNullable: true, + isActive: workspaceRelationMetadataArgs.isActive ?? true, }); return fieldMetadataCollection; diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-field-metadata.interface.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-field-metadata.interface.ts index c36e2da750b4..81722ad20710 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-field-metadata.interface.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-field-metadata.interface.ts @@ -15,6 +15,7 @@ export type PartialFieldMetadata = Omit< isSystem?: boolean; workspaceId: string; objectMetadataId?: string; + isActive?: boolean; }; export type PartialComputedFieldMetadata = { diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/services/workspace-metadata-updater.service.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/services/workspace-metadata-updater.service.ts index 1ae597c2d985..219ce346a7d2 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/services/workspace-metadata-updater.service.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/services/workspace-metadata-updater.service.ts @@ -7,23 +7,23 @@ import { In, ObjectLiteral, } from 'typeorm'; -import { v4 as uuidV4 } from 'uuid'; import { DeepPartial } from 'typeorm/common/DeepPartial'; +import { v4 as uuidV4 } from 'uuid'; import { PartialFieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-field-metadata.interface'; import { PartialIndexMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-index-metadata.interface'; -import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; +import { FieldMetadataComplexOption } from 'src/engine/metadata-modules/field-metadata/dtos/options.input'; import { FieldMetadataEntity, FieldMetadataType, } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; +import { IndexMetadataEntity } from 'src/engine/metadata-modules/index-metadata/index-metadata.entity'; +import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; import { RelationMetadataEntity } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity'; -import { FieldMetadataComplexOption } from 'src/engine/metadata-modules/field-metadata/dtos/options.input'; -import { WorkspaceSyncStorage } from 'src/engine/workspace-manager/workspace-sync-metadata/storage/workspace-sync.storage'; import { FieldMetadataUpdate } from 'src/engine/workspace-manager/workspace-migration-builder/factories/workspace-migration-field.factory'; import { ObjectMetadataUpdate } from 'src/engine/workspace-manager/workspace-migration-builder/factories/workspace-migration-object.factory'; -import { IndexMetadataEntity } from 'src/engine/metadata-modules/index-metadata/index-metadata.entity'; +import { WorkspaceSyncStorage } from 'src/engine/workspace-manager/workspace-sync-metadata/storage/workspace-sync.storage'; @Injectable() export class WorkspaceMetadataUpdaterService { @@ -104,7 +104,6 @@ export class WorkspaceMetadataUpdaterService { ), } : {}), - isActive: true, }; }