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