From 6caa78008f79a890d2171581d581e629da24cd09 Mon Sep 17 00:00:00 2001 From: "gitstart-app[bot]" <57568882+gitstart-app[bot]@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:19:21 +0200 Subject: [PATCH] If an object is disabled, then the relationships to that object should be disabled (#6690) This PR was created by [GitStart](https://gitstart.com/) to address the requirements from this ticket: [TWNTY-5370](https://clients.gitstart.com/twenty/5449/tickets/TWNTY-5370). This ticket was imported from: [TWNTY-5370](https://github.com/twentyhq/twenty/issues/5370) --- ### Description - We updated the logic in packages/twenty-server/src/engine/metadata-modules/object-metadata/object-metadata.service.ts Test cases: 1. Ensure that when an object is disabled, all related relationships are also disabled. a. Example disable the people object b. Check the company object and verify that the people field has been disabled too c. Check the opportunity object and check that the point of contact field has been disabled too 2. Verify that when a previously disabled object is restored, the relationships are also restored. 3. Ensure that previously disabled relationships remain disabled when the object is disabled and later restored. 4. Verify that relationships of a disabled object are not visible in the UI. 5. Ensure that relationships to a disabled object are marked as inactive in the data models screen ### Refs #5370 ### Demo Fixes #5370 --------- Co-authored-by: gitstart-twenty Co-authored-by: Marie Stoppa --- .../object-metadata.service.ts | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/twenty-server/src/engine/metadata-modules/object-metadata/object-metadata.service.ts b/packages/twenty-server/src/engine/metadata-modules/object-metadata/object-metadata.service.ts index 973a5cf35..53df8a651 100644 --- a/packages/twenty-server/src/engine/metadata-modules/object-metadata/object-metadata.service.ts +++ b/packages/twenty-server/src/engine/metadata-modules/object-metadata/object-metadata.service.ts @@ -5,7 +5,7 @@ import console from 'console'; import { Query, QueryOptions } from '@ptc-org/nestjs-query-core'; import { TypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm'; -import { FindManyOptions, FindOneOptions, Repository } from 'typeorm'; +import { FindManyOptions, FindOneOptions, In, Repository } from 'typeorm'; import { FieldMetadataSettings } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-settings.interface'; @@ -369,6 +369,10 @@ export class ObjectMetadataService extends TypeOrmQueryService { + acc.push(fromFieldMetadataId, toFieldMetadataId); + + return acc; + }, + [] as string[], + ); + + if (affectedFieldIds.length > 0) { + await this.fieldMetadataRepository.update( + { id: In(affectedFieldIds) }, + { isActive: isActive }, + ); + } + } }