diff --git a/apps/browser/src/services/families-policy.service.spec.ts b/apps/browser/src/services/families-policy.service.spec.ts index 19291bcd825..29beb3eb8af 100644 --- a/apps/browser/src/services/families-policy.service.spec.ts +++ b/apps/browser/src/services/families-policy.service.spec.ts @@ -2,27 +2,35 @@ import { TestBed } from "@angular/core/testing"; import { mock, MockProxy } from "jest-mock-extended"; import { firstValueFrom, of } from "rxjs"; -import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; +import { vNextOrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/vnext.organization.service.abstraction"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; import { Policy } from "@bitwarden/common/admin-console/models/domain/policy"; +import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; +import { Utils } from "@bitwarden/common/platform/misc/utils"; +import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/spec"; +import { UserId } from "@bitwarden/common/types/guid"; import { FamiliesPolicyService } from "./families-policy.service"; // Adjust the import as necessary describe("FamiliesPolicyService", () => { let service: FamiliesPolicyService; - let organizationService: MockProxy; + let organizationService: MockProxy; let policyService: MockProxy; + let accountService: FakeAccountService; + const userId = Utils.newGuid() as UserId; beforeEach(() => { - organizationService = mock(); + organizationService = mock(); policyService = mock(); + accountService = mockAccountServiceWith(userId); TestBed.configureTestingModule({ providers: [ FamiliesPolicyService, - { provide: OrganizationService, useValue: organizationService }, + { provide: vNextOrganizationService, useValue: organizationService }, { provide: PolicyService, useValue: policyService }, + { provide: AccountService, useValue: accountService }, ], }); @@ -40,7 +48,7 @@ describe("FamiliesPolicyService", () => { jest.spyOn(service, "hasSingleEnterpriseOrg$").mockReturnValue(of(true)); const organizations = [{ id: "org1", canManageSponsorships: true }] as Organization[]; - organizationService.getAll$.mockReturnValue(of(organizations)); + organizationService.organizations$.mockReturnValue(of(organizations)); const policies = [{ organizationId: "org1", enabled: true }] as Policy[]; policyService.getAll$.mockReturnValue(of(policies)); @@ -53,7 +61,7 @@ describe("FamiliesPolicyService", () => { jest.spyOn(service, "hasSingleEnterpriseOrg$").mockReturnValue(of(true)); const organizations = [{ id: "org1", canManageSponsorships: true }] as Organization[]; - organizationService.getAll$.mockReturnValue(of(organizations)); + organizationService.organizations$.mockReturnValue(of(organizations)); const policies = [{ organizationId: "org1", enabled: false }] as Policy[]; policyService.getAll$.mockReturnValue(of(policies)); @@ -64,7 +72,7 @@ describe("FamiliesPolicyService", () => { it("should return true when there is exactly one enterprise organization that can manage sponsorships", async () => { const organizations = [{ id: "org1", canManageSponsorships: true }] as Organization[]; - organizationService.getAll$.mockReturnValue(of(organizations)); + organizationService.organizations$.mockReturnValue(of(organizations)); const result = await firstValueFrom(service.hasSingleEnterpriseOrg$()); expect(result).toBe(true); @@ -75,7 +83,7 @@ describe("FamiliesPolicyService", () => { { id: "org1", canManageSponsorships: true }, { id: "org2", canManageSponsorships: true }, ] as Organization[]; - organizationService.getAll$.mockReturnValue(of(organizations)); + organizationService.organizations$.mockReturnValue(of(organizations)); const result = await firstValueFrom(service.hasSingleEnterpriseOrg$()); expect(result).toBe(false); diff --git a/apps/browser/src/services/families-policy.service.ts b/apps/browser/src/services/families-policy.service.ts index 426f39dcfd0..0fdf931c133 100644 --- a/apps/browser/src/services/families-policy.service.ts +++ b/apps/browser/src/services/families-policy.service.ts @@ -1,30 +1,37 @@ import { Injectable } from "@angular/core"; import { map, Observable, of, switchMap } from "rxjs"; -import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; +import { vNextOrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/vnext.organization.service.abstraction"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; import { PolicyType } from "@bitwarden/common/admin-console/enums"; +import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; +import { getUserId } from "@bitwarden/common/auth/services/account.service"; @Injectable({ providedIn: "root" }) export class FamiliesPolicyService { constructor( private policyService: PolicyService, - private organizationService: OrganizationService, + private organizationService: vNextOrganizationService, + private accountService: AccountService, ) {} hasSingleEnterpriseOrg$(): Observable { // Retrieve all organizations the user is part of - return this.organizationService.getAll$().pipe( - map((organizations) => { - // Filter to only those organizations that can manage sponsorships - const sponsorshipOrgs = organizations.filter((org) => org.canManageSponsorships); + return getUserId(this.accountService.activeAccount$).pipe( + switchMap((userId) => + this.organizationService.organizations$(userId).pipe( + map((organizations) => { + // Filter to only those organizations that can manage sponsorships + const sponsorshipOrgs = organizations.filter((org) => org.canManageSponsorships); - // Check if there is exactly one organization that can manage sponsorships. - // This is important because users that are part of multiple organizations - // may always access free bitwarden family menu. We want to restrict access - // to the policy only when there is a single enterprise organization and the free family policy is turn. - return sponsorshipOrgs.length === 1; - }), + // Check if there is exactly one organization that can manage sponsorships. + // This is important because users that are part of multiple organizations + // may always access free bitwarden family menu. We want to restrict access + // to the policy only when there is a single enterprise organization and the free family policy is turn. + return sponsorshipOrgs.length === 1; + }), + ), + ), ); } @@ -34,18 +41,22 @@ export class FamiliesPolicyService { if (!hasSingleEnterpriseOrg) { return of(false); } - return this.organizationService.getAll$().pipe( - map((organizations) => organizations.find((org) => org.canManageSponsorships)?.id), - switchMap((enterpriseOrgId) => - this.policyService - .getAll$(PolicyType.FreeFamiliesSponsorshipPolicy) - .pipe( - map( - (policies) => - policies.find((policy) => policy.organizationId === enterpriseOrgId)?.enabled ?? - false, - ), + return getUserId(this.accountService.activeAccount$).pipe( + switchMap((userId) => + this.organizationService.organizations$(userId).pipe( + map((organizations) => organizations.find((org) => org.canManageSponsorships)?.id), + switchMap((enterpriseOrgId) => + this.policyService + .getAll$(PolicyType.FreeFamiliesSponsorshipPolicy) + .pipe( + map( + (policies) => + policies.find((policy) => policy.organizationId === enterpriseOrgId) + ?.enabled ?? false, + ), + ), ), + ), ), ); }), diff --git a/apps/browser/src/tools/popup/settings/about-page/more-from-bitwarden-page-v2.component.ts b/apps/browser/src/tools/popup/settings/about-page/more-from-bitwarden-page-v2.component.ts index 2d451dddaa7..8b420d5f2e0 100644 --- a/apps/browser/src/tools/popup/settings/about-page/more-from-bitwarden-page-v2.component.ts +++ b/apps/browser/src/tools/popup/settings/about-page/more-from-bitwarden-page-v2.component.ts @@ -1,10 +1,12 @@ import { CommonModule } from "@angular/common"; import { Component } from "@angular/core"; import { RouterModule } from "@angular/router"; -import { Observable, firstValueFrom } from "rxjs"; +import { Observable, firstValueFrom, switchMap } from "rxjs"; import { JslibModule } from "@bitwarden/angular/jslib.module"; -import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; +import { vNextOrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/vnext.organization.service.abstraction"; +import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; +import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service"; import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; import { DialogService, ItemModule } from "@bitwarden/components"; @@ -38,11 +40,14 @@ export class MoreFromBitwardenPageV2Component { private dialogService: DialogService, billingAccountProfileStateService: BillingAccountProfileStateService, private environmentService: EnvironmentService, - private organizationService: OrganizationService, + private organizationService: vNextOrganizationService, + private accountService: AccountService, private familiesPolicyService: FamiliesPolicyService, ) { this.canAccessPremium$ = billingAccountProfileStateService.hasPremiumFromAnySource$; - this.familySponsorshipAvailable$ = this.organizationService.familySponsorshipAvailable$; + this.familySponsorshipAvailable$ = getUserId(this.accountService.activeAccount$).pipe( + switchMap((userId) => this.organizationService.familySponsorshipAvailable$(userId)), + ); this.hasSingleEnterpriseOrg$ = this.familiesPolicyService.hasSingleEnterpriseOrg$(); this.isFreeFamilyPolicyEnabled$ = this.familiesPolicyService.isFreeFamilyPolicyEnabled$(); } diff --git a/apps/browser/src/vault/popup/components/vault-v2/attachments/open-attachments/open-attachments.component.spec.ts b/apps/browser/src/vault/popup/components/vault-v2/attachments/open-attachments/open-attachments.component.spec.ts index 8c1e0641b03..b9c977c95de 100644 --- a/apps/browser/src/vault/popup/components/vault-v2/attachments/open-attachments/open-attachments.component.spec.ts +++ b/apps/browser/src/vault/popup/components/vault-v2/attachments/open-attachments/open-attachments.component.spec.ts @@ -1,9 +1,9 @@ import { ComponentFixture, TestBed } from "@angular/core/testing"; import { Router } from "@angular/router"; import { RouterTestingModule } from "@angular/router/testing"; -import { BehaviorSubject } from "rxjs"; +import { BehaviorSubject, of } from "rxjs"; -import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; +import { vNextOrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/vnext.organization.service.abstraction"; import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions"; @@ -51,7 +51,7 @@ describe("OpenAttachmentsComponent", () => { } as Organization; const getCipher = jest.fn().mockResolvedValue(cipherDomain); - const getOrganization = jest.fn().mockResolvedValue(org); + const organizations$ = jest.fn().mockReturnValue(of([org])); const showFilePopoutMessage = jest.fn().mockReturnValue(false); const mockUserId = Utils.newGuid() as UserId; @@ -61,7 +61,7 @@ describe("OpenAttachmentsComponent", () => { openCurrentPagePopout.mockClear(); getCipher.mockClear(); showToast.mockClear(); - getOrganization.mockClear(); + organizations$.mockClear(); showFilePopoutMessage.mockClear(); await TestBed.configureTestingModule({ @@ -81,8 +81,8 @@ describe("OpenAttachmentsComponent", () => { useValue: { showToast }, }, { - provide: OrganizationService, - useValue: { get: getOrganization }, + provide: vNextOrganizationService, + useValue: { organizations$ }, }, { provide: FilePopoutUtilsService, @@ -141,11 +141,11 @@ describe("OpenAttachmentsComponent", () => { describe("Free Orgs", () => { beforeEach(() => { - component.cipherIsAPartOfFreeOrg = undefined; + component.cipherIsAPartOfFreeOrg = false; }); it("sets `cipherIsAPartOfFreeOrg` to false when the cipher is not a part of an organization", async () => { - cipherView.organizationId = null; + cipherView.organizationId = ""; await component.ngOnInit(); @@ -155,6 +155,7 @@ describe("OpenAttachmentsComponent", () => { it("sets `cipherIsAPartOfFreeOrg` to true when the cipher is a part of a free organization", async () => { cipherView.organizationId = "888-333-333"; org.productTierType = ProductTierType.Free; + org.id = cipherView.organizationId; await component.ngOnInit(); @@ -164,6 +165,7 @@ describe("OpenAttachmentsComponent", () => { it("sets `cipherIsAPartOfFreeOrg` to false when the organization is not free", async () => { cipherView.organizationId = "888-333-333"; org.productTierType = ProductTierType.Families; + org.id = cipherView.organizationId; await component.ngOnInit(); diff --git a/apps/browser/src/vault/popup/components/vault-v2/attachments/open-attachments/open-attachments.component.ts b/apps/browser/src/vault/popup/components/vault-v2/attachments/open-attachments/open-attachments.component.ts index ca620531ca8..2cb39018834 100644 --- a/apps/browser/src/vault/popup/components/vault-v2/attachments/open-attachments/open-attachments.component.ts +++ b/apps/browser/src/vault/popup/components/vault-v2/attachments/open-attachments/open-attachments.component.ts @@ -7,8 +7,12 @@ import { Router } from "@angular/router"; import { firstValueFrom, map } from "rxjs"; import { JslibModule } from "@bitwarden/angular/jslib.module"; -import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; +import { + getOrganizationById, + vNextOrganizationService, +} from "@bitwarden/common/admin-console/abstractions/organization/vnext.organization.service.abstraction"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; +import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions"; import { ProductTierType } from "@bitwarden/common/billing/enums"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; @@ -48,7 +52,7 @@ export class OpenAttachmentsComponent implements OnInit { private router: Router, private billingAccountProfileStateService: BillingAccountProfileStateService, private cipherService: CipherService, - private organizationService: OrganizationService, + private organizationService: vNextOrganizationService, private toastService: ToastService, private i18nService: I18nService, private filePopoutUtilsService: FilePopoutUtilsService, @@ -81,7 +85,12 @@ export class OpenAttachmentsComponent implements OnInit { return; } - const org = await this.organizationService.get(cipher.organizationId); + const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); + const org = await firstValueFrom( + this.organizationService + .organizations$(userId) + .pipe(getOrganizationById(cipher.organizationId)), + ); this.cipherIsAPartOfFreeOrg = org.productTierType === ProductTierType.Free; } diff --git a/apps/browser/src/vault/popup/components/vault-v2/item-more-options/item-more-options.component.ts b/apps/browser/src/vault/popup/components/vault-v2/item-more-options/item-more-options.component.ts index 5d3dee9018e..8cb571663c0 100644 --- a/apps/browser/src/vault/popup/components/vault-v2/item-more-options/item-more-options.component.ts +++ b/apps/browser/src/vault/popup/components/vault-v2/item-more-options/item-more-options.component.ts @@ -7,8 +7,9 @@ import { BehaviorSubject, firstValueFrom, map, switchMap } from "rxjs"; import { filter } from "rxjs/operators"; import { JslibModule } from "@bitwarden/angular/jslib.module"; -import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; +import { vNextOrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/vnext.organization.service.abstraction"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; +import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; import { CipherRepromptType, CipherType } from "@bitwarden/common/vault/enums"; @@ -83,12 +84,13 @@ export class ItemMoreOptionsComponent implements OnInit { private i18nService: I18nService, private vaultPopupAutofillService: VaultPopupAutofillService, private accountService: AccountService, - private organizationService: OrganizationService, + private organizationService: vNextOrganizationService, private cipherAuthorizationService: CipherAuthorizationService, ) {} async ngOnInit(): Promise { - this.hasOrganizations = await this.organizationService.hasOrganizations(); + const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); + this.hasOrganizations = await firstValueFrom(this.organizationService.hasOrganizations(userId)); } get canEdit() { diff --git a/apps/browser/src/vault/popup/components/vault-v2/vault-header/vault-header-v2.component.spec.ts b/apps/browser/src/vault/popup/components/vault-v2/vault-header/vault-header-v2.component.spec.ts index 38ec6056d19..eccaac56bbe 100644 --- a/apps/browser/src/vault/popup/components/vault-v2/vault-header/vault-header-v2.component.spec.ts +++ b/apps/browser/src/vault/popup/components/vault-v2/vault-header/vault-header-v2.component.spec.ts @@ -8,7 +8,7 @@ import { BehaviorSubject, Subject } from "rxjs"; import { CollectionService } from "@bitwarden/admin-console/common"; import { SearchService } from "@bitwarden/common/abstractions/search.service"; -import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; +import { vNextOrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/vnext.organization.service.abstraction"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; @@ -63,7 +63,7 @@ describe("VaultHeaderV2Component", () => { }, { provide: VaultSettingsService, useValue: mock() }, { provide: FolderService, useValue: mock() }, - { provide: OrganizationService, useValue: mock() }, + { provide: vNextOrganizationService, useValue: mock() }, { provide: CollectionService, useValue: mock() }, { provide: PolicyService, useValue: mock() }, { provide: SearchService, useValue: mock() }, diff --git a/apps/browser/src/vault/popup/components/vault/current-tab.component.ts b/apps/browser/src/vault/popup/components/vault/current-tab.component.ts index 156a708015f..03cbd95225a 100644 --- a/apps/browser/src/vault/popup/components/vault/current-tab.component.ts +++ b/apps/browser/src/vault/popup/components/vault/current-tab.component.ts @@ -6,7 +6,9 @@ import { Subject, firstValueFrom, from, Subscription } from "rxjs"; import { debounceTime, switchMap, takeUntil } from "rxjs/operators"; import { SearchService } from "@bitwarden/common/abstractions/search.service"; -import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; +import { vNextOrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/vnext.organization.service.abstraction"; +import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; +import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { AutofillOverlayVisibility } from "@bitwarden/common/autofill/constants"; import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service"; import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service"; @@ -70,7 +72,8 @@ export class CurrentTabComponent implements OnInit, OnDestroy { private searchService: SearchService, private autofillSettingsService: AutofillSettingsServiceAbstraction, private passwordRepromptService: PasswordRepromptService, - private organizationService: OrganizationService, + private organizationService: vNextOrganizationService, + private accountService: AccountService, private vaultFilterService: VaultFilterService, private vaultSettingsService: VaultSettingsService, ) {} @@ -272,7 +275,10 @@ export class CurrentTabComponent implements OnInit, OnDestroy { const dontShowIdentities = !(await firstValueFrom( this.vaultSettingsService.showIdentitiesCurrentTab$, )); - this.showOrganizations = await this.organizationService.hasOrganizations(); + const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); + this.showOrganizations = await firstValueFrom( + this.organizationService.hasOrganizations(userId), + ); if (!dontShowCards) { otherTypes.push(CipherType.Card); } diff --git a/apps/browser/src/vault/popup/components/vault/vault-items.component.ts b/apps/browser/src/vault/popup/components/vault/vault-items.component.ts index 387afcfe217..7125eec887f 100644 --- a/apps/browser/src/vault/popup/components/vault/vault-items.component.ts +++ b/apps/browser/src/vault/popup/components/vault/vault-items.component.ts @@ -3,13 +3,16 @@ import { Location } from "@angular/common"; import { ChangeDetectorRef, Component, NgZone, OnDestroy, OnInit } from "@angular/core"; import { ActivatedRoute, Router } from "@angular/router"; +import { firstValueFrom } from "rxjs"; import { first } from "rxjs/operators"; import { CollectionService, CollectionView } from "@bitwarden/admin-console/common"; import { VaultItemsComponent as BaseVaultItemsComponent } from "@bitwarden/angular/vault/components/vault-items.component"; import { VaultFilter } from "@bitwarden/angular/vault/vault-filter/models/vault-filter.model"; import { SearchService } from "@bitwarden/common/abstractions/search.service"; -import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; +import { vNextOrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/vnext.organization.service.abstraction"; +import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; +import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; @@ -53,7 +56,8 @@ export class VaultItemsComponent extends BaseVaultItemsComponent implements OnIn constructor( searchService: SearchService, - private organizationService: OrganizationService, + private organizationService: vNextOrganizationService, + private accountService: AccountService, private route: ActivatedRoute, private router: Router, private location: Location, @@ -75,7 +79,10 @@ export class VaultItemsComponent extends BaseVaultItemsComponent implements OnIn async ngOnInit() { this.searchTypeSearch = !this.platformUtilsService.isSafari(); - this.showOrganizations = await this.organizationService.hasOrganizations(); + const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); + this.showOrganizations = await firstValueFrom( + this.organizationService.hasOrganizations(userId), + ); this.vaultFilter = this.vaultFilterService.getVaultFilter(); // eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe this.route.queryParams.pipe(first()).subscribe(async (params) => { diff --git a/apps/browser/src/vault/popup/components/vault/vault-select.component.ts b/apps/browser/src/vault/popup/components/vault/vault-select.component.ts index 3c5061a516f..b14a38c44d9 100644 --- a/apps/browser/src/vault/popup/components/vault/vault-select.component.ts +++ b/apps/browser/src/vault/popup/components/vault/vault-select.component.ts @@ -19,6 +19,7 @@ import { BehaviorSubject, combineLatest, concatMap, + firstValueFrom, map, merge, Observable, @@ -26,10 +27,12 @@ import { takeUntil, } from "rxjs"; -import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; +import { vNextOrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/vnext.organization.service.abstraction"; import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction"; import { PolicyType } from "@bitwarden/common/admin-console/enums"; import { Organization } from "@bitwarden/common/admin-console/models/domain/organization"; +import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; +import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; @@ -100,7 +103,8 @@ export class VaultSelectComponent implements OnInit, OnDestroy { private overlay: Overlay, private viewContainerRef: ViewContainerRef, private platformUtilsService: PlatformUtilsService, - private organizationService: OrganizationService, + private organizationService: vNextOrganizationService, + private accountService: AccountService, private policyService: PolicyService, ) {} @@ -113,7 +117,9 @@ export class VaultSelectComponent implements OnInit, OnDestroy { } async ngOnInit() { - this.organizations$ = this.organizationService.memberOrganizations$ + const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); + this.organizations$ = this.organizationService + .memberOrganizations$(userId) .pipe(takeUntil(this._destroy)) .pipe(map((orgs) => orgs.sort(Utils.getSortFunction(this.i18nService, "name"))));