From 59a530045860f89bde2cd37e93f4e09d76e307b3 Mon Sep 17 00:00:00 2001 From: Jake Fink Date: Fri, 17 Dec 2021 11:24:38 -0500 Subject: [PATCH] move sso properties to globalstate (#583) * move sso properties to globalstate * whitespace * npm prettier changes --- common/src/models/domain/account.ts | 3 -- common/src/models/domain/globalState.ts | 3 ++ common/src/services/state.service.ts | 44 +++++++++++-------- common/src/services/stateMigration.service.ts | 18 ++++---- 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/common/src/models/domain/account.ts b/common/src/models/domain/account.ts index 22ab5ddf93..98ea62df43 100644 --- a/common/src/models/domain/account.ts +++ b/common/src/models/domain/account.ts @@ -95,9 +95,6 @@ export class AccountProfile { hasPremiumPersonally?: boolean; lastActive?: number; lastSync?: string; - ssoCodeVerifier?: string; - ssoOrganizationIdentifier?: string; - ssoState?: string; userId?: string; usesKeyConnector?: boolean; keyHash?: string; diff --git a/common/src/models/domain/globalState.ts b/common/src/models/domain/globalState.ts index ad270bcee9..66ad5130d4 100644 --- a/common/src/models/domain/globalState.ts +++ b/common/src/models/domain/globalState.ts @@ -5,6 +5,9 @@ export class GlobalState { locale?: string; openAtLogin?: boolean; organizationInvitation?: any; + ssoCodeVerifier?: string; + ssoOrganizationIdentifier?: string; + ssoState?: string; rememberedEmail?: string; theme?: string; window?: Map = new Map(); diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index 8fc30f8ba8..59c5a73a94 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -1874,46 +1874,54 @@ export class StateService implements StateServiceAbstraction { } async getSsoCodeVerifier(options?: StorageOptions): Promise { - return (await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions))) - ?.profile?.ssoCodeVerifier; + return ( + await this.getGlobals(this.reconcileOptions(options, await this.defaultOnDiskOptions())) + )?.ssoCodeVerifier; } async setSsoCodeVerifier(value: string, options?: StorageOptions): Promise { - const account = await this.getAccount( - this.reconcileOptions(options, this.defaultInMemoryOptions) + const globals = await this.getGlobals( + this.reconcileOptions(options, await this.defaultOnDiskOptions()) + ); + globals.ssoCodeVerifier = value; + await this.saveGlobals( + globals, + this.reconcileOptions(options, await this.defaultOnDiskOptions()) ); - account.profile.ssoCodeVerifier = value; - await this.saveAccount(account, this.reconcileOptions(options, this.defaultInMemoryOptions)); } async getSsoOrgIdentifier(options?: StorageOptions): Promise { return ( - await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskLocalOptions())) - )?.profile?.ssoOrganizationIdentifier; + await this.getGlobals(this.reconcileOptions(options, await this.defaultOnDiskLocalOptions())) + )?.ssoOrganizationIdentifier; } async setSsoOrganizationIdentifier(value: string, options?: StorageOptions): Promise { - const account = await this.getAccount( + const globals = await this.getGlobals( this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()) ); - account.profile.ssoOrganizationIdentifier = value; - await this.saveAccount( - account, + globals.ssoOrganizationIdentifier = value; + await this.saveGlobals( + globals, this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()) ); } async getSsoState(options?: StorageOptions): Promise { - return (await this.getAccount(this.reconcileOptions(options, this.defaultInMemoryOptions))) - ?.profile?.ssoState; + return ( + await this.getGlobals(this.reconcileOptions(options, await this.defaultOnDiskOptions())) + )?.ssoState; } async setSsoState(value: string, options?: StorageOptions): Promise { - const account = await this.getAccount( - this.reconcileOptions(options, this.defaultInMemoryOptions) + const globals = await this.getGlobals( + this.reconcileOptions(options, await this.defaultOnDiskOptions()) + ); + globals.ssoState = value; + await this.saveGlobals( + globals, + this.reconcileOptions(options, await this.defaultOnDiskOptions()) ); - account.profile.ssoState = value; - await this.saveAccount(account, this.reconcileOptions(options, this.defaultInMemoryOptions)); } async getTheme(options?: StorageOptions): Promise { diff --git a/common/src/services/stateMigration.service.ts b/common/src/services/stateMigration.service.ts index bab3667fad..903cc093ff 100644 --- a/common/src/services/stateMigration.service.ts +++ b/common/src/services/stateMigration.service.ts @@ -192,6 +192,15 @@ export class StateMigrationService { ), openAtLogin: await this.storageService.get(v1Keys.openAtLogin, options), organizationInvitation: await this.storageService.get("", options), + ssoCodeVerifier: await this.storageService.get( + v1Keys.ssoCodeVerifier, + options + ), + ssoOrganizationIdentifier: await this.storageService.get( + v1Keys.ssoIdentifier, + options + ), + ssoState: null, rememberedEmail: await this.storageService.get( v1Keys.rememberedEmail, options @@ -327,15 +336,6 @@ export class StateMigrationService { keyHash: await this.storageService.get(v1Keys.keyHash, options), lastActive: await this.storageService.get(v1Keys.lastActive, options), lastSync: null, - ssoCodeVerifier: await this.storageService.get( - v1Keys.ssoCodeVerifier, - options - ), - ssoOrganizationIdentifier: await this.storageService.get( - v1Keys.ssoIdentifier, - options - ), - ssoState: null, userId: userId, usesKeyConnector: null, },