mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 05:13:29 +00:00
Migrate OrganizationService to StateProvider (#7895)
This commit is contained in:
@@ -17,7 +17,7 @@ export class IsPaidOrgGuard implements CanActivate {
|
||||
) {}
|
||||
|
||||
async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
const org = this.organizationService.get(route.params.organizationId);
|
||||
const org = await this.organizationService.get(route.params.organizationId);
|
||||
|
||||
if (org == null) {
|
||||
return this.router.createUrlTree(["/"]);
|
||||
|
||||
@@ -66,7 +66,7 @@ describe("Organization Permissions Guard", () => {
|
||||
|
||||
it("permits navigation if no permissions are specified", async () => {
|
||||
const org = orgFactory();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const actual = await organizationPermissionsGuard.canActivate(route, state);
|
||||
|
||||
@@ -81,7 +81,7 @@ describe("Organization Permissions Guard", () => {
|
||||
};
|
||||
|
||||
const org = orgFactory();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const actual = await organizationPermissionsGuard.canActivate(route, state);
|
||||
|
||||
@@ -104,7 +104,7 @@ describe("Organization Permissions Guard", () => {
|
||||
});
|
||||
|
||||
const org = orgFactory();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const actual = await organizationPermissionsGuard.canActivate(route, state);
|
||||
|
||||
@@ -124,7 +124,7 @@ describe("Organization Permissions Guard", () => {
|
||||
}),
|
||||
});
|
||||
const org = orgFactory();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const actual = await organizationPermissionsGuard.canActivate(route, state);
|
||||
|
||||
@@ -141,7 +141,7 @@ describe("Organization Permissions Guard", () => {
|
||||
type: OrganizationUserType.Admin,
|
||||
enabled: false,
|
||||
});
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const actual = await organizationPermissionsGuard.canActivate(route, state);
|
||||
|
||||
@@ -153,7 +153,7 @@ describe("Organization Permissions Guard", () => {
|
||||
type: OrganizationUserType.Owner,
|
||||
enabled: false,
|
||||
});
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const actual = await organizationPermissionsGuard.canActivate(route, state);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export class OrganizationPermissionsGuard implements CanActivate {
|
||||
await this.syncService.fullSync(false);
|
||||
}
|
||||
|
||||
const org = this.organizationService.get(route.params.organizationId);
|
||||
const org = await this.organizationService.get(route.params.organizationId);
|
||||
if (org == null) {
|
||||
return this.router.createUrlTree(["/"]);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export class OrganizationRedirectGuard implements CanActivate {
|
||||
) {}
|
||||
|
||||
async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
const org = this.organizationService.get(route.params.organizationId);
|
||||
const org = await this.organizationService.get(route.params.organizationId);
|
||||
|
||||
const customRedirect = route.data?.autoRedirectCallback;
|
||||
if (customRedirect) {
|
||||
|
||||
@@ -143,7 +143,7 @@ export class PeopleComponent
|
||||
|
||||
async ngOnInit() {
|
||||
const organization$ = this.route.params.pipe(
|
||||
map((params) => this.organizationService.get(params.organizationId)),
|
||||
concatMap((params) => this.organizationService.get$(params.organizationId)),
|
||||
shareReplay({ refCount: true, bufferSize: 1 }),
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Component, OnInit } from "@angular/core";
|
||||
import { ActivatedRoute, NavigationEnd, Router } from "@angular/router";
|
||||
import { filter, map, Observable, startWith } from "rxjs";
|
||||
import { filter, map, Observable, startWith, concatMap } from "rxjs";
|
||||
|
||||
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||
|
||||
@@ -28,7 +28,7 @@ export class ReportsHomeComponent implements OnInit {
|
||||
);
|
||||
|
||||
this.reports$ = this.route.params.pipe(
|
||||
map((params) => this.organizationService.get(params.organizationId)),
|
||||
concatMap((params) => this.organizationService.get$(params.organizationId)),
|
||||
map((org) => this.buildReports(org.isFreeOrg)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Component } from "@angular/core";
|
||||
import { ActivatedRoute } from "@angular/router";
|
||||
import { concatMap, takeUntil } from "rxjs";
|
||||
import { concatMap, takeUntil, map } from "rxjs";
|
||||
import { tap } from "rxjs/operators";
|
||||
|
||||
import { ModalService } from "@bitwarden/angular/services/modal.service";
|
||||
@@ -42,9 +42,14 @@ export class TwoFactorSetupComponent extends BaseTwoFactorSetupComponent {
|
||||
async ngOnInit() {
|
||||
this.route.params
|
||||
.pipe(
|
||||
tap((params) => {
|
||||
this.organizationId = params.organizationId;
|
||||
this.organization = this.organizationService.get(this.organizationId);
|
||||
concatMap((params) =>
|
||||
this.organizationService
|
||||
.get$(params.organizationId)
|
||||
.pipe(map((organization) => ({ params, organization }))),
|
||||
),
|
||||
tap(async (mapResponse) => {
|
||||
this.organizationId = mapResponse.params.organizationId;
|
||||
this.organization = mapResponse.organization;
|
||||
}),
|
||||
concatMap(async () => await super.ngOnInit()),
|
||||
takeUntil(this.destroy$),
|
||||
|
||||
@@ -11,7 +11,7 @@ import { NotificationsService } from "@bitwarden/common/abstractions/notificatio
|
||||
import { SearchService } from "@bitwarden/common/abstractions/search.service";
|
||||
import { SettingsService } from "@bitwarden/common/abstractions/settings.service";
|
||||
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vault-timeout/vault-timeout.service";
|
||||
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||
import { InternalOrganizationServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
||||
@@ -92,7 +92,7 @@ export class AppComponent implements OnDestroy, OnInit {
|
||||
private biometricStateService: BiometricStateService,
|
||||
private stateEventRunnerService: StateEventRunnerService,
|
||||
private paymentMethodWarningService: PaymentMethodWarningService,
|
||||
private organizationService: OrganizationService,
|
||||
private organizationService: InternalOrganizationServiceAbstraction,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
@@ -150,7 +150,7 @@ export class OrganizationPlansComponent implements OnInit, OnDestroy {
|
||||
|
||||
async ngOnInit() {
|
||||
if (this.organizationId) {
|
||||
this.organization = this.organizationService.get(this.organizationId);
|
||||
this.organization = await this.organizationService.get(this.organizationId);
|
||||
this.billing = await this.organizationApiService.getBilling(this.organizationId);
|
||||
this.sub = await this.organizationApiService.getSubscription(this.organizationId);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ export class OrganizationSubscriptionCloudComponent implements OnInit, OnDestroy
|
||||
return;
|
||||
}
|
||||
this.loading = true;
|
||||
this.userOrg = this.organizationService.get(this.organizationId);
|
||||
this.userOrg = await this.organizationService.get(this.organizationId);
|
||||
if (this.userOrg.canViewSubscription) {
|
||||
this.sub = await this.organizationApiService.getSubscription(this.organizationId);
|
||||
this.lineItems = this.sub?.subscription?.items;
|
||||
|
||||
@@ -110,7 +110,7 @@ export class OrganizationSubscriptionSelfhostComponent implements OnInit, OnDest
|
||||
return;
|
||||
}
|
||||
this.loading = true;
|
||||
this.userOrg = this.organizationService.get(this.organizationId);
|
||||
this.userOrg = await this.organizationService.get(this.organizationId);
|
||||
if (this.userOrg.canViewSubscription) {
|
||||
const subscriptionResponse = await this.organizationApiService.getSubscription(
|
||||
this.organizationId,
|
||||
|
||||
@@ -139,9 +139,9 @@ export class CollectionDialogComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
async loadOrg(orgId: string, collectionIds: string[]) {
|
||||
const organization$ = of(this.organizationService.get(orgId)).pipe(
|
||||
shareReplay({ refCount: true, bufferSize: 1 }),
|
||||
);
|
||||
const organization$ = this.organizationService
|
||||
.get$(orgId)
|
||||
.pipe(shareReplay({ refCount: true, bufferSize: 1 }));
|
||||
const groups$ = organization$.pipe(
|
||||
switchMap((organization) => {
|
||||
if (!organization.useGroups) {
|
||||
|
||||
@@ -518,7 +518,7 @@ export class VaultComponent implements OnInit, OnDestroy {
|
||||
this.messagingService.send("premiumRequired");
|
||||
return;
|
||||
} else if (cipher.organizationId != null) {
|
||||
const org = this.organizationService.get(cipher.organizationId);
|
||||
const org = await this.organizationService.get(cipher.organizationId);
|
||||
if (org != null && (org.maxStorageGb == null || org.maxStorageGb === 0)) {
|
||||
this.messagingService.send("upgradeOrganization", {
|
||||
organizationId: cipher.organizationId,
|
||||
@@ -697,7 +697,7 @@ export class VaultComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
async deleteCollection(collection: CollectionView): Promise<void> {
|
||||
const organization = this.organizationService.get(collection.organizationId);
|
||||
const organization = await this.organizationService.get(collection.organizationId);
|
||||
if (!collection.canDelete(organization)) {
|
||||
this.platformUtilsService.showToast(
|
||||
"error",
|
||||
|
||||
Reference in New Issue
Block a user