1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00

Create browser-synced Policy Service

This commit is contained in:
Matt Gibson
2022-11-16 19:02:46 -05:00
parent 430e10c221
commit 5d577a992d
5 changed files with 33 additions and 7 deletions

View File

@@ -64,7 +64,6 @@ import { NotificationsService } from "@bitwarden/common/services/notifications.s
import { OrganizationService } from "@bitwarden/common/services/organization/organization.service";
import { PasswordGenerationService } from "@bitwarden/common/services/passwordGeneration.service";
import { PolicyApiService } from "@bitwarden/common/services/policy/policy-api.service";
import { PolicyService } from "@bitwarden/common/services/policy/policy.service";
import { ProviderService } from "@bitwarden/common/services/provider.service";
import { SearchService } from "@bitwarden/common/services/search.service";
import { SendService } from "@bitwarden/common/services/send.service";
@@ -92,6 +91,7 @@ import { AutofillService as AutofillServiceAbstraction } from "../services/abstr
import { StateService as StateServiceAbstraction } from "../services/abstractions/state.service";
import AutofillService from "../services/autofill.service";
import { BrowserEnvironmentService } from "../services/browser-environment.service";
import { BrowserPolicyService } from "../services/browser-policy.service";
import { BrowserCryptoService } from "../services/browserCrypto.service";
import BrowserLocalStorageService from "../services/browserLocalStorage.service";
import BrowserMessagingService from "../services/browserMessaging.service";
@@ -318,7 +318,7 @@ export default class MainBackground {
);
this.syncNotifierService = new SyncNotifierService();
this.organizationService = new OrganizationService(this.stateService, this.syncNotifierService);
this.policyService = new PolicyService(this.stateService, this.organizationService);
this.policyService = new BrowserPolicyService(this.stateService, this.organizationService);
this.policyApiService = new PolicyApiService(
this.policyService,
this.apiService,

View File

@@ -1,5 +1,6 @@
import { PolicyService as AbstractPolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction";
import { PolicyService } from "@bitwarden/common/services/policy/policy.service";
import { BrowserPolicyService } from "../../services/browser-policy.service";
import { CachedServices, factory, FactoryOptions } from "./factory-options";
import {
@@ -26,7 +27,7 @@ export function policyServiceFactory(
"policyService",
opts,
async () =>
new PolicyService(
new BrowserPolicyService(
await stateServiceFactory(cache, opts),
await organizationServiceFactory(cache, opts)
)

View File

@@ -57,6 +57,7 @@ import { BrowserApi } from "../../browser/browserApi";
import { AutofillService } from "../../services/abstractions/autofill.service";
import { StateService as StateServiceAbstraction } from "../../services/abstractions/state.service";
import { BrowserEnvironmentService } from "../../services/browser-environment.service";
import { BrowserPolicyService } from "../../services/browser-policy.service";
import { BrowserFileDownloadService } from "../../services/browserFileDownloadService";
import BrowserMessagingService from "../../services/browserMessaging.service";
import BrowserMessagingPrivateModePopupService from "../../services/browserMessagingPrivateModePopup.service";
@@ -190,8 +191,13 @@ function getBgService<T>(service: keyof MainBackground) {
{ provide: EventService, useFactory: getBgService<EventService>("eventService"), deps: [] },
{
provide: PolicyService,
useFactory: getBgService<PolicyService>("policyService"),
deps: [],
useFactory: (
stateService: StateServiceAbstraction,
organizationService: OrganizationService
) => {
return new BrowserPolicyService(stateService, organizationService);
},
deps: [StateServiceAbstraction, OrganizationService],
},
{
provide: PolicyApiServiceAbstraction,

View File

@@ -0,0 +1,19 @@
import { BehaviorSubject } from "rxjs";
import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction";
import { Policy } from "@bitwarden/common/models/domain/policy";
import { PolicyService } from "@bitwarden/common/services/policy/policy.service";
import { browserSession, sessionSync } from "../decorators/session-sync-observable";
import { StateService } from "./abstractions/state.service";
@browserSession
export class BrowserPolicyService extends PolicyService {
@sessionSync({ ctor: Policy, initializeAsArray: true })
protected _policies: BehaviorSubject<Policy[]>;
constructor(stateService: StateService, organizationService: OrganizationService) {
super(stateService, organizationService);
}
}

View File

@@ -16,7 +16,7 @@ import { ListResponse } from "../../models/response/list.response";
import { PolicyResponse } from "../../models/response/policy.response";
export class PolicyService implements InternalPolicyServiceAbstraction {
private _policies: BehaviorSubject<Policy[]> = new BehaviorSubject([]);
protected _policies: BehaviorSubject<Policy[]> = new BehaviorSubject([]);
policies$ = this._policies.asObservable();