From 94d6cc3ef180cf3ab0fe3365069bf4560c940069 Mon Sep 17 00:00:00 2001 From: aj-rosado <109146700+aj-rosado@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:45:35 +0100 Subject: [PATCH] [PM-8780] Added validation to only display organizations with managed collections (#10065) * Added validation to only display organizations with managed collections on the export org selector * using the decryptedCollection$ directly instead of creating a new observable from the encryptedCollections array --- .../src/components/export.component.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.ts b/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.ts index 84d4c459348..cf6577c403e 100644 --- a/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.ts +++ b/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.ts @@ -9,7 +9,7 @@ import { ViewChild, } from "@angular/core"; import { ReactiveFormsModule, UntypedFormBuilder, Validators } from "@angular/forms"; -import { map, merge, Observable, startWith, Subject, takeUntil } from "rxjs"; +import { combineLatest, map, merge, Observable, startWith, Subject, takeUntil } from "rxjs"; import { JslibModule } from "@bitwarden/angular/jslib.module"; import { PasswordStrengthV2Component } from "@bitwarden/angular/tools/password-strength/password-strength-v2.component"; @@ -25,6 +25,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { EncryptedExportType } from "@bitwarden/common/tools/enums/encrypted-export-type.enum"; +import { CollectionService } from "@bitwarden/common/vault/abstractions/collection.service"; import { AsyncActionsModule, BitSubmitDirective, @@ -160,6 +161,7 @@ export class ExportComponent implements OnInit, OnDestroy { protected fileDownloadService: FileDownloadService, protected dialogService: DialogService, protected organizationService: OrganizationService, + private collectionService: CollectionService, ) {} async ngOnInit() { @@ -196,8 +198,21 @@ export class ExportComponent implements OnInit, OnDestroy { return; } - this.organizations$ = this.organizationService.memberOrganizations$.pipe( - map((orgs) => orgs.sort(Utils.getSortFunction(this.i18nService, "name"))), + this.organizations$ = combineLatest({ + collections: this.collectionService.decryptedCollections$, + memberOrganizations: this.organizationService.memberOrganizations$, + }).pipe( + map(({ collections, memberOrganizations }) => { + const managedCollectionsOrgIds = new Set( + collections.filter((c) => c.manage).map((c) => c.organizationId), + ); + // Filter organizations that exist in managedCollectionsOrgIds + const filteredOrgs = memberOrganizations.filter((org) => + managedCollectionsOrgIds.has(org.id), + ); + // Sort the filtered organizations based on the name + return filteredOrgs.sort(Utils.getSortFunction(this.i18nService, "name")); + }), ); this.exportForm.controls.vaultSelector.valueChanges