From c8e404cb9b6a234544057a87f20ad2c9ff5be628 Mon Sep 17 00:00:00 2001 From: Alec Rippberger Date: Wed, 16 Oct 2024 16:07:39 -0500 Subject: [PATCH] Reimplement RegistrationSelfHostedEnvConfigDialogComponent --- apps/browser/src/auth/popup/home.component.ts | 16 +++++++-- .../desktop/src/auth/login/login.component.ts | 35 ++++++++++++++++++- .../environment-selector.component.html | 2 +- .../registration-env-selector.component.ts | 2 +- ...lf-hosted-env-config-dialog.component.html | 1 + ...self-hosted-env-config-dialog.component.ts | 0 6 files changed, 51 insertions(+), 5 deletions(-) rename libs/auth/src/angular/registration/{registration-env-selector => registration-self-hosted-env-config-dialog}/registration-self-hosted-env-config-dialog.component.html (98%) rename libs/auth/src/angular/registration/{registration-env-selector => registration-self-hosted-env-config-dialog}/registration-self-hosted-env-config-dialog.component.ts (100%) diff --git a/apps/browser/src/auth/popup/home.component.ts b/apps/browser/src/auth/popup/home.component.ts index cd9dfc3702..ef9f3a328c 100644 --- a/apps/browser/src/auth/popup/home.component.ts +++ b/apps/browser/src/auth/popup/home.component.ts @@ -5,9 +5,13 @@ import { Subject, firstValueFrom, switchMap, takeUntil } from "rxjs"; import { EnvironmentSelectorComponent } from "@bitwarden/angular/auth/components/environment-selector.component"; import { LoginEmailServiceAbstraction, RegisterRouteService } from "@bitwarden/auth/common"; +import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; +import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { ToastService } from "@bitwarden/components"; +import { ToastService, DialogService } from "@bitwarden/components"; + +import { RegistrationSelfHostedEnvConfigDialogComponent } from "../../../../../libs/auth/src/angular/registration/registration-self-hosted-env-config-dialog/registration-self-hosted-env-config-dialog.component"; import { AccountSwitcherService } from "./account-switching/services/account-switcher.service"; @@ -38,6 +42,8 @@ export class HomeComponent implements OnInit, OnDestroy { private accountSwitcherService: AccountSwitcherService, private registerRouteService: RegisterRouteService, private toastService: ToastService, + private configService: ConfigService, + private dialogService: DialogService, ) {} async ngOnInit(): Promise { @@ -58,7 +64,13 @@ export class HomeComponent implements OnInit, OnDestroy { .pipe( switchMap(async () => { await this.setLoginEmailValues(); - await this.router.navigate(["environment"]); + if ( + await this.configService.getFeatureFlag(FeatureFlag.UnauthenticatedExtensionUIRefresh) + ) { + await RegistrationSelfHostedEnvConfigDialogComponent.open(this.dialogService); + } else { + await this.router.navigate(["environment"]); + } }), takeUntil(this.destroyed$), ) diff --git a/apps/desktop/src/auth/login/login.component.ts b/apps/desktop/src/auth/login/login.component.ts index 6ba143421c..650acd8110 100644 --- a/apps/desktop/src/auth/login/login.component.ts +++ b/apps/desktop/src/auth/login/login.component.ts @@ -14,8 +14,10 @@ import { import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction"; import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction"; import { WebAuthnLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/webauthn/webauthn-login.service.abstraction"; +import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service"; import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service"; +import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service"; import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; @@ -25,9 +27,10 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; -import { ToastService } from "@bitwarden/components"; +import { DialogService, ToastService } from "@bitwarden/components"; import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy"; +import { RegistrationSelfHostedEnvConfigDialogComponent } from "../../../../../libs/auth/src/angular/registration/registration-self-hosted-env-config-dialog/registration-self-hosted-env-config-dialog.component"; import { EnvironmentComponent } from "../environment.component"; const BroadcasterSubscriptionId = "LoginComponent"; @@ -76,6 +79,8 @@ export class LoginComponent extends BaseLoginComponent implements OnInit, OnDest webAuthnLoginService: WebAuthnLoginServiceAbstraction, registerRouteService: RegisterRouteService, toastService: ToastService, + private configService: ConfigService, + private dialogService: DialogService, ) { super( devicesApiService, @@ -137,7 +142,35 @@ export class LoginComponent extends BaseLoginComponent implements OnInit, OnDest this.componentDestroyed$.complete(); } + /** + * Opens the environment configuration dialog. + * If the feature flag is enabled, it will open the refreshed environment configuration dialog. + * Otherwise, it will open the environment configuration dialog. + */ async settings() { + if (await this.configService.getFeatureFlag(FeatureFlag.UnauthenticatedExtensionUIRefresh)) { + await this.showRefreshedEnvConfigDialog(); + } else { + await this.showEnvConfigDialog(); + } + } + + /** + * Show the refreshed environment configuration dialog (when the UnauthenticatedExtensionUIRefresh flag is true). + */ + async showRefreshedEnvConfigDialog() { + this.showingModal = true; + const wasSaved = await RegistrationSelfHostedEnvConfigDialogComponent.open(this.dialogService); + this.showingModal = false; + if (wasSaved) { + await this.getLoginWithDevice(this.loggedEmail); + } + } + + /** + * Show the environment configuration dialog. + */ + async showEnvConfigDialog() { const [modal, childComponent] = await this.modalService.openViewRef( EnvironmentComponent, this.environmentModal, diff --git a/libs/angular/src/auth/components/environment-selector.component.html b/libs/angular/src/auth/components/environment-selector.component.html index 673f647984..bc3106f046 100644 --- a/libs/angular/src/auth/components/environment-selector.component.html +++ b/libs/angular/src/auth/components/environment-selector.component.html @@ -4,7 +4,7 @@ } as data" >
- {{ "loggingInOn" | i18n }}: + {{ accessingString }}: