mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-07 09:31:31 +01:00
Update callers in the browser
This commit is contained in:
parent
9011af99de
commit
d56dfd9caf
@ -2,7 +2,7 @@ import { mock, MockProxy } from "jest-mock-extended";
|
||||
import { BehaviorSubject, firstValueFrom } from "rxjs";
|
||||
|
||||
import { PolicyService } from "@bitwarden/common/admin-console/services/policy/policy.service";
|
||||
import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { AccountInfo } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||
import { AuthService } from "@bitwarden/common/auth/services/auth.service";
|
||||
import { ExtensionCommand } from "@bitwarden/common/autofill/constants";
|
||||
@ -11,8 +11,10 @@ import { UserNotificationSettingsService } from "@bitwarden/common/autofill/serv
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
import { SelfHostedEnvironment } from "@bitwarden/common/platform/services/default-environment.service";
|
||||
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
|
||||
import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/spec";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
||||
@ -58,9 +60,12 @@ describe("NotificationBackground", () => {
|
||||
const logService = mock<LogService>();
|
||||
const themeStateService = mock<ThemeStateService>();
|
||||
const configService = mock<ConfigService>();
|
||||
const accountService = mock<AccountService>();
|
||||
let accountService: FakeAccountService;
|
||||
|
||||
const userId = Utils.newGuid() as UserId;
|
||||
|
||||
beforeEach(() => {
|
||||
accountService = mockAccountServiceWith(userId);
|
||||
activeAccountStatusMock$ = new BehaviorSubject(AuthenticationStatus.Locked);
|
||||
authService = mock<AuthService>();
|
||||
authService.activeAccountStatus$ = activeAccountStatusMock$;
|
||||
|
@ -81,6 +81,8 @@ export default class NotificationBackground {
|
||||
getWebVaultUrlForNotification: () => this.getWebVaultUrl(),
|
||||
};
|
||||
|
||||
private activeUserId$ = this.accountService.activeAccount$.pipe(map((a) => a?.id));
|
||||
|
||||
constructor(
|
||||
private autofillService: AutofillService,
|
||||
private cipherService: CipherService,
|
||||
@ -609,11 +611,10 @@ export default class NotificationBackground {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeUserId = await firstValueFrom(
|
||||
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
|
||||
const cipher = await this.cipherService.encrypt(
|
||||
cipherView,
|
||||
await firstValueFrom(this.activeUserId$),
|
||||
);
|
||||
|
||||
const cipher = await this.cipherService.encrypt(cipherView, activeUserId);
|
||||
try {
|
||||
// We've only updated the password, no need to broadcast editedCipher message
|
||||
await this.cipherService.updateWithServer(cipher);
|
||||
@ -646,7 +647,7 @@ export default class NotificationBackground {
|
||||
return false;
|
||||
}
|
||||
|
||||
const folders = await firstValueFrom(this.folderService.folderViews$);
|
||||
const folders = await firstValueFrom(this.folderService.folderViews$(this.activeUserId$));
|
||||
return folders.some((x) => x.id === folderId);
|
||||
}
|
||||
|
||||
@ -695,7 +696,7 @@ export default class NotificationBackground {
|
||||
* Returns the first value found from the folder service's folderViews$ observable.
|
||||
*/
|
||||
private async getFolderData() {
|
||||
return await firstValueFrom(this.folderService.folderViews$);
|
||||
return await firstValueFrom(this.folderService.folderViews$(this.activeUserId$));
|
||||
}
|
||||
|
||||
private async getWebVaultUrl(): Promise<string> {
|
||||
|
@ -844,7 +844,11 @@ export default class MainBackground {
|
||||
this.cipherService,
|
||||
this.stateProvider,
|
||||
);
|
||||
this.folderApiService = new FolderApiService(this.folderService, this.apiService);
|
||||
this.folderApiService = new FolderApiService(
|
||||
this.folderService,
|
||||
this.apiService,
|
||||
this.accountService,
|
||||
);
|
||||
|
||||
this.userVerificationService = new UserVerificationService(
|
||||
this.keyService,
|
||||
|
@ -7,8 +7,11 @@ import { OrganizationService } from "@bitwarden/common/admin-console/abstraction
|
||||
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||
import { PolicyType } from "@bitwarden/common/admin-console/enums";
|
||||
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { ProductTierType } from "@bitwarden/common/billing/enums";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { mockAccountServiceWith } from "@bitwarden/common/spec";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
@ -31,7 +34,7 @@ describe("VaultPopupListFiltersService", () => {
|
||||
} as unknown as CollectionService;
|
||||
|
||||
const folderService = {
|
||||
folderViews$,
|
||||
folderViews$: () => folderViews$,
|
||||
} as unknown as FolderService;
|
||||
|
||||
const cipherService = {
|
||||
@ -56,6 +59,8 @@ describe("VaultPopupListFiltersService", () => {
|
||||
policyAppliesToActiveUser$.next(false);
|
||||
policyService.policyAppliesToActiveUser$.mockClear();
|
||||
|
||||
const accountService = mockAccountServiceWith("userId" as UserId);
|
||||
|
||||
collectionService.getAllNested = () => Promise.resolve([]);
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
@ -84,6 +89,10 @@ describe("VaultPopupListFiltersService", () => {
|
||||
useValue: policyService,
|
||||
},
|
||||
{ provide: FormBuilder, useClass: FormBuilder },
|
||||
{
|
||||
provide: AccountService,
|
||||
useValue: accountService,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
|
@ -17,6 +17,7 @@ import { OrganizationService } from "@bitwarden/common/admin-console/abstraction
|
||||
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||
import { PolicyType } from "@bitwarden/common/admin-console/enums";
|
||||
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { ProductTierType } from "@bitwarden/common/billing/enums";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
@ -81,6 +82,8 @@ export class VaultPopupListFiltersService {
|
||||
map((ciphers) => Object.values(ciphers)),
|
||||
);
|
||||
|
||||
private activeUserId$ = this.accountService.activeAccount$.pipe(map((a) => a?.id));
|
||||
|
||||
constructor(
|
||||
private folderService: FolderService,
|
||||
private cipherService: CipherService,
|
||||
@ -89,6 +92,7 @@ export class VaultPopupListFiltersService {
|
||||
private collectionService: CollectionService,
|
||||
private formBuilder: FormBuilder,
|
||||
private policyService: PolicyService,
|
||||
private accountService: AccountService,
|
||||
) {
|
||||
this.filterForm.controls.organization.valueChanges
|
||||
.pipe(takeUntilDestroyed())
|
||||
@ -242,7 +246,7 @@ export class VaultPopupListFiltersService {
|
||||
previousFilter.organization?.id === currentFilter.organization?.id,
|
||||
),
|
||||
),
|
||||
this.folderService.folderViews$,
|
||||
this.folderService.folderViews$(this.activeUserId$),
|
||||
this.cipherViews$,
|
||||
]).pipe(
|
||||
map(([filters, folders, cipherViews]): [PopupListFilter, FolderView[], CipherView[]] => {
|
||||
|
@ -4,10 +4,13 @@ import { By } from "@angular/platform-browser";
|
||||
import { mock } from "jest-mock-extended";
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import { mockAccountServiceWith } from "@bitwarden/common/spec";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
||||
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
||||
import { DialogService } from "@bitwarden/components";
|
||||
@ -52,8 +55,9 @@ describe("FoldersV2Component", () => {
|
||||
{ provide: PlatformUtilsService, useValue: mock<PlatformUtilsService>() },
|
||||
{ provide: ConfigService, useValue: mock<ConfigService>() },
|
||||
{ provide: LogService, useValue: mock<LogService>() },
|
||||
{ provide: FolderService, useValue: { folderViews$ } },
|
||||
{ provide: FolderService, useValue: { folderViews$: () => folderViews$ } },
|
||||
{ provide: I18nService, useValue: { t: (key: string) => key } },
|
||||
{ provide: AccountService, useValue: mockAccountServiceWith("UserId" as UserId) },
|
||||
],
|
||||
})
|
||||
.overrideComponent(FoldersV2Component, {
|
||||
|
@ -3,6 +3,7 @@ import { Component } from "@angular/core";
|
||||
import { map, Observable } from "rxjs";
|
||||
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
||||
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
||||
import {
|
||||
@ -45,12 +46,14 @@ export class FoldersV2Component {
|
||||
folders$: Observable<FolderView[]>;
|
||||
|
||||
NoFoldersIcon = VaultIcons.NoFolders;
|
||||
private activeUserId$ = this.accountService.activeAccount$.pipe(map((a) => a?.id));
|
||||
|
||||
constructor(
|
||||
private folderService: FolderService,
|
||||
private dialogService: DialogService,
|
||||
private accountService: AccountService,
|
||||
) {
|
||||
this.folders$ = this.folderService.folderViews$.pipe(
|
||||
this.folders$ = this.folderService.folderViews$(this.activeUserId$).pipe(
|
||||
map((folders) => {
|
||||
// Remove the last folder, which is the "no folder" option folder
|
||||
if (folders.length > 0) {
|
||||
|
@ -2,6 +2,7 @@ import { Component } from "@angular/core";
|
||||
import { Router } from "@angular/router";
|
||||
import { map, Observable } from "rxjs";
|
||||
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
||||
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
||||
|
||||
@ -12,11 +13,14 @@ import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
||||
export class FoldersComponent {
|
||||
folders$: Observable<FolderView[]>;
|
||||
|
||||
private activeUserId$ = this.accountService.activeAccount$.pipe(map((a) => a?.id));
|
||||
|
||||
constructor(
|
||||
private folderService: FolderService,
|
||||
private router: Router,
|
||||
private accountService: AccountService,
|
||||
) {
|
||||
this.folders$ = this.folderService.folderViews$.pipe(
|
||||
this.folders$ = this.folderService.folderViews$(this.activeUserId$).pipe(
|
||||
map((folders) => {
|
||||
if (folders.length > 0) {
|
||||
folders = folders.slice(0, folders.length - 1);
|
||||
|
@ -22,7 +22,7 @@ export class VaultFilterService extends BaseVaultFilterService {
|
||||
collectionService: CollectionService,
|
||||
policyService: PolicyService,
|
||||
stateProvider: StateProvider,
|
||||
private accountService: AccountService,
|
||||
accountService: AccountService,
|
||||
) {
|
||||
super(
|
||||
organizationService,
|
||||
@ -31,6 +31,7 @@ export class VaultFilterService extends BaseVaultFilterService {
|
||||
collectionService,
|
||||
policyService,
|
||||
stateProvider,
|
||||
accountService,
|
||||
);
|
||||
this.vaultFilter.myVaultOnly = false;
|
||||
this.vaultFilter.selectedOrganizationId = null;
|
||||
|
Loading…
Reference in New Issue
Block a user