From 2e11fb2a243d8f54f01c3d929a3f9cd5904b3ef0 Mon Sep 17 00:00:00 2001 From: Shane Melton Date: Wed, 7 Feb 2024 11:08:07 -0800 Subject: [PATCH] [AC-1899] Fix Collection Access Model Resetting (#7612) * [AC-1899] Only take the first emission of feature flags and organizations to avoid overwriting form values * [AC-1899] Fix flexibleCollections flag to update when selected org changes * [AC-1899] Prettier --- .../collection-dialog.component.html | 4 ++-- .../collection-dialog.component.ts | 23 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/apps/web/src/app/vault/components/collection-dialog/collection-dialog.component.html b/apps/web/src/app/vault/components/collection-dialog/collection-dialog.component.html index db63ef3d34..e3063dfe4a 100644 --- a/apps/web/src/app/vault/components/collection-dialog/collection-dialog.component.html +++ b/apps/web/src/app/vault/components/collection-dialog/collection-dialog.component.html @@ -89,7 +89,7 @@ [selectorLabelText]="'selectGroupsAndMembers' | i18n" [selectorHelpText]="'userPermissionOverrideHelper' | i18n" [emptySelectionText]="'noMembersOrGroupsAdded' | i18n" - [flexibleCollectionsEnabled]="flexibleCollectionsEnabled$ | async" + [flexibleCollectionsEnabled]="organization.flexibleCollections" > diff --git a/apps/web/src/app/vault/components/collection-dialog/collection-dialog.component.ts b/apps/web/src/app/vault/components/collection-dialog/collection-dialog.component.ts index 211cc05c14..b10d6b1e28 100644 --- a/apps/web/src/app/vault/components/collection-dialog/collection-dialog.component.ts +++ b/apps/web/src/app/vault/components/collection-dialog/collection-dialog.component.ts @@ -12,6 +12,7 @@ import { switchMap, takeUntil, } from "rxjs"; +import { first } from "rxjs/operators"; import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; import { OrganizationUserService } from "@bitwarden/common/admin-console/abstractions/organization-user/organization-user.service"; @@ -70,14 +71,9 @@ export enum CollectionDialogAction { templateUrl: "collection-dialog.component.html", }) export class CollectionDialogComponent implements OnInit, OnDestroy { - protected flexibleCollectionsEnabled$ = this.organizationService - .get$(this.params.organizationId) - .pipe(map((o) => o?.flexibleCollections)); - - protected flexibleCollectionsV1Enabled$ = this.configService.getFeatureFlag$( - FeatureFlag.FlexibleCollectionsV1, - false, - ); + protected flexibleCollectionsV1Enabled$ = this.configService + .getFeatureFlag$(FeatureFlag.FlexibleCollectionsV1, false) + .pipe(first()); private destroy$ = new Subject(); protected organizations$: Observable; @@ -126,6 +122,7 @@ export class CollectionDialogComponent implements OnInit, OnDestroy { .pipe(takeUntil(this.destroy$)) .subscribe((id) => this.loadOrg(id, this.params.collectionIds)); this.organizations$ = this.organizationService.organizations$.pipe( + first(), map((orgs) => orgs .filter((o) => o.canCreateNewCollections && !o.isProviderUser) @@ -165,7 +162,6 @@ export class CollectionDialogComponent implements OnInit, OnDestroy { collection: this.params.collectionId ? this.collectionService.get(this.params.collectionId) : of(null), - flexibleCollections: this.flexibleCollectionsEnabled$, flexibleCollectionsV1: this.flexibleCollectionsV1Enabled$, }) .pipe(takeUntil(this.formGroup.controls.selectedOrg.valueChanges), takeUntil(this.destroy$)) @@ -177,7 +173,6 @@ export class CollectionDialogComponent implements OnInit, OnDestroy { groups, users, collection, - flexibleCollections, flexibleCollectionsV1, }) => { this.organization = organization; @@ -222,7 +217,7 @@ export class CollectionDialogComponent implements OnInit, OnDestroy { (u) => u.userId === this.organization?.userId, )?.id; const initialSelection: AccessItemValue[] = - currentOrgUserId !== undefined && flexibleCollections + currentOrgUserId !== undefined && organization.flexibleCollections ? [ { id: currentOrgUserId, @@ -238,7 +233,11 @@ export class CollectionDialogComponent implements OnInit, OnDestroy { }); } - if (flexibleCollectionsV1 && !organization.allowAdminAccessToAllCollectionItems) { + if ( + organization.flexibleCollections && + flexibleCollectionsV1 && + !organization.allowAdminAccessToAllCollectionItems + ) { this.formGroup.controls.access.addValidators(validateCanManagePermission); } else { this.formGroup.controls.access.removeValidators(validateCanManagePermission);