mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
Migrate OrganizationService to StateProvider (#7895)
This commit is contained in:
@@ -16,7 +16,7 @@ export const organizationEnabledGuard: CanActivateFn = async (route: ActivatedRo
|
||||
await syncService.fullSync(false);
|
||||
}
|
||||
|
||||
const org = orgService.get(route.params.organizationId);
|
||||
const org = await orgService.get(route.params.organizationId);
|
||||
if (org == null || !org.canAccessSecretsManager) {
|
||||
return createUrlTreeFromSnapshot(route, ["/"]);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ export class NavigationComponent {
|
||||
protected readonly logo = SecretsManagerLogo;
|
||||
protected orgFilter = (org: Organization) => org.canAccessSecretsManager;
|
||||
protected isAdmin$ = this.route.params.pipe(
|
||||
map((params) => this.organizationService.get(params.organizationId)?.isAdmin),
|
||||
map(async (params) => (await this.organizationService.get(params.organizationId))?.isAdmin),
|
||||
);
|
||||
|
||||
constructor(
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
take,
|
||||
share,
|
||||
firstValueFrom,
|
||||
concatMap,
|
||||
} from "rxjs";
|
||||
|
||||
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||
@@ -105,7 +106,7 @@ export class OverviewComponent implements OnInit, OnDestroy {
|
||||
|
||||
orgId$
|
||||
.pipe(
|
||||
map((orgId) => this.organizationService.get(orgId)),
|
||||
concatMap(async (orgId) => await this.organizationService.get(orgId)),
|
||||
takeUntil(this.destroy$),
|
||||
)
|
||||
.subscribe((org) => {
|
||||
|
||||
@@ -63,7 +63,9 @@ export class ProjectSecretsComponent {
|
||||
switchMap(async ([_, params]) => {
|
||||
this.organizationId = params.organizationId;
|
||||
this.projectId = params.projectId;
|
||||
this.organizationEnabled = this.organizationService.get(params.organizationId)?.enabled;
|
||||
this.organizationEnabled = (
|
||||
await this.organizationService.get(params.organizationId)
|
||||
)?.enabled;
|
||||
return await this.getSecretsByProject();
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
Subject,
|
||||
switchMap,
|
||||
takeUntil,
|
||||
map,
|
||||
concatMap,
|
||||
} from "rxjs";
|
||||
|
||||
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||
@@ -70,11 +72,18 @@ export class ProjectComponent implements OnInit, OnDestroy {
|
||||
}),
|
||||
);
|
||||
|
||||
this.route.params.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
||||
this.organizationId = params.organizationId;
|
||||
this.projectId = params.projectId;
|
||||
this.organizationEnabled = this.organizationService.get(params.organizationId)?.enabled;
|
||||
});
|
||||
const projectId$ = this.route.params.pipe(map((p) => p.projectId));
|
||||
const organization$ = this.route.params.pipe(
|
||||
concatMap((params) => this.organizationService.get$(params.organizationId)),
|
||||
);
|
||||
|
||||
combineLatest([projectId$, organization$])
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(([projectId, organization]) => {
|
||||
this.organizationId = organization.id;
|
||||
this.projectId = projectId;
|
||||
this.organizationEnabled = organization.enabled;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
|
||||
@@ -51,7 +51,9 @@ export class ProjectsComponent implements OnInit {
|
||||
]).pipe(
|
||||
switchMap(async ([params]) => {
|
||||
this.organizationId = params.organizationId;
|
||||
this.organizationEnabled = this.organizationService.get(params.organizationId)?.enabled;
|
||||
this.organizationEnabled = (
|
||||
await this.organizationService.get(params.organizationId)
|
||||
)?.enabled;
|
||||
|
||||
return await this.getProjects();
|
||||
}),
|
||||
|
||||
@@ -87,7 +87,7 @@ export class SecretDialogComponent implements OnInit {
|
||||
this.formGroup.get("project").setValue(this.data.projectId);
|
||||
}
|
||||
|
||||
if (this.organizationService.get(this.data.organizationId)?.isAdmin) {
|
||||
if ((await this.organizationService.get(this.data.organizationId))?.isAdmin) {
|
||||
this.formGroup.get("project").removeValidators(Validators.required);
|
||||
this.formGroup.get("project").updateValueAndValidity();
|
||||
}
|
||||
|
||||
@@ -47,7 +47,9 @@ export class SecretsComponent implements OnInit {
|
||||
combineLatestWith(this.route.params),
|
||||
switchMap(async ([_, params]) => {
|
||||
this.organizationId = params.organizationId;
|
||||
this.organizationEnabled = this.organizationService.get(params.organizationId)?.enabled;
|
||||
this.organizationEnabled = (
|
||||
await this.organizationService.get(params.organizationId)
|
||||
)?.enabled;
|
||||
|
||||
return await this.getSecrets();
|
||||
}),
|
||||
|
||||
@@ -46,7 +46,9 @@ export class ServiceAccountsComponent implements OnInit {
|
||||
]).pipe(
|
||||
switchMap(async ([params]) => {
|
||||
this.organizationId = params.organizationId;
|
||||
this.organizationEnabled = this.organizationService.get(params.organizationId)?.enabled;
|
||||
this.organizationEnabled = (
|
||||
await this.organizationService.get(params.organizationId)
|
||||
)?.enabled;
|
||||
|
||||
return await this.getServiceAccounts();
|
||||
}),
|
||||
|
||||
@@ -26,7 +26,7 @@ describe("AccessPolicySelectorService", () => {
|
||||
describe("showAccessRemovalWarning", () => {
|
||||
it("returns false when current user is admin", async () => {
|
||||
const org = orgFactory();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const selectedPolicyValues: ApItemValueType[] = [];
|
||||
|
||||
@@ -38,7 +38,7 @@ describe("AccessPolicySelectorService", () => {
|
||||
it("returns false when current user is owner", async () => {
|
||||
const org = orgFactory();
|
||||
org.type = OrganizationUserType.Owner;
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const selectedPolicyValues: ApItemValueType[] = [];
|
||||
|
||||
@@ -49,7 +49,7 @@ describe("AccessPolicySelectorService", () => {
|
||||
|
||||
it("returns true when current user isn't owner/admin and all policies are removed", async () => {
|
||||
const org = setupUserOrg();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const selectedPolicyValues: ApItemValueType[] = [];
|
||||
|
||||
@@ -60,7 +60,7 @@ describe("AccessPolicySelectorService", () => {
|
||||
|
||||
it("returns true when current user isn't owner/admin and user policy is set to canRead", async () => {
|
||||
const org = setupUserOrg();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const selectedPolicyValues: ApItemValueType[] = [];
|
||||
selectedPolicyValues.push(
|
||||
@@ -77,7 +77,7 @@ describe("AccessPolicySelectorService", () => {
|
||||
|
||||
it("returns false when current user isn't owner/admin and user policy is set to canReadWrite", async () => {
|
||||
const org = setupUserOrg();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const selectedPolicyValues: ApItemValueType[] = [
|
||||
createApItemValueType({
|
||||
@@ -93,7 +93,7 @@ describe("AccessPolicySelectorService", () => {
|
||||
|
||||
it("returns true when current user isn't owner/admin and a group Read policy is submitted that the user is a member of", async () => {
|
||||
const org = setupUserOrg();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const selectedPolicyValues: ApItemValueType[] = [
|
||||
createApItemValueType({
|
||||
@@ -111,7 +111,7 @@ describe("AccessPolicySelectorService", () => {
|
||||
|
||||
it("returns false when current user isn't owner/admin and a group ReadWrite policy is submitted that the user is a member of", async () => {
|
||||
const org = setupUserOrg();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const selectedPolicyValues: ApItemValueType[] = [
|
||||
createApItemValueType({
|
||||
@@ -129,7 +129,7 @@ describe("AccessPolicySelectorService", () => {
|
||||
|
||||
it("returns true when current user isn't owner/admin and a group ReadWrite policy is submitted that the user is not a member of", async () => {
|
||||
const org = setupUserOrg();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const selectedPolicyValues: ApItemValueType[] = [
|
||||
createApItemValueType({
|
||||
@@ -147,7 +147,7 @@ describe("AccessPolicySelectorService", () => {
|
||||
|
||||
it("returns false when current user isn't owner/admin, user policy is set to CanRead, and user is in read write group", async () => {
|
||||
const org = setupUserOrg();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const selectedPolicyValues: ApItemValueType[] = [
|
||||
createApItemValueType({
|
||||
@@ -169,7 +169,7 @@ describe("AccessPolicySelectorService", () => {
|
||||
|
||||
it("returns true when current user isn't owner/admin, user policy is set to CanRead, and user is not in ReadWrite group", async () => {
|
||||
const org = setupUserOrg();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const selectedPolicyValues: ApItemValueType[] = [
|
||||
createApItemValueType({
|
||||
@@ -191,7 +191,7 @@ describe("AccessPolicySelectorService", () => {
|
||||
|
||||
it("returns true when current user isn't owner/admin, user policy is set to CanRead, and user is in Read group", async () => {
|
||||
const org = setupUserOrg();
|
||||
organizationService.get.calledWith(org.id).mockReturnValue(org);
|
||||
organizationService.get.calledWith(org.id).mockResolvedValue(org);
|
||||
|
||||
const selectedPolicyValues: ApItemValueType[] = [
|
||||
createApItemValueType({
|
||||
|
||||
@@ -17,7 +17,7 @@ export class AccessPolicySelectorService {
|
||||
organizationId: string,
|
||||
selectedPoliciesValues: ApItemValueType[],
|
||||
): Promise<boolean> {
|
||||
const organization = this.organizationService.get(organizationId);
|
||||
const organization = await this.organizationService.get(organizationId);
|
||||
if (organization.isOwner || organization.isAdmin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Component, OnDestroy, OnInit } from "@angular/core";
|
||||
import { ActivatedRoute } from "@angular/router";
|
||||
import { Subject, takeUntil } from "rxjs";
|
||||
import { Subject, takeUntil, concatMap, map } from "rxjs";
|
||||
|
||||
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||
import { DialogService } from "@bitwarden/components";
|
||||
@@ -34,10 +34,19 @@ export class NewMenuComponent implements OnInit, OnDestroy {
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.params.pipe(takeUntil(this.destroy$)).subscribe((params: any) => {
|
||||
this.organizationId = params.organizationId;
|
||||
this.organizationEnabled = this.organizationService.get(params.organizationId)?.enabled;
|
||||
});
|
||||
this.route.params
|
||||
.pipe(
|
||||
concatMap((params) =>
|
||||
this.organizationService
|
||||
.get$(params.organizationId)
|
||||
.pipe(map((organization) => ({ params, organization }))),
|
||||
),
|
||||
takeUntil(this.destroy$),
|
||||
)
|
||||
.subscribe((mapResult) => {
|
||||
this.organizationId = mapResult?.params?.organizationId;
|
||||
this.organizationEnabled = mapResult?.organization?.enabled;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Component } from "@angular/core";
|
||||
import { ActivatedRoute } from "@angular/router";
|
||||
import { map } from "rxjs";
|
||||
import { map, concatMap } from "rxjs";
|
||||
|
||||
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
|
||||
import { Icon, Icons } from "@bitwarden/components";
|
||||
@@ -16,6 +16,7 @@ export class OrgSuspendedComponent {
|
||||
|
||||
protected NoAccess: Icon = Icons.NoAccess;
|
||||
protected organizationName$ = this.route.params.pipe(
|
||||
map((params) => this.organizationService.get(params.organizationId)?.name),
|
||||
concatMap((params) => this.organizationService.get$(params.organizationId)),
|
||||
map((org) => org?.name),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user