From 2b5f61cadd66bfe6532b0a4f5669568851423c46 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Fri, 23 Jul 2021 20:47:43 +0200 Subject: [PATCH] Use the helper methods in EnvironmentService (#1092) --- jslib | 2 +- src/app/accounts/register.component.ts | 6 +++-- src/app/accounts/sso.component.ts | 5 ++-- .../layouts/organization-layout.component.ts | 7 +----- .../manage/policies.component.ts | 7 +----- src/app/services/services.module.ts | 25 ++++++++----------- src/app/settings/link-sso.component.ts | 5 ++-- 7 files changed, 24 insertions(+), 33 deletions(-) diff --git a/jslib b/jslib index 8bf0f75d9e..e1ce721364 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 8bf0f75d9e9869bbb8df397fb0c3bae4359eacf0 +Subproject commit e1ce72136490b9055d8d6a03988e9d39ac560a89 diff --git a/src/app/accounts/register.component.ts b/src/app/accounts/register.component.ts index 499572fa84..fb8e085121 100644 --- a/src/app/accounts/register.component.ts +++ b/src/app/accounts/register.component.ts @@ -7,6 +7,7 @@ import { import { ApiService } from 'jslib-common/abstractions/api.service'; import { AuthService } from 'jslib-common/abstractions/auth.service'; import { CryptoService } from 'jslib-common/abstractions/crypto.service'; +import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; @@ -36,9 +37,10 @@ export class RegisterComponent extends BaseRegisterComponent { i18nService: I18nService, cryptoService: CryptoService, apiService: ApiService, private route: ActivatedRoute, stateService: StateService, platformUtilsService: PlatformUtilsService, - passwordGenerationService: PasswordGenerationService, private policyService: PolicyService) { + passwordGenerationService: PasswordGenerationService, private policyService: PolicyService, + environmentService: EnvironmentService) { super(authService, router, i18nService, cryptoService, apiService, stateService, platformUtilsService, - passwordGenerationService); + passwordGenerationService, environmentService); } getPasswordScoreAlertDisplay() { diff --git a/src/app/accounts/sso.component.ts b/src/app/accounts/sso.component.ts index 0e5df65be0..fbdaa90b13 100644 --- a/src/app/accounts/sso.component.ts +++ b/src/app/accounts/sso.component.ts @@ -7,6 +7,7 @@ import { import { ApiService } from 'jslib-common/abstractions/api.service'; import { AuthService } from 'jslib-common/abstractions/auth.service'; import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service'; +import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; @@ -26,10 +27,10 @@ export class SsoComponent extends BaseSsoComponent { i18nService: I18nService, route: ActivatedRoute, storageService: StorageService, stateService: StateService, platformUtilsService: PlatformUtilsService, apiService: ApiService, - cryptoFunctionService: CryptoFunctionService, + cryptoFunctionService: CryptoFunctionService, environmentService: EnvironmentService, passwordGenerationService: PasswordGenerationService) { super(authService, router, i18nService, route, storageService, stateService, platformUtilsService, - apiService, cryptoFunctionService, passwordGenerationService); + apiService, cryptoFunctionService, environmentService, passwordGenerationService); this.redirectUri = window.location.origin + '/sso-connector.html'; this.clientId = 'web'; } diff --git a/src/app/layouts/organization-layout.component.ts b/src/app/layouts/organization-layout.component.ts index 0a1f688f53..73cc5e8f0b 100644 --- a/src/app/layouts/organization-layout.component.ts +++ b/src/app/layouts/organization-layout.component.ts @@ -34,12 +34,7 @@ export class OrganizationLayoutComponent implements OnInit, OnDestroy { private environmentService: EnvironmentService) { } ngOnInit() { - this.businessUrl = 'https://portal.bitwarden.com'; - if (this.environmentService.enterpriseUrl != null) { - this.businessUrl = this.environmentService.enterpriseUrl; - } else if (this.environmentService.baseUrl != null) { - this.businessUrl = this.environmentService.baseUrl + '/portal'; - } + this.businessUrl = this.environmentService.getEnterpriseUrl(); document.body.classList.remove('layout_frontend'); this.route.params.subscribe(async params => { diff --git a/src/app/organizations/manage/policies.component.ts b/src/app/organizations/manage/policies.component.ts index 0b31a01aa9..e27ea2923f 100644 --- a/src/app/organizations/manage/policies.component.ts +++ b/src/app/organizations/manage/policies.component.ts @@ -149,12 +149,7 @@ export class PoliciesComponent implements OnInit { }); // Remove when removing deprecation warning - this.enterpriseUrl = 'https://portal.bitwarden.com'; - if (this.environmentService.enterpriseUrl != null) { - this.enterpriseUrl = this.environmentService.enterpriseUrl; - } else if (this.environmentService.baseUrl != null) { - this.enterpriseUrl = this.environmentService.baseUrl + '/portal'; - } + this.enterpriseUrl = this.environmentService.getEnterpriseUrl(); } async load() { diff --git a/src/app/services/services.module.ts b/src/app/services/services.module.ts index 3b6231a2d6..3d93ab9f6b 100644 --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts @@ -103,7 +103,8 @@ const cryptoService = new CryptoService(storageService, consoleLogService); const tokenService = new TokenService(storageService); const appIdService = new AppIdService(storageService); -const apiService = new ApiService(tokenService, platformUtilsService, +const environmentService = new EnvironmentService(storageService); +const apiService = new ApiService(tokenService, platformUtilsService, environmentService, async (expired: boolean) => messagingService.send('logout', { expired: expired })); const userService = new UserService(tokenService, storageService); const settingsService = new SettingsService(userService, storageService); @@ -133,9 +134,8 @@ const authService = new AuthService(cryptoService, apiService, const exportService = new ExportService(folderService, cipherService, apiService, cryptoService); const importService = new ImportService(cipherService, folderService, apiService, i18nService, collectionService, platformUtilsService, cryptoService); -const notificationsService = new NotificationsService(userService, syncService, appIdService, - apiService, vaultTimeoutService, async () => messagingService.send('logout', { expired: true }), consoleLogService); -const environmentService = new EnvironmentService(apiService, storageService, notificationsService); +const notificationsService = new NotificationsService(userService, syncService, appIdService, apiService, vaultTimeoutService, + environmentService, async () => messagingService.send('logout', { expired: true }), consoleLogService); const auditService = new AuditService(cryptoFunctionService, apiService); const eventLoggingService = new EventLoggingService(storageService, apiService, userService, cipherService); const passwordRepromptService = new PasswordRepromptService(i18nService, cryptoService, platformUtilsService); @@ -147,19 +147,16 @@ export function initFactory(): Function { await (storageService as HtmlStorageService).init(); if (process.env.ENV !== 'production' || platformUtilsService.isSelfHost()) { - environmentService.baseUrl = window.location.origin; + environmentService.setUrls({ base: window.location.origin }, false); } else { - environmentService.notificationsUrl = 'https://notifications.bitwarden.com'; - environmentService.enterpriseUrl = 'https://portal.bitwarden.com'; + environmentService.setUrls({ + base: window.location.origin, + notifications: 'https://notifications.bitwarden.com', + enterprise: 'https://portal.bitwarden.com', + }, false); } - apiService.setUrls({ - base: window.location.origin, - api: null, - identity: null, - events: null, - }); - setTimeout(() => notificationsService.init(environmentService), 3000); + setTimeout(() => notificationsService.init(), 3000); vaultTimeoutService.init(true); const locale = await storageService.get(ConstantsService.localeKey); diff --git a/src/app/settings/link-sso.component.ts b/src/app/settings/link-sso.component.ts index 4367b67fe8..a8ef0594c7 100644 --- a/src/app/settings/link-sso.component.ts +++ b/src/app/settings/link-sso.component.ts @@ -8,6 +8,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { ApiService } from 'jslib-common/abstractions/api.service'; import { AuthService } from 'jslib-common/abstractions/auth.service'; import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service'; +import { EnvironmentService } from 'jslib-common/abstractions/environment.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { PasswordGenerationService } from 'jslib-common/abstractions/passwordGeneration.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; @@ -30,12 +31,12 @@ export class LinkSsoComponent extends SsoComponent implements AfterContentInit { apiService: ApiService, authService: AuthService, router: Router, route: ActivatedRoute, cryptoFunctionService: CryptoFunctionService, passwordGenerationService: PasswordGenerationService, - storageService: StorageService, stateService: StateService) { + storageService: StorageService, stateService: StateService, environmentService: EnvironmentService) { super(authService, router, i18nService, route, storageService, stateService, platformUtilsService, apiService, - cryptoFunctionService, passwordGenerationService); + cryptoFunctionService, environmentService, passwordGenerationService); this.returnUri = '/settings/organizations'; this.redirectUri = window.location.origin + '/sso-connector.html';