Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bitwarden/clients
Browse files Browse the repository at this point in the history
# Conflicts:
#	apps/desktop/src/main.ts
  • Loading branch information
Hinton committed Mar 18, 2024
2 parents c097a93 + bdbae39 commit 7ea56a2
Show file tree
Hide file tree
Showing 257 changed files with 6,992 additions and 1,550 deletions.
28 changes: 14 additions & 14 deletions apps/browser/src/_locales/be/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"message": "Дадаць лагін"
},
"addCardMenu": {
"message": "Add card"
"message": "Дадаць картку"
},
"addIdentityMenu": {
"message": "Add identity"
Expand Down Expand Up @@ -269,7 +269,7 @@
"message": "Даўжыня"
},
"passwordMinLength": {
"message": "Minimum password length"
"message": "Мінімальная даўжыня пароля"
},
"uppercase": {
"message": "Вялікія літары (A-Z)"
Expand Down Expand Up @@ -369,7 +369,7 @@
"message": "Iншае"
},
"unlockMethodNeededToChangeTimeoutActionDesc": {
"message": "Set up an unlock method to change your vault timeout action."
"message": "Наладзіць метад разблакіроўкі для змянення дзеяння часу чакання вашага сховішча."
},
"unlockMethodNeeded": {
"message": "Set up an unlock method in Settings"
Expand Down Expand Up @@ -415,7 +415,7 @@
"message": "Заблакіраваць зараз"
},
"lockAll": {
"message": "Lock all"
"message": "Заблакаваць усе"
},
"immediately": {
"message": "Адразу"
Expand Down Expand Up @@ -494,7 +494,7 @@
"message": "Ваш уліковы запіс створаны! Цяпер вы можаце ўвайсці ў яго."
},
"youSuccessfullyLoggedIn": {
"message": "You successfully logged in"
"message": "Вы паспяхова аўтарызаваны"
},
"youMayCloseThisWindow": {
"message": "You may close this window"
Expand Down Expand Up @@ -2005,7 +2005,7 @@
"message": "Выбраць папку..."
},
"noFoldersFound": {
"message": "No folders found",
"message": "Папкі не знойдзены",
"description": "Used as a message within the notification bar when no folders are found"
},
"orgPermissionsUpdatedMustSetPassword": {
Expand Down Expand Up @@ -2215,7 +2215,7 @@
"message": "Версія сервера"
},
"selfHostedServer": {
"message": "self-hosted"
"message": "уласнае размяшчэнне"
},
"thirdParty": {
"message": "Іншы пастаўшчык"
Expand Down Expand Up @@ -2356,25 +2356,25 @@
}
},
"loggingInOn": {
"message": "Logging in on"
"message": "Увайсці на"
},
"opensInANewWindow": {
"message": "Адкрываць у новым акне"
},
"deviceApprovalRequired": {
"message": "Device approval required. Select an approval option below:"
"message": "Патрабуецца ўхваленне прылады. Выберыце параметры ўхвалення ніжэй:"
},
"rememberThisDevice": {
"message": "Remember this device"
"message": "Запомніць гэту прыладу"
},
"uncheckIfPublicDevice": {
"message": "Uncheck if using a public device"
"message": "Здыміце пазнаку, калі выкарыстоўваеце агульнадаступную прыладу"
},
"approveFromYourOtherDevice": {
"message": "Approve from your other device"
"message": "Ухваліць з іншай вашай прылады"
},
"requestAdminApproval": {
"message": "Request admin approval"
"message": "Запытаць ухваленне адміністратара"
},
"approveWithMasterPassword": {
"message": "Approve with master password"
Expand Down Expand Up @@ -2402,7 +2402,7 @@
"message": "Адлюстраванне"
},
"accountSuccessfullyCreated": {
"message": "Account successfully created!"
"message": "Уліковы запіс паспяхова створаны!"
},
"adminApprovalRequested": {
"message": "Admin approval requested"
Expand Down
2 changes: 1 addition & 1 deletion apps/browser/src/_locales/hu/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@
"message": "A bejelentkezési jelszó frissítésének kérése, ha változást lett érzékelve egy webhelyen. Minden bejelentkezett fiókra vonatkozik."
},
"enableUsePasskeys": {
"message": "Kérés a jhozzáférési kulcs mentésére és használatára"
"message": "Kérés a hozzáférési kulcs mentésére és használatára"
},
"usePasskeysDesc": {
"message": "Kérés az új hozzáféréi kulcsok mentésére vagy bejelentkezés a széfben tárolt hozzáférési kulcsokkal. Minden bejelentkezett fiókra vonatkozik."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { AvatarService as AvatarServiceAbstraction } from "@bitwarden/common/auth/abstractions/avatar.service";
import { AvatarService } from "@bitwarden/common/auth/services/avatar.service";

import {
ApiServiceInitOptions,
apiServiceFactory,
} from "../../../platform/background/service-factories/api-service.factory";
import {
CachedServices,
factory,
FactoryOptions,
} from "../../../platform/background/service-factories/factory-options";
import {
stateProviderFactory,
StateProviderInitOptions,
} from "../../../platform/background/service-factories/state-provider.factory";

type AvatarServiceFactoryOptions = FactoryOptions;

export type AvatarServiceInitOptions = AvatarServiceFactoryOptions &
ApiServiceInitOptions &
StateProviderInitOptions;

export function avatarServiceFactory(
cache: { avatarService?: AvatarServiceAbstraction } & CachedServices,
opts: AvatarServiceInitOptions,
): Promise<AvatarServiceAbstraction> {
return factory(
cache,
"avatarService",
opts,
async () =>
new AvatarService(
await apiServiceFactory(cache, opts),
await stateProviderFactory(cache, opts),
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ApiServiceInitOptions,
} from "../../../platform/background/service-factories/api-service.factory";
import { appIdServiceFactory } from "../../../platform/background/service-factories/app-id-service.factory";
import { billingAccountProfileStateServiceFactory } from "../../../platform/background/service-factories/billing-account-profile-state-service.factory";
import {
CryptoServiceInitOptions,
cryptoServiceFactory,
Expand Down Expand Up @@ -119,6 +120,7 @@ export function loginStrategyServiceFactory(
await deviceTrustCryptoServiceFactory(cache, opts),
await authRequestServiceFactory(cache, opts),
await globalStateProviderFactory(cache, opts),
await billingAccountProfileStateServiceFactory(cache, opts),
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@ import {
factory,
} from "../../../platform/background/service-factories/factory-options";
import {
stateServiceFactory,
StateServiceInitOptions,
} from "../../../platform/background/service-factories/state-service.factory";
GlobalStateProviderInitOptions,
globalStateProviderFactory,
} from "../../../platform/background/service-factories/global-state-provider.factory";
import {
PlatformUtilsServiceInitOptions,
platformUtilsServiceFactory,
} from "../../../platform/background/service-factories/platform-utils-service.factory";
import {
SingleUserStateProviderInitOptions,
singleUserStateProviderFactory,
} from "../../../platform/background/service-factories/single-user-state-provider.factory";
import {
SecureStorageServiceInitOptions,
secureStorageServiceFactory,
} from "../../../platform/background/service-factories/storage-service.factory";

type TokenServiceFactoryOptions = FactoryOptions;

export type TokenServiceInitOptions = TokenServiceFactoryOptions & StateServiceInitOptions;
export type TokenServiceInitOptions = TokenServiceFactoryOptions &
SingleUserStateProviderInitOptions &
GlobalStateProviderInitOptions &
PlatformUtilsServiceInitOptions &
SecureStorageServiceInitOptions;

export function tokenServiceFactory(
cache: { tokenService?: AbstractTokenService } & CachedServices,
Expand All @@ -23,6 +39,12 @@ export function tokenServiceFactory(
cache,
"tokenService",
opts,
async () => new TokenService(await stateServiceFactory(cache, opts)),
async () =>
new TokenService(
await singleUserStateProviderFactory(cache, opts),
await globalStateProviderFactory(cache, opts),
(await platformUtilsServiceFactory(cache, opts)).supportsSecureStorage(),
await secureStorageServiceFactory(cache, opts),
),
);
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,61 @@
import { Location } from "@angular/common";
import { Component } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { Observable, combineLatest, switchMap } from "rxjs";

import { CurrentAccountService } from "./services/current-account.service";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AvatarService } from "@bitwarden/common/auth/abstractions/avatar.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { UserId } from "@bitwarden/common/types/guid";

export type CurrentAccount = {
id: UserId;
name: string | undefined;
email: string;
status: AuthenticationStatus;
avatarColor: string;
};

@Component({
selector: "app-current-account",
templateUrl: "current-account.component.html",
})
export class CurrentAccountComponent {
currentAccount$: Observable<CurrentAccount>;

constructor(
private currentAccountService: CurrentAccountService,
private accountService: AccountService,
private avatarService: AvatarService,
private router: Router,
private location: Location,
private route: ActivatedRoute,
) {}
) {
this.currentAccount$ = combineLatest([
this.accountService.activeAccount$,
this.avatarService.avatarColor$,
]).pipe(
switchMap(async ([account, avatarColor]) => {
if (account == null) {
return null;
}
const currentAccount: CurrentAccount = {
id: account.id,
name: account.name || account.email,
email: account.email,
status: account.status,
avatarColor,
};

get currentAccount$() {
return this.currentAccountService.currentAccount$;
return currentAccount;
}),
);
}

async currentAccountClicked() {
if (this.route.snapshot.data.state.includes("account-switcher")) {
this.location.back();
} else {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.router.navigate(["/account-switcher"]);
await this.router.navigate(["/account-switcher"]);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { matches, mock } from "jest-mock-extended";
import { BehaviorSubject, firstValueFrom, timeout } from "rxjs";
import { BehaviorSubject, firstValueFrom, of, timeout } from "rxjs";

import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AvatarService } from "@bitwarden/common/auth/abstractions/avatar.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { UserId } from "@bitwarden/common/types/guid";

import { AccountSwitcherService } from "./account-switcher.service";
Expand All @@ -16,7 +16,7 @@ describe("AccountSwitcherService", () => {
const activeAccountSubject = new BehaviorSubject<{ id: UserId } & AccountInfo>(null);

const accountService = mock<AccountService>();
const stateService = mock<StateService>();
const avatarService = mock<AvatarService>();
const messagingService = mock<MessagingService>();
const environmentService = mock<EnvironmentService>();
const logService = mock<LogService>();
Expand All @@ -25,11 +25,13 @@ describe("AccountSwitcherService", () => {

beforeEach(() => {
jest.resetAllMocks();

accountService.accounts$ = accountsSubject;
accountService.activeAccount$ = activeAccountSubject;

accountSwitcherService = new AccountSwitcherService(
accountService,
stateService,
avatarService,
messagingService,
environmentService,
logService,
Expand All @@ -44,6 +46,7 @@ describe("AccountSwitcherService", () => {
status: AuthenticationStatus.Unlocked,
};

avatarService.getUserAvatarColor$.mockReturnValue(of("#cccccc"));
accountsSubject.next({
"1": user1AccountInfo,
} as Record<UserId, AccountInfo>);
Expand Down Expand Up @@ -72,6 +75,7 @@ describe("AccountSwitcherService", () => {
status: AuthenticationStatus.Unlocked,
};
}
avatarService.getUserAvatarColor$.mockReturnValue(of("#cccccc"));
accountsSubject.next(seedAccounts);
activeAccountSubject.next(
Object.assign(seedAccounts["1" as UserId], { id: "1" as UserId }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
} from "rxjs";

import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AvatarService } from "@bitwarden/common/auth/abstractions/avatar.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { UserId } from "@bitwarden/common/types/guid";

import { fromChromeEvent } from "../../../../platform/browser/from-chrome-event";
Expand Down Expand Up @@ -44,7 +44,7 @@ export class AccountSwitcherService {

constructor(
private accountService: AccountService,
private stateService: StateService,
private avatarService: AvatarService,
private messagingService: MessagingService,
private environmentService: EnvironmentService,
private logService: LogService,
Expand All @@ -68,7 +68,9 @@ export class AccountSwitcherService {
server: await this.environmentService.getHost(id),
status: account.status,
isActive: id === activeAccount?.id,
avatarColor: await this.stateService.getAvatarColor({ userId: id }),
avatarColor: await firstValueFrom(
this.avatarService.getUserAvatarColor$(id as UserId),
),
};
}),
);
Expand Down
Loading

0 comments on commit 7ea56a2

Please sign in to comment.