Skip to content

Commit 6caa780

Browse files
gitstart-app[bot]gitstart-twentyijreilly
authored
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](#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 <https://www.loom.com/share/2b0a91f463ca4e02a6963f9a8796a0d9?sid=1e9c4fb8-8fb9-4c6c-b43a-c50f3776e1d3> Fixes #5370 --------- Co-authored-by: gitstart-twenty <[email protected]> Co-authored-by: Marie Stoppa <[email protected]>
1 parent 08e07ac commit 6caa780

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

packages/twenty-server/src/engine/metadata-modules/object-metadata/object-metadata.service.ts

+33-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import console from 'console';
55

66
import { Query, QueryOptions } from '@ptc-org/nestjs-query-core';
77
import { TypeOrmQueryService } from '@ptc-org/nestjs-query-typeorm';
8-
import { FindManyOptions, FindOneOptions, Repository } from 'typeorm';
8+
import { FindManyOptions, FindOneOptions, In, Repository } from 'typeorm';
99

1010
import { FieldMetadataSettings } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-settings.interface';
1111

@@ -369,6 +369,10 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
369369

370370
const updatedObject = await super.updateOne(input.id, input.update);
371371

372+
if (input.update.isActive !== undefined) {
373+
await this.updateObjectRelationships(input.id, input.update.isActive);
374+
}
375+
372376
await this.workspaceMetadataVersionService.incrementMetadataVersion(
373377
workspaceId,
374378
);
@@ -1238,4 +1242,32 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
12381242
],
12391243
);
12401244
}
1245+
1246+
private async updateObjectRelationships(
1247+
objectMetadataId: string,
1248+
isActive: boolean,
1249+
) {
1250+
const affectedRelations = await this.relationMetadataRepository.find({
1251+
where: [
1252+
{ fromObjectMetadataId: objectMetadataId },
1253+
{ toObjectMetadataId: objectMetadataId },
1254+
],
1255+
});
1256+
1257+
const affectedFieldIds = affectedRelations.reduce(
1258+
(acc, { fromFieldMetadataId, toFieldMetadataId }) => {
1259+
acc.push(fromFieldMetadataId, toFieldMetadataId);
1260+
1261+
return acc;
1262+
},
1263+
[] as string[],
1264+
);
1265+
1266+
if (affectedFieldIds.length > 0) {
1267+
await this.fieldMetadataRepository.update(
1268+
{ id: In(affectedFieldIds) },
1269+
{ isActive: isActive },
1270+
);
1271+
}
1272+
}
12411273
}

0 commit comments

Comments
 (0)