Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-3000] Add Environment URLs to Account Switcher #5978

Merged
merged 28 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
44da127
add server url to account switcher tab
rr-bw Aug 7, 2023
5e3ae65
add serverUrl to SwitcherAccount(s)
rr-bw Aug 7, 2023
687d136
refactor serverUrl getter
rr-bw Aug 7, 2023
18c1694
Merge branch 'master' into auth/pm-3000/desktop-account-switcher-urls
rr-bw Aug 7, 2023
d7b28bd
cleanup urls
rr-bw Aug 7, 2023
cbca02b
Merge branch 'auth/pm-3000/desktop-account-switcher-urls' of https://…
rr-bw Aug 7, 2023
b03c4a8
adjust styling
rr-bw Aug 7, 2023
75a508e
Merge branch 'master' into auth/pm-3000/desktop-account-switcher-urls
rr-bw Sep 25, 2023
2e16845
remove SwitcherAccount class
rr-bw Oct 10, 2023
66ed3ef
Merge branch 'master' into auth/pm-3000/desktop-account-switcher-urls
rr-bw Oct 10, 2023
972e923
remove authenticationStatus from AccountProfile
rr-bw Oct 10, 2023
80a1424
rename to inactiveAccounts for clarity
rr-bw Oct 10, 2023
10aa289
move business logic to environmentService
rr-bw Oct 10, 2023
d923db5
use tokenService instead of stateService
rr-bw Oct 10, 2023
f7d204a
cleanup type and comments
rr-bw Oct 10, 2023
43d7ed7
remove unused property
rr-bw Oct 10, 2023
b18257f
replace magic strings
rr-bw Oct 10, 2023
772a888
remove unused function
rr-bw Oct 10, 2023
262a54b
minor refactoring
rr-bw Oct 10, 2023
755419f
refactor to use environmentService insead of getServerConfig
rr-bw Oct 12, 2023
9e93c97
use Utils.getHost() instead of Utils.getDomain()
rr-bw Oct 12, 2023
96436e4
create getHost() method
rr-bw Oct 12, 2023
8514d96
remove comment
rr-bw Oct 12, 2023
8d6eee5
get base url as fallback
rr-bw Oct 16, 2023
4d32a4a
resolve eslint error
rr-bw Oct 26, 2023
81e9ae8
Merge branch 'master' into auth/pm-3000/desktop-account-switcher-urls
rr-bw Oct 26, 2023
395b7d6
resolve merge conflicts for a11y changes
rr-bw Oct 31, 2023
1755488
Update apps/desktop/src/app/layout/account-switcher.component.html
rr-bw Nov 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions apps/desktop/src/app/layout/account-switcher.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
*ngIf="activeAccount.email != null"
aria-hidden="true"
></app-avatar>
<span>{{ activeAccount.email }}</span>
<div class="active-account">
<div>{{ activeAccount.email }}</div>
<span>{{ activeAccount.serverUrl }}</span>
</div>
</ng-container>
<ng-template #noActiveAccount>
<span>{{ "switchAccount" | i18n }}</span>
Expand Down Expand Up @@ -74,9 +77,7 @@
></app-avatar>
<div class="accountInfo">
<span class="email" aria-hidden="true">{{ a.value.profile.email }}</span>
<span class="server" aria-hidden="true" *ngIf="a.value.serverUrl != 'bitwarden.com'">{{
a.value.serverUrl
}}</span>
<span class="server" aria-hidden="true">{{ a.value.serverUrl }}</span>
<span class="status" aria-hidden="true">{{
(a.value.profile.authenticationStatus === authStatus.Unlocked ? "unlocked" : "locked")
| i18n
Expand Down
21 changes: 19 additions & 2 deletions apps/desktop/src/app/layout/account-switcher.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { concatMap, Subject, takeUntil } from "rxjs";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
Expand All @@ -17,14 +18,15 @@ type ActiveAccount = {
name: string;
email: string;
avatarColor: string;
serverUrl: string;
};

export class SwitcherAccount extends Account {
get serverUrl() {
return this.removeWebProtocolFromString(
this.settings?.environmentUrls?.base ??
this.settings?.environmentUrls.api ??
"https://bitwarden.com"
this.settings.region
);
}

Expand Down Expand Up @@ -96,7 +98,8 @@ export class AccountSwitcherComponent implements OnInit, OnDestroy {
private authService: AuthService,
private messagingService: MessagingService,
private router: Router,
private tokenService: TokenService
private tokenService: TokenService,
private environmentService: EnvironmentService
) {}

async ngOnInit(): Promise<void> {
Expand All @@ -110,12 +113,16 @@ export class AccountSwitcherComponent implements OnInit, OnDestroy {
}

this.accounts = await this.createSwitcherAccounts(accounts);

try {
this.activeAccount = {
id: await this.tokenService.getUserId(),
name: (await this.tokenService.getName()) ?? (await this.tokenService.getEmail()),
email: await this.tokenService.getEmail(),
avatarColor: await this.stateService.getAvatarColor(),
serverUrl: Utils.removeVaultfromHostname(
Utils.getHostname(this.environmentService.getWebVaultUrl())
),
};
} catch {
this.activeAccount = undefined;
Expand Down Expand Up @@ -156,6 +163,7 @@ export class AccountSwitcherComponent implements OnInit, OnDestroy {
[userId: string]: Account;
}): Promise<{ [userId: string]: SwitcherAccount }> {
const switcherAccounts: { [userId: string]: SwitcherAccount } = {};

for (const userId in baseAccounts) {
if (userId == null || userId === (await this.stateService.getUserId())) {
continue;
Expand All @@ -165,11 +173,20 @@ export class AccountSwitcherComponent implements OnInit, OnDestroy {
baseAccounts[userId].settings.environmentUrls = await this.stateService.getEnvironmentUrls({
userId: userId,
});

const serverConfig = await this.stateService.getServerConfig({
userId: userId,
});
Hinton marked this conversation as resolved.
Show resolved Hide resolved

baseAccounts[userId].settings.region = Utils.removeVaultfromHostname(
Utils.getHostname(serverConfig.environment.vault)
);
Hinton marked this conversation as resolved.
Show resolved Hide resolved
switcherAccounts[userId] = new SwitcherAccount(baseAccounts[userId]);
switcherAccounts[userId].avatarColor = await this.stateService.getAvatarColor({
userId: userId,
});
}

return switcherAccounts;
}
}
19 changes: 15 additions & 4 deletions apps/desktop/src/scss/header.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.header {
-webkit-app-region: drag;
min-height: 44px;
max-height: 44px;
min-height: 54px;
max-height: 54px;
border-bottom: 1px solid #000000;
display: grid;
grid-template-columns: 25% 1fr 25%;
Expand Down Expand Up @@ -102,7 +102,7 @@
.account-switcher {
display: grid;
grid-template-columns: auto 1fr auto;
grid-column-gap: 5px;
grid-column-gap: 10px;
align-items: center;
justify-items: center;
padding: 0 10px;
Expand All @@ -121,11 +121,22 @@
display: block;
}

span {
.active-account {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-align: left;

div {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

span {
font-size: $font-size-small;
}
}

&:hover {
Expand Down
12 changes: 9 additions & 3 deletions libs/angular/src/auth/components/lock.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,15 @@ export class LockComponent implements OnInit, OnDestroy {
this.email = await this.stateService.getEmail();

const webVaultUrl = this.environmentService.getWebVaultUrl();
const vaultUrl =
webVaultUrl === "https://vault.bitwarden.com" ? "https://bitwarden.com" : webVaultUrl;
this.webVaultHostname = Utils.getHostname(vaultUrl);

switch (webVaultUrl) {
case "https://vault.bitwarden.com":
case "https://vault.bitwarden.eu":
this.webVaultHostname = Utils.removeVaultfromHostname(Utils.getHostname(webVaultUrl));
break;
default:
this.webVaultHostname = Utils.getHostname(webVaultUrl);
}
Hinton marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
4 changes: 4 additions & 0 deletions libs/common/src/platform/misc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ export class Utils {
return null;
}

static removeVaultfromHostname(uriString: string): string {
rr-bw marked this conversation as resolved.
Show resolved Hide resolved
Hinton marked this conversation as resolved.
Show resolved Hide resolved
return uriString.replace(/vault./g, "");
}

static getHost(uriString: string): string {
const url = Utils.getUrl(uriString);
try {
Expand Down