From e3ca9220184a0fa56a49d1df30f6532ce7b332c1 Mon Sep 17 00:00:00 2001 From: adpare Date: Thu, 17 Sep 2026 14:28:56 -0400 Subject: [PATCH] fix: enable saving of subtechnique-of relationships --- src/app/classes/stix/technique.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/app/classes/stix/technique.ts b/src/app/classes/stix/technique.ts index 7ae6dbc4..fe0a424a 100644 --- a/src/app/classes/stix/technique.ts +++ b/src/app/classes/stix/technique.ts @@ -729,11 +729,29 @@ export class Technique extends StixObject { * @returns {Observable} of the post */ public save(restApiService: RestApiConnectorService): Observable { - const postObservable = this.updateParentRelationship(restApiService).pipe( - concatMap(() => this.syncTacticsWithParentOrSubs(restApiService)), - concatMap(() => restApiService.postTechnique(this)), - shareReplay(1) // share the result and ensure only the last POST result is emitted - ); + // For a new subtechnique, save the child technique first, then create its subtechnique-of relationship, and sync tactics + const isNewSubtechniqueWithParent = + this.firstInitialized && this.is_subtechnique && this.parentTechnique; + const postObservable = isNewSubtechniqueWithParent + ? restApiService.postTechnique(this).pipe( + concatMap(savedTechnique => { + const serializedTechnique = savedTechnique.serialize( + savedTechnique.modified.toISOString() + ); + this.base_deserialize(serializedTechnique); + this.deserialize(serializedTechnique); + return this.updateParentRelationship(restApiService).pipe( + concatMap(() => this.syncTacticsWithParentOrSubs(restApiService)), + map(() => savedTechnique) + ); + }), + shareReplay(1) + ) + : this.updateParentRelationship(restApiService).pipe( + concatMap(() => this.syncTacticsWithParentOrSubs(restApiService)), + concatMap(() => restApiService.postTechnique(this)), + shareReplay(1) + ); const subscription = postObservable.subscribe({ next: result => {