From b9fe78796afc6026e4cbcf71f5fa120c00d66b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bispo?= Date: Fri, 19 May 2023 17:35:42 +0100 Subject: [PATCH] [PM-1019] Environment selection clients (#5480) * [PM-169][PM-142][PM-191] Add Environments to Web and Desktop (#5294) * [PM-1351] Add property to server-config.response. Change config to be able to fetch without being authed. * [PM-1351] fetch every hour. * [PM-1351] fetch on vault sync. * [PM-1351] browser desktop fetch configs on sync complete. * [PM-1351] Add methods to retrieve feature flags * [PM-1351] Add enum to use as key to get values feature flag values * [PM-1351] Remove debug code * [PM-1351] Get flags when unauthed. Add enums as params. Hourly always fetch. * [PM-1351] add check for authed user using auth service * [PM-169] Web: add drop down to select environment * [PM-169] Fix pop up menu margins. Add DisplayEuEnvironmentFlag. * [PM-169] Change menu name. * [PM-169] Add environment selector ts and html. Add declaration and import on login.module * [PM-169] Add environment selector to desktop. * [PM-169] Ignore lint error. * [PM-169] add takeUntil to subscribes * [PM-191] PR Fixes, code format * [PM-168] Add Environments to extension login/registration (#5434) --- apps/browser/src/_locales/en/messages.json | 11 ++ apps/browser/src/_locales/en_GB/messages.json | 3 + .../src/auth/popup/environment.component.ts | 6 +- .../src/auth/popup/home.component.html | 7 +- apps/browser/src/auth/popup/home.component.ts | 27 ++++- apps/browser/src/popup/app.module.ts | 2 + apps/browser/src/popup/images/eu-flag.png | Bin 0 -> 4549 bytes apps/browser/src/popup/images/us-flag.png | Bin 0 -> 4268 bytes apps/browser/src/popup/scss/environment.scss | 64 +++++++++++ apps/browser/src/popup/scss/pages.scss | 2 +- .../desktop/src/auth/environment.component.ts | 6 +- .../src/auth/login/login.component.html | 20 +--- .../desktop/src/auth/login/login.component.ts | 23 +++- apps/desktop/src/auth/login/login.module.ts | 4 +- apps/desktop/src/images/eu-flag.png | Bin 0 -> 4549 bytes apps/desktop/src/images/us-flag.png | Bin 0 -> 4268 bytes apps/desktop/src/locales/en/messages.json | 14 +++ apps/desktop/src/scss/environment.scss | 60 ++++++++++ apps/desktop/src/scss/misc.scss | 4 + .../layouts/frontend-layout.component.html | 29 +++++ .../app/layouts/frontend-layout.component.ts | 15 ++- apps/web/src/images/eu_flag.png | Bin 0 -> 4549 bytes apps/web/src/images/us_flag.png | Bin 0 -> 4268 bytes apps/web/src/locales/en/messages.json | 11 ++ .../environment-selector.component.html | 86 +++++++++++++++ .../environment-selector.component.ts | 103 ++++++++++++++++++ .../src/components/environment.component.ts | 6 +- .../src/services/environment.service.ts | 2 + 28 files changed, 463 insertions(+), 42 deletions(-) create mode 100644 apps/browser/src/popup/images/eu-flag.png create mode 100644 apps/browser/src/popup/images/us-flag.png create mode 100644 apps/desktop/src/images/eu-flag.png create mode 100644 apps/desktop/src/images/us-flag.png create mode 100644 apps/web/src/images/eu_flag.png create mode 100644 apps/web/src/images/us_flag.png create mode 100644 libs/angular/src/auth/components/environment-selector.component.html create mode 100644 libs/angular/src/auth/components/environment-selector.component.ts diff --git a/apps/browser/src/_locales/en/messages.json b/apps/browser/src/_locales/en/messages.json index 0a69b94887..69d26333a8 100644 --- a/apps/browser/src/_locales/en/messages.json +++ b/apps/browser/src/_locales/en/messages.json @@ -2221,7 +2221,18 @@ } } }, + "region": { + "message": "Region" + }, "opensInANewWindow": { "message": "Opens in a new window" + }, + "eu": { + "message": "EU", + "description": "European Union" + }, + "us": { + "message": "US", + "description": "United States" } } diff --git a/apps/browser/src/_locales/en_GB/messages.json b/apps/browser/src/_locales/en_GB/messages.json index c0d018ee1f..3b54fe0efe 100644 --- a/apps/browser/src/_locales/en_GB/messages.json +++ b/apps/browser/src/_locales/en_GB/messages.json @@ -2221,6 +2221,9 @@ } } }, + "region": { + "message": "Region" + }, "opensInANewWindow": { "message": "Opens in a new window" } diff --git a/apps/browser/src/auth/popup/environment.component.ts b/apps/browser/src/auth/popup/environment.component.ts index 3b58ccfa1d..5ad42a600c 100644 --- a/apps/browser/src/auth/popup/environment.component.ts +++ b/apps/browser/src/auth/popup/environment.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from "@angular/core"; import { Router } from "@angular/router"; import { EnvironmentComponent as BaseEnvironmentComponent } from "@bitwarden/angular/components/environment.component"; +import { ModalService } from "@bitwarden/angular/services/modal.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; @@ -18,9 +19,10 @@ export class EnvironmentComponent extends BaseEnvironmentComponent implements On platformUtilsService: PlatformUtilsService, public environmentService: BrowserEnvironmentService, i18nService: I18nService, - private router: Router + private router: Router, + modalService: ModalService ) { - super(platformUtilsService, environmentService, i18nService); + super(platformUtilsService, environmentService, i18nService, modalService); this.showCustom = true; } diff --git a/apps/browser/src/auth/popup/home.component.html b/apps/browser/src/auth/popup/home.component.html index fb51458c13..da208a8d50 100644 --- a/apps/browser/src/auth/popup/home.component.html +++ b/apps/browser/src/auth/popup/home.component.html @@ -9,9 +9,7 @@ - +
- diff --git a/apps/browser/src/auth/popup/home.component.ts b/apps/browser/src/auth/popup/home.component.ts index 9f864fa2ad..361218c6e4 100644 --- a/apps/browser/src/auth/popup/home.component.ts +++ b/apps/browser/src/auth/popup/home.component.ts @@ -1,7 +1,9 @@ -import { Component, OnInit } from "@angular/core"; +import { Component, OnDestroy, OnInit, ViewChild } from "@angular/core"; import { FormBuilder, Validators } from "@angular/forms"; -import { ActivatedRoute, Router } from "@angular/router"; +import { Router } from "@angular/router"; +import { Subject, takeUntil } from "rxjs"; +import { EnvironmentSelectorComponent } from "@bitwarden/angular/auth/components/environment-selector.component"; import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; @@ -12,9 +14,12 @@ import { LoginService } from "@bitwarden/common/auth/abstractions/login.service" selector: "app-home", templateUrl: "home.component.html", }) -export class HomeComponent implements OnInit { - loginInitiated = false; +export class HomeComponent implements OnInit, OnDestroy { + @ViewChild(EnvironmentSelectorComponent, { static: true }) + environmentSelector!: EnvironmentSelectorComponent; + private destroyed$: Subject = new Subject(); + loginInitiated = false; formGroup = this.formBuilder.group({ email: ["", [Validators.required, Validators.email]], rememberEmail: [false], @@ -27,9 +32,9 @@ export class HomeComponent implements OnInit { private router: Router, private i18nService: I18nService, private environmentService: EnvironmentService, - private route: ActivatedRoute, private loginService: LoginService ) {} + async ngOnInit(): Promise { let savedEmail = this.loginService.getEmail(); const rememberEmail = this.loginService.getRememberEmail(); @@ -48,6 +53,18 @@ export class HomeComponent implements OnInit { }); } } + + this.environmentSelector.onOpenSelfHostedSettings + .pipe(takeUntil(this.destroyed$)) + .subscribe(() => { + this.setFormValues(); + this.router.navigate(["environment"]); + }); + } + + ngOnDestroy(): void { + this.destroyed$.next(); + this.destroyed$.complete(); } submit() { diff --git a/apps/browser/src/popup/app.module.ts b/apps/browser/src/popup/app.module.ts index a0cd5e8887..3b8501be44 100644 --- a/apps/browser/src/popup/app.module.ts +++ b/apps/browser/src/popup/app.module.ts @@ -10,6 +10,7 @@ import { FormsModule, ReactiveFormsModule } from "@angular/forms"; import { BrowserModule } from "@angular/platform-browser"; import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; +import { EnvironmentSelectorComponent } from "@bitwarden/angular/auth/components/environment-selector.component"; import { BitwardenToastModule } from "@bitwarden/angular/components/toastr.component"; import { JslibModule } from "@bitwarden/angular/jslib.module"; import { ColorPasswordCountPipe } from "@bitwarden/angular/pipes/color-password-count.pipe"; @@ -153,6 +154,7 @@ import "./locales"; AboutComponent, HelpAndFeedbackComponent, AutofillComponent, + EnvironmentSelectorComponent, ], providers: [CurrencyPipe, DatePipe], bootstrap: [AppComponent], diff --git a/apps/browser/src/popup/images/eu-flag.png b/apps/browser/src/popup/images/eu-flag.png new file mode 100644 index 0000000000000000000000000000000000000000..592bc95e0ce80551d890e7867335df7c8206ccdb GIT binary patch literal 4549 zcmZ`+2Q*w;)E+@}MsLCB-OLz78H4DeMf4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*t})}(4qupwVlu- z6X(ylAQAHeyee~dEIJtPn@$5>J$b%P_X&>M4CH=61Qw^7Acv1KXAKM}2xIh;X8Dj$ zZfpUKaFENJlRQMtWjVDT=b*!%4Bh%B%|Cycu{8Q>39brbF8?PmNPRUMb#(ymCB6Z` z1yTTTE)nqZ0st8RxW6#~fB@e78*2l(|8TAW0O9t4>wh?gm-cF?Ud~JPAA2q9+TRSC zES$eF*%h^)jg9Wo5V)!ucmM!Ilvfi7NX1?{ui@J3=%e-3?@3v?I0;%m zDgX>4bqSr2XbUjL$;*JE12|@*-tZ+gw z7z}f_wvp0SRQ@Bse3D_cL!(`#AP_GvFF`L6K^J#hh>)bDBm^o95f&D>WC(b8JEJWy z0?r<6evUD|dTWw7rWn_$sf3rHdz8hL!cI(BI>)KGF6z|5S4J__M6b1wyVO z5FtS*vQQgd|D}A-5v8&2PF#P>n(c1S3jR6|o z%xYUz%HF z2jzg~#!N$-#VgQJ$InTtNe^CM)IZ|ubcHH|@GNOLw)EqSn!N{3_qOSirG2w%d%F4w zj*akQJB#ejgxY - +
-
+
Bitwarden

{{ "loginOrCreateNewAccount" | i18n }}

@@ -37,9 +25,7 @@ />
- +
+ + +
+ +
+
diff --git a/libs/angular/src/auth/components/environment-selector.component.ts b/libs/angular/src/auth/components/environment-selector.component.ts new file mode 100644 index 0000000000..c708a0af0e --- /dev/null +++ b/libs/angular/src/auth/components/environment-selector.component.ts @@ -0,0 +1,103 @@ +import { animate, state, style, transition, trigger } from "@angular/animations"; +import { ConnectedPosition } from "@angular/cdk/overlay"; +import { Component, EventEmitter, OnDestroy, OnInit, Output } from "@angular/core"; +import { Router } from "@angular/router"; +import { Subject } from "rxjs"; + +import { ConfigServiceAbstraction } from "@bitwarden/common/abstractions/config/config.service.abstraction"; +import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service"; +import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; + +@Component({ + selector: "environment-selector", + templateUrl: "environment-selector.component.html", + animations: [ + trigger("transformPanel", [ + state( + "void", + style({ + opacity: 0, + }) + ), + transition( + "void => open", + animate( + "100ms linear", + style({ + opacity: 1, + }) + ) + ), + transition("* => void", animate("100ms linear", style({ opacity: 0 }))), + ]), + ], +}) +export class EnvironmentSelectorComponent implements OnInit, OnDestroy { + @Output() onOpenSelfHostedSettings = new EventEmitter(); + isOpen = false; + showingModal = false; + selectedEnvironment: ServerEnvironment; + ServerEnvironmentType = ServerEnvironment; + euServerFlagEnabled: boolean; + overlayPostition: ConnectedPosition[] = [ + { + originX: "start", + originY: "bottom", + overlayX: "start", + overlayY: "top", + }, + ]; + protected componentDestroyed$: Subject = new Subject(); + + constructor( + protected environmentService: EnvironmentService, + protected configService: ConfigServiceAbstraction, + protected router: Router + ) {} + + async ngOnInit() { + this.euServerFlagEnabled = await this.configService.getFeatureFlagBool( + FeatureFlag.DisplayEuEnvironmentFlag + ); + this.updateEnvironmentInfo(); + } + + ngOnDestroy(): void { + this.componentDestroyed$.next(); + this.componentDestroyed$.complete(); + } + + async toggle(option: ServerEnvironment) { + this.isOpen = !this.isOpen; + if (option === ServerEnvironment.EU) { + await this.environmentService.setUrls({ base: "https://vault.bitwarden.eu" }); + } else if (option === ServerEnvironment.US) { + await this.environmentService.setUrls({ base: "https://vault.bitwarden.com" }); + } else if (option === ServerEnvironment.SelfHosted) { + this.onOpenSelfHostedSettings.emit(); + } + this.updateEnvironmentInfo(); + } + + updateEnvironmentInfo() { + const webvaultUrl = this.environmentService.getWebVaultUrl(); + if (this.environmentService.isSelfHosted()) { + this.selectedEnvironment = ServerEnvironment.SelfHosted; + } else if (webvaultUrl != null && webvaultUrl.includes("bitwarden.eu")) { + this.selectedEnvironment = ServerEnvironment.EU; + } else { + this.selectedEnvironment = ServerEnvironment.US; + } + } + + close() { + this.isOpen = false; + this.updateEnvironmentInfo(); + } +} + +enum ServerEnvironment { + US = "US", + EU = "EU", + SelfHosted = "Self-hosted", +} diff --git a/libs/angular/src/components/environment.component.ts b/libs/angular/src/components/environment.component.ts index 347b5686e7..f47fcf9124 100644 --- a/libs/angular/src/components/environment.component.ts +++ b/libs/angular/src/components/environment.component.ts @@ -4,6 +4,8 @@ import { EnvironmentService } from "@bitwarden/common/abstractions/environment.s import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; +import { ModalService } from "../services/modal.service"; + @Directive() export class EnvironmentComponent { @Output() onSaved = new EventEmitter(); @@ -19,7 +21,8 @@ export class EnvironmentComponent { constructor( protected platformUtilsService: PlatformUtilsService, protected environmentService: EnvironmentService, - protected i18nService: I18nService + protected i18nService: I18nService, + private modalService: ModalService ) { const urls = this.environmentService.getUrls(); @@ -59,5 +62,6 @@ export class EnvironmentComponent { protected saved() { this.onSaved.emit(); + this.modalService.closeAll(); } } diff --git a/libs/common/src/services/environment.service.ts b/libs/common/src/services/environment.service.ts index e093f0891a..2c6df478eb 100644 --- a/libs/common/src/services/environment.service.ts +++ b/libs/common/src/services/environment.service.ts @@ -218,6 +218,8 @@ export class EnvironmentService implements EnvironmentServiceAbstraction { return ![ "http://vault.bitwarden.com", "https://vault.bitwarden.com", + "http://vault.bitwarden.eu", + "https://vault.bitwarden.eu", "http://vault.qa.bitwarden.pw", "https://vault.qa.bitwarden.pw", ].includes(this.getWebVaultUrl());