From 1ae5a7798db117239c36f92d4cedf8c2d8916bab Mon Sep 17 00:00:00 2001 From: Brandon Treston Date: Tue, 2 Sep 2025 10:36:39 -0400 Subject: [PATCH] fix model creation (#16257) --- .../collection-dialog.component.ts | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/web/src/app/admin-console/organizations/shared/components/collection-dialog/collection-dialog.component.ts b/apps/web/src/app/admin-console/organizations/shared/components/collection-dialog/collection-dialog.component.ts index 5b207b5a688..33dd4dcaa28 100644 --- a/apps/web/src/app/admin-console/organizations/shared/components/collection-dialog/collection-dialog.component.ts +++ b/apps/web/src/app/admin-console/organizations/shared/components/collection-dialog/collection-dialog.component.ts @@ -400,20 +400,29 @@ export class CollectionDialogComponent implements OnInit, OnDestroy { } if ( this.editMode && - !this.collection.canEditName(this.organization) && + !this.collection?.canEditName(this.organization) && this.formGroup.controls.name.dirty ) { throw new Error("Cannot change readonly field: Name"); } const parent = this.formGroup.controls.parent?.value; - const collectionView = new CollectionAdminView({ - id: this.params.collectionId as CollectionId, - organizationId: this.formGroup.controls.selectedOrg.value, - name: parent - ? `${parent}/${this.formGroup.controls.name.value}` - : this.formGroup.controls.name.value, - }); + + // Clone the current collection + const collectionView = Object.assign( + new CollectionAdminView({ + id: "" as CollectionId, + organizationId: "" as OrganizationId, + name: "", + }), + this.collection, + ); + + collectionView.name = parent + ? `${parent}/${this.formGroup.controls.name.value}` + : this.formGroup.controls.name.value; + collectionView.id = this.params.collectionId as CollectionId; + collectionView.organizationId = this.formGroup.controls.selectedOrg.value; collectionView.externalId = this.formGroup.controls.externalId.value; collectionView.groups = this.formGroup.controls.access.value .filter((v) => v.type === AccessItemType.Group) @@ -421,7 +430,6 @@ export class CollectionDialogComponent implements OnInit, OnDestroy { collectionView.users = this.formGroup.controls.access.value .filter((v) => v.type === AccessItemType.Member) .map(convertToSelectionView); - collectionView.defaultUserCollectionEmail = this.collection?.defaultUserCollectionEmail; const userId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));