1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 22:03:36 +00:00

[PM-2347] Refresh configs when environment urls change (#5507)

* [PM-2347] Re fetch feature flags when environment urls change and update UI.
This commit is contained in:
André Bispo
2023-05-25 14:38:23 +01:00
committed by GitHub
parent 8201bd4e34
commit 1a9a328d39
5 changed files with 37 additions and 16 deletions

View File

@@ -501,7 +501,8 @@ export default class MainBackground {
this.configService = new ConfigService( this.configService = new ConfigService(
this.stateService, this.stateService,
this.configApiService, this.configApiService,
this.authService this.authService,
this.environmentService
); );
const systemUtilsServiceReloadCallback = () => { const systemUtilsServiceReloadCallback = () => {

View File

@@ -489,7 +489,12 @@ function getBgService<T>(service: keyof MainBackground) {
{ {
provide: ConfigServiceAbstraction, provide: ConfigServiceAbstraction,
useClass: BrowserConfigService, useClass: BrowserConfigService,
deps: [StateServiceAbstraction, ConfigApiServiceAbstraction], deps: [
StateServiceAbstraction,
ConfigApiServiceAbstraction,
AuthServiceAbstraction,
EnvironmentService,
],
}, },
{ {
provide: DialogServiceAbstraction, provide: DialogServiceAbstraction,

View File

@@ -2,7 +2,7 @@ import { animate, state, style, transition, trigger } from "@angular/animations"
import { ConnectedPosition } from "@angular/cdk/overlay"; import { ConnectedPosition } from "@angular/cdk/overlay";
import { Component, EventEmitter, OnDestroy, OnInit, Output } from "@angular/core"; import { Component, EventEmitter, OnDestroy, OnInit, Output } from "@angular/core";
import { Router } from "@angular/router"; import { Router } from "@angular/router";
import { Subject } from "rxjs"; import { Subject, takeUntil } from "rxjs";
import { ConfigServiceAbstraction } from "@bitwarden/common/abstractions/config/config.service.abstraction"; import { ConfigServiceAbstraction } from "@bitwarden/common/abstractions/config/config.service.abstraction";
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service"; import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
@@ -34,11 +34,11 @@ import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
}) })
export class EnvironmentSelectorComponent implements OnInit, OnDestroy { export class EnvironmentSelectorComponent implements OnInit, OnDestroy {
@Output() onOpenSelfHostedSettings = new EventEmitter(); @Output() onOpenSelfHostedSettings = new EventEmitter();
euServerFlagEnabled: boolean;
isOpen = false; isOpen = false;
showingModal = false; showingModal = false;
selectedEnvironment: ServerEnvironment; selectedEnvironment: ServerEnvironment;
ServerEnvironmentType = ServerEnvironment; ServerEnvironmentType = ServerEnvironment;
euServerFlagEnabled: boolean;
overlayPostition: ConnectedPosition[] = [ overlayPostition: ConnectedPosition[] = [
{ {
originX: "start", originX: "start",
@@ -56,9 +56,9 @@ export class EnvironmentSelectorComponent implements OnInit, OnDestroy {
) {} ) {}
async ngOnInit() { async ngOnInit() {
this.euServerFlagEnabled = await this.configService.getFeatureFlagBool( this.configService.serverConfig$.pipe(takeUntil(this.componentDestroyed$)).subscribe(() => {
FeatureFlag.DisplayEuEnvironmentFlag this.updateEnvironmentInfo();
); });
this.updateEnvironmentInfo(); this.updateEnvironmentInfo();
} }
@@ -69,6 +69,9 @@ export class EnvironmentSelectorComponent implements OnInit, OnDestroy {
async toggle(option: ServerEnvironment) { async toggle(option: ServerEnvironment) {
this.isOpen = !this.isOpen; this.isOpen = !this.isOpen;
if (option === null) {
return;
}
if (option === ServerEnvironment.EU) { if (option === ServerEnvironment.EU) {
await this.environmentService.setUrls({ base: "https://vault.bitwarden.eu" }); await this.environmentService.setUrls({ base: "https://vault.bitwarden.eu" });
} else if (option === ServerEnvironment.US) { } else if (option === ServerEnvironment.US) {
@@ -79,7 +82,10 @@ export class EnvironmentSelectorComponent implements OnInit, OnDestroy {
this.updateEnvironmentInfo(); this.updateEnvironmentInfo();
} }
updateEnvironmentInfo() { async updateEnvironmentInfo() {
this.euServerFlagEnabled = await this.configService.getFeatureFlagBool(
FeatureFlag.DisplayEuEnvironmentFlag
);
const webvaultUrl = this.environmentService.getWebVaultUrl(); const webvaultUrl = this.environmentService.getWebVaultUrl();
if (this.environmentService.isSelfHosted()) { if (this.environmentService.isSelfHosted()) {
this.selectedEnvironment = ServerEnvironment.SelfHosted; this.selectedEnvironment = ServerEnvironment.SelfHosted;

View File

@@ -615,7 +615,12 @@ import { AbstractThemingService } from "./theming/theming.service.abstraction";
{ {
provide: ConfigServiceAbstraction, provide: ConfigServiceAbstraction,
useClass: ConfigService, useClass: ConfigService,
deps: [StateServiceAbstraction, ConfigApiServiceAbstraction, AuthServiceAbstraction], deps: [
StateServiceAbstraction,
ConfigApiServiceAbstraction,
AuthServiceAbstraction,
EnvironmentServiceAbstraction,
],
}, },
{ {
provide: ConfigApiServiceAbstraction, provide: ConfigApiServiceAbstraction,

View File

@@ -1,8 +1,9 @@
import { BehaviorSubject, concatMap, timer } from "rxjs"; import { BehaviorSubject, concatMap, from, timer } from "rxjs";
import { ConfigApiServiceAbstraction } from "../../abstractions/config/config-api.service.abstraction"; import { ConfigApiServiceAbstraction } from "../../abstractions/config/config-api.service.abstraction";
import { ConfigServiceAbstraction } from "../../abstractions/config/config.service.abstraction"; import { ConfigServiceAbstraction } from "../../abstractions/config/config.service.abstraction";
import { ServerConfig } from "../../abstractions/config/server-config"; import { ServerConfig } from "../../abstractions/config/server-config";
import { EnvironmentService } from "../../abstractions/environment.service";
import { StateService } from "../../abstractions/state.service"; import { StateService } from "../../abstractions/state.service";
import { AuthService } from "../../auth/abstractions/auth.service"; import { AuthService } from "../../auth/abstractions/auth.service";
import { AuthenticationStatus } from "../../auth/enums/authentication-status"; import { AuthenticationStatus } from "../../auth/enums/authentication-status";
@@ -16,15 +17,18 @@ export class ConfigService implements ConfigServiceAbstraction {
constructor( constructor(
private stateService: StateService, private stateService: StateService,
private configApiService: ConfigApiServiceAbstraction, private configApiService: ConfigApiServiceAbstraction,
private authService: AuthService private authService: AuthService,
private environmentService: EnvironmentService
) { ) {
// Re-fetch the server config every hour // Re-fetch the server config every hour
timer(0, 1000 * 3600) timer(0, 1000 * 3600)
.pipe( .pipe(concatMap(() => from(this.fetchServerConfig())))
concatMap(async () => { .subscribe((serverConfig) => {
return await this.fetchServerConfig(); this._serverConfig.next(serverConfig);
}) });
)
this.environmentService.urls
.pipe(concatMap(() => from(this.fetchServerConfig())))
.subscribe((serverConfig) => { .subscribe((serverConfig) => {
this._serverConfig.next(serverConfig); this._serverConfig.next(serverConfig);
}); });