From 4074c2a45f26ebb589ec70a2cc46a069ac09fd4c Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Mon, 10 Jan 2022 12:25:38 -0500 Subject: [PATCH] [Bug] [Account Switching] Ensure EnvironmentUrls Pull From The Correction Location On Account Add (#602) * [bug] Fully initilize environmentUrls default value We want the full environmentUrls object to be saved to storage with null values as an indicator of using BW cloud. Currently the initilization behavior creates an empty object instead. Setting property values returns the correct behavior. * [bug] Return the correct environmentUrls when scaffloging a new account To allow for setting environmentUrls before an account is created we save that value as a global setting and then apply it to any newly authed accounts. There is a bug that will instead save the urls used by the previous logged in account, making account switching with multiple servers cause errors. This commit resolves this by specifically getting environementUrls from global state when creating a new account --- common/src/abstractions/state.service.ts | 5 +++-- common/src/models/domain/environmentUrls.ts | 16 ++++++++-------- common/src/services/state.service.ts | 15 ++++++++++----- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/common/src/abstractions/state.service.ts b/common/src/abstractions/state.service.ts index 5dd3da2e87..693feb7eb3 100644 --- a/common/src/abstractions/state.service.ts +++ b/common/src/abstractions/state.service.ts @@ -14,6 +14,7 @@ import { SendData } from "../models/data/sendData"; import { Account } from "../models/domain/account"; import { EncString } from "../models/domain/encString"; +import { EnvironmentUrls } from "../models/domain/environmentUrls"; import { GeneratedPasswordHistory } from "../models/domain/generatedPasswordHistory"; import { Policy } from "../models/domain/policy"; import { StorageOptions } from "../models/domain/storageOptions"; @@ -213,8 +214,8 @@ export abstract class StateService { setEntityId: (value: string, options?: StorageOptions) => Promise; getEntityType: (options?: StorageOptions) => Promise; setEntityType: (value: string, options?: StorageOptions) => Promise; - getEnvironmentUrls: (options?: StorageOptions) => Promise; - setEnvironmentUrls: (value: any, options?: StorageOptions) => Promise; + getEnvironmentUrls: (options?: StorageOptions) => Promise; + setEnvironmentUrls: (value: EnvironmentUrls, options?: StorageOptions) => Promise; getEquivalentDomains: (options?: StorageOptions) => Promise; setEquivalentDomains: (value: string, options?: StorageOptions) => Promise; getEventCollection: (options?: StorageOptions) => Promise; diff --git a/common/src/models/domain/environmentUrls.ts b/common/src/models/domain/environmentUrls.ts index c80265924c..d4fd173c83 100644 --- a/common/src/models/domain/environmentUrls.ts +++ b/common/src/models/domain/environmentUrls.ts @@ -1,10 +1,10 @@ export class EnvironmentUrls { - base: string; - api: string; - identity: string; - icons: string; - notifications: string; - events: string; - webVault: string; - keyConnector: string; + base: string = null; + api: string = null; + identity: string = null; + icons: string = null; + notifications: string = null; + events: string = null; + webVault: string = null; + keyConnector: string = null; } diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index aefdf6652a..0f6b1c9e3e 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -1361,15 +1361,15 @@ export class StateService ); } - async getEnvironmentUrls(options?: StorageOptions): Promise { - options = this.reconcileOptions(options, await this.defaultOnDiskOptions()); + async getEnvironmentUrls(options?: StorageOptions): Promise { if (this.state.activeUserId == null) { - return (await this.getGlobals(options)).environmentUrls ?? new EnvironmentUrls(); + return await this.getGlobalEnvironmentUrls(options); } + options = this.reconcileOptions(options, await this.defaultOnDiskOptions()); return (await this.getAccount(options))?.settings?.environmentUrls ?? new EnvironmentUrls(); } - async setEnvironmentUrls(value: any, options?: StorageOptions): Promise { + async setEnvironmentUrls(value: EnvironmentUrls, options?: StorageOptions): Promise { // Global values are set on each change and the current global settings are passed to any newly authed accounts. // This is to allow setting environement values before an account is active, while still allowing individual accounts to have their own environments. const globals = await this.getGlobals( @@ -2377,7 +2377,12 @@ export class StateService } protected async setAccountEnvironmentUrls(account: TAccount): Promise { - account.settings.environmentUrls = await this.getEnvironmentUrls(); + account.settings.environmentUrls = await this.getGlobalEnvironmentUrls(); return account; } + + protected async getGlobalEnvironmentUrls(options?: StorageOptions): Promise { + options = this.reconcileOptions(options, await this.defaultOnDiskOptions()); + return (await this.getGlobals(options)).environmentUrls ?? new EnvironmentUrls(); + } }