1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-28 07:49:41 +01:00

WIP updating callers

This commit is contained in:
Thomas Rittson 2024-10-28 11:10:54 +10:00
parent 5b0003b467
commit c0b97ec21f
No known key found for this signature in database
GPG Key ID: CDDDA03861C35E27
16 changed files with 71 additions and 26 deletions

View File

@ -21,11 +21,10 @@ import { LoginExport } from "@bitwarden/common/models/export/login.export";
import { SecureNoteExport } from "@bitwarden/common/models/export/secure-note.export";
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
import { OrganizationId } from "@bitwarden/common/types/guid";
import { CollectionId, OrganizationId } 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 { TotpService } from "@bitwarden/common/vault/abstractions/totp.service";
@ -48,6 +47,7 @@ import { CollectionResponse } from "../vault/models/collection.response";
import { FolderResponse } from "../vault/models/folder.response";
import { DownloadCommand } from "./download.command";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
export class GetCommand extends DownloadCommand {
constructor(
@ -58,7 +58,6 @@ export class GetCommand extends DownloadCommand {
private auditService: AuditService,
private keyService: KeyService,
encryptService: EncryptService,
private stateService: StateService,
private searchService: SearchService,
private apiService: ApiService,
private organizationService: OrganizationService,
@ -95,7 +94,7 @@ export class GetCommand extends DownloadCommand {
case "folder":
return await this.getFolder(id);
case "collection":
return await this.getCollection(id);
return await this.getCollection(id as CollectionId);
case "org-collection":
return await this.getOrganizationCollection(id, normalizedOptions);
case "organization":
@ -406,10 +405,14 @@ export class GetCommand extends DownloadCommand {
return Response.success(res);
}
private async getCollection(id: string) {
private async getCollection(id: CollectionId) {
const activeUserId$ = this.accountService.activeAccount$.pipe(getUserId);
let decCollection: CollectionView = null;
if (Utils.isGuid(id)) {
const collection = await this.collectionService.get(id);
const collection = (
await firstValueFrom(this.collectionService.encryptedCollections$(activeUserId$))
).find((c) => c.id === id);
if (collection != null) {
const orgKeys = await firstValueFrom(this.keyService.activeUserOrgKeys$);
decCollection = await collection.decrypt(
@ -417,7 +420,9 @@ export class GetCommand extends DownloadCommand {
);
}
} else if (id.trim() !== "") {
let collections = await this.collectionService.getAllDecrypted();
let collections = await firstValueFrom(
this.collectionService.decryptedCollections$(activeUserId$),
);
collections = CliUtils.searchCollections(collections, id);
if (collections.length > 1) {
return Response.multipleResults(collections.map((c) => c.id));

View File

@ -12,6 +12,8 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { SearchService } from "@bitwarden/common/abstractions/search.service";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { EventType } from "@bitwarden/common/enums";
import { ListResponse as ApiListResponse } from "@bitwarden/common/models/response/list.response";
import { Utils } from "@bitwarden/common/platform/misc/utils";
@ -38,6 +40,7 @@ export class ListCommand {
private organizationUserApiService: OrganizationUserApiService,
private apiService: ApiService,
private eventCollectionService: EventCollectionService,
private accountService: AccountService,
) {}
async run(object: string, cmdOptions: Record<string, any>): Promise<Response> {
@ -146,7 +149,10 @@ export class ListCommand {
}
private async listCollections(options: Options) {
let collections = await this.collectionService.getAllDecrypted();
const activeUserId$ = this.accountService.activeAccount$.pipe(getUserId);
let collections = await firstValueFrom(
this.collectionService.decryptedCollections$(activeUserId$),
);
if (options.organizationId != null) {
collections = collections.filter((c) => {

View File

@ -58,7 +58,6 @@ export class OssServeConfigurator {
this.serviceContainer.auditService,
this.serviceContainer.keyService,
this.serviceContainer.encryptService,
this.serviceContainer.stateService,
this.serviceContainer.searchService,
this.serviceContainer.apiService,
this.serviceContainer.organizationService,
@ -75,6 +74,7 @@ export class OssServeConfigurator {
this.serviceContainer.organizationUserApiService,
this.serviceContainer.apiService,
this.serviceContainer.eventCollectionService,
this.serviceContainer.accountService,
);
this.createCommand = new CreateCommand(
this.serviceContainer.cipherService,

View File

@ -144,7 +144,6 @@ export class SendProgram extends BaseProgram {
this.serviceContainer.auditService,
this.serviceContainer.keyService,
this.serviceContainer.encryptService,
this.serviceContainer.stateService,
this.serviceContainer.searchService,
this.serviceContainer.apiService,
this.serviceContainer.organizationService,

View File

@ -111,6 +111,7 @@ export class VaultProgram extends BaseProgram {
this.serviceContainer.organizationUserApiService,
this.serviceContainer.apiService,
this.serviceContainer.eventCollectionService,
this.serviceContainer.accountService,
);
const response = await command.run(object, cmd);
@ -179,7 +180,6 @@ export class VaultProgram extends BaseProgram {
this.serviceContainer.auditService,
this.serviceContainer.keyService,
this.serviceContainer.encryptService,
this.serviceContainer.stateService,
this.serviceContainer.searchService,
this.serviceContainer.apiService,
this.serviceContainer.organizationService,

View File

@ -5,7 +5,6 @@ import { CollectionsComponent as BaseCollectionsComponent } from "@bitwarden/ang
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.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 { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { ToastService } from "@bitwarden/components";
@ -21,7 +20,6 @@ export class CollectionsComponent extends BaseCollectionsComponent {
collectionService: CollectionService,
platformUtilsService: PlatformUtilsService,
organizationService: OrganizationService,
logService: LogService,
accountService: AccountService,
toastService: ToastService,
) {
@ -31,7 +29,6 @@ export class CollectionsComponent extends BaseCollectionsComponent {
i18nService,
cipherService,
organizationService,
logService,
accountService,
toastService,
);

View File

@ -4,6 +4,7 @@ import { ActivatedRoute } from "@angular/router";
import { CollectionService } from "@bitwarden/admin-console/common";
import { ModalService } from "@bitwarden/angular/services/modal.service";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
@ -31,6 +32,7 @@ export class UnsecuredWebsitesReportComponent
i18nService: I18nService,
syncService: SyncService,
collectionService: CollectionService,
accountService: AccountService,
) {
super(
cipherService,
@ -40,6 +42,7 @@ export class UnsecuredWebsitesReportComponent
i18nService,
syncService,
collectionService,
accountService,
);
}

View File

@ -7,7 +7,10 @@ import { CollectionService } from "@bitwarden/admin-console/common";
import { I18nPipe } from "@bitwarden/angular/platform/pipes/i18n.pipe";
import { ModalService } from "@bitwarden/angular/services/modal.service";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/spec";
import { UserId } from "@bitwarden/common/types/guid";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import { PasswordRepromptService } from "@bitwarden/vault";
@ -21,12 +24,15 @@ describe("UnsecuredWebsitesReportComponent", () => {
let organizationService: MockProxy<OrganizationService>;
let syncServiceMock: MockProxy<SyncService>;
let collectionService: MockProxy<CollectionService>;
let accountService: FakeAccountService;
beforeEach(() => {
organizationService = mock<OrganizationService>();
organizationService.organizations$ = of([]);
syncServiceMock = mock<SyncService>();
collectionService = mock<CollectionService>();
collectionService.encryptedCollections$.mockReturnValue(of([]));
accountService = mockAccountServiceWith("UserId" as UserId);
// 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
TestBed.configureTestingModule({
@ -60,6 +66,10 @@ describe("UnsecuredWebsitesReportComponent", () => {
provide: CollectionService,
useValue: collectionService,
},
{
provide: AccountService,
useValue: accountService,
},
],
schemas: [],
}).compileComponents();

View File

@ -1,8 +1,11 @@
import { Component, OnInit } from "@angular/core";
import { firstValueFrom } from "rxjs";
import { CollectionService, Collection } from "@bitwarden/admin-console/common";
import { ModalService } from "@bitwarden/angular/services/modal.service";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
@ -19,6 +22,8 @@ import { CipherReportComponent } from "./cipher-report.component";
export class UnsecuredWebsitesReportComponent extends CipherReportComponent implements OnInit {
disabled = true;
private activeUserId$ = this.accountService.activeAccount$.pipe(getUserId);
constructor(
protected cipherService: CipherService,
protected organizationService: OrganizationService,
@ -27,6 +32,7 @@ export class UnsecuredWebsitesReportComponent extends CipherReportComponent impl
i18nService: I18nService,
syncService: SyncService,
private collectionService: CollectionService,
private accountService: AccountService,
) {
super(
cipherService,
@ -44,7 +50,9 @@ export class UnsecuredWebsitesReportComponent extends CipherReportComponent impl
async setCiphers() {
const allCiphers = await this.getAllCiphers();
const allCollections = await this.collectionService.getAll();
const allCollections = await firstValueFrom(
this.collectionService.encryptedCollections$(this.activeUserId$),
);
this.filterStatus = [0];
const unsecuredCiphers = allCiphers.filter((c) => {

View File

@ -66,7 +66,7 @@ describe("AddEditComponentV2", () => {
folderService = mock<FolderService>();
folderService.folderViews$ = of([]);
collectionService = mock<CollectionService>();
collectionService.decryptedCollections$ = of([]);
collectionService.decryptedCollections$.mockReturnValue(of([]));
const mockDefaultCipherFormConfigService = {
buildConfig: jest.fn().mockResolvedValue({

View File

@ -1,11 +1,12 @@
import { DialogConfig, DialogRef, DIALOG_DATA } from "@angular/cdk/dialog";
import { Component, Inject, OnDestroy, OnInit } from "@angular/core";
import { firstValueFrom, map } from "rxjs";
import { firstValueFrom } from "rxjs";
import { CollectionService, CollectionView } from "@bitwarden/admin-console/common";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getUserId } from "@bitwarden/common/auth/services/account.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";
@ -52,6 +53,7 @@ export class BulkShareDialogComponent implements OnInit, OnDestroy {
shareableCiphers: CipherView[] = [];
private writeableCollections: CollectionView[] = [];
private activeUserId$ = this.accountService.activeAccount$.pipe(getUserId);
constructor(
@Inject(DIALOG_DATA) params: BulkShareDialogParams,
@ -73,7 +75,9 @@ export class BulkShareDialogComponent implements OnInit, OnDestroy {
(c) => !c.hasOldAttachments && c.organizationId == null,
);
this.nonShareableCount = this.ciphers.length - this.shareableCiphers.length;
const allCollections = await this.collectionService.getAllDecrypted();
const allCollections = await firstValueFrom(
this.collectionService.decryptedCollections$(this.activeUserId$),
);
this.writeableCollections = allCollections.filter((c) => !c.readOnly);
this.organizations = await this.organizationService.getAll();
if (this.organizationId == null && this.organizations.length > 0) {
@ -100,14 +104,11 @@ export class BulkShareDialogComponent implements OnInit, OnDestroy {
submit = async () => {
const checkedCollectionIds = this.collections.filter(isChecked).map((c) => c.id);
try {
const activeUserId = await firstValueFrom(
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
);
await this.cipherService.shareManyWithServer(
this.shareableCiphers,
this.organizationId,
checkedCollectionIds,
activeUserId,
await firstValueFrom(this.activeUserId$),
);
const orgName =
this.organizations.find((o) => o.id === this.organizationId)?.name ??

View File

@ -64,7 +64,7 @@ describe("vault filter service", () => {
organizationService.memberOrganizations$ = organizations;
folderService.folderViews$ = folderViews;
collectionService.decryptedCollections$ = collectionViews;
collectionService.decryptedCollections$.mockReturnValue(collectionViews);
policyService.policyAppliesToActiveUser$
.calledWith(PolicyType.PersonalOwnership)
.mockReturnValue(personalOwnershipPolicy);
@ -81,6 +81,7 @@ describe("vault filter service", () => {
i18nService,
stateProvider,
collectionService,
accountService,
);
collapsedGroupingsState = stateProvider.activeUser.getFake(COLLAPSED_GROUPINGS);
});

View File

@ -19,6 +19,8 @@ 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 { getUserId } from "@bitwarden/common/auth/services/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { ActiveUserState, StateProvider } from "@bitwarden/common/platform/state";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
@ -43,6 +45,8 @@ const NestingDelimiter = "/";
@Injectable()
export class VaultFilterService implements VaultFilterServiceAbstraction {
private activeUserId$ = this.accountService.activeAccount$.pipe(getUserId);
organizationTree$: Observable<TreeNode<OrganizationFilter>> = combineLatest([
this.organizationService.memberOrganizations$,
this.policyService.policyAppliesToActiveUser$(PolicyType.SingleOrg),
@ -65,8 +69,9 @@ export class VaultFilterService implements VaultFilterServiceAbstraction {
map((folders) => this.buildFolderTree(folders)),
);
filteredCollections$: Observable<CollectionView[]> =
this.collectionService.decryptedCollections$.pipe(
filteredCollections$: Observable<CollectionView[]> = this.collectionService
.decryptedCollections$(this.activeUserId$)
.pipe(
combineLatestWith(this._organizationFilter),
switchMap(([collections, org]) => {
return this.filterCollections(collections, org);
@ -93,6 +98,7 @@ export class VaultFilterService implements VaultFilterServiceAbstraction {
protected i18nService: I18nService,
protected stateProvider: StateProvider,
protected collectionService: CollectionService,
protected accountService: AccountService,
) {}
async getCollectionNodeFromTree(id: string) {

View File

@ -120,6 +120,7 @@ import { FolderFilter, OrganizationFilter } from "./vault-filter/shared/models/v
import { VaultFilterModule } from "./vault-filter/vault-filter.module";
import { VaultHeaderComponent } from "./vault-header/vault-header.component";
import { VaultOnboardingComponent } from "./vault-onboarding/vault-onboarding.component";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
const BroadcasterSubscriptionId = "VaultComponent";
const SearchTextDebounceInterval = 200;
@ -178,6 +179,7 @@ export class VaultComponent implements OnInit, OnDestroy {
private refresh$ = new BehaviorSubject<void>(null);
private destroy$ = new Subject<void>();
private extensionRefreshEnabled: boolean;
private activeUserId$ = this.accountService.activeAccount$.pipe(getUserId);
private vaultItemDialogRef?: DialogRef<VaultItemDialogResult> | undefined;
@ -268,7 +270,7 @@ export class VaultComponent implements OnInit, OnDestroy {
});
const filter$ = this.routedVaultFilterService.filter$;
const allCollections$ = this.collectionService.decryptedCollections$;
const allCollections$ = this.collectionService.decryptedCollections$(this.activeUserId$);
const nestedCollections$ = allCollections$.pipe(
map((collections) => getNestedCollectionTree(collections)),
);

View File

@ -5,11 +5,14 @@ import { mock } from "jest-mock-extended";
import { CollectionService } from "@bitwarden/admin-console/common";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.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 { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.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 { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
@ -63,6 +66,7 @@ describe("ViewComponent", () => {
useValue: mock<BillingAccountProfileStateService>(),
},
{ provide: ConfigService, useValue: mock<ConfigService>() },
{ provide: AccountService, useValue: mockAccountServiceWith("UserId" as UserId) },
{
provide: CipherAuthorizationService,
useValue: {

View File

@ -4,6 +4,7 @@ import { map, Observable, ReplaySubject, Subject } from "rxjs";
import { CollectionAdminView, CollectionService } from "@bitwarden/admin-console/common";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { StateProvider } from "@bitwarden/common/platform/state";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
@ -32,6 +33,7 @@ export class VaultFilterService extends BaseVaultFilterService implements OnDest
i18nService: I18nService,
stateProvider: StateProvider,
collectionService: CollectionService,
accountService: AccountService,
) {
super(
organizationService,
@ -41,6 +43,7 @@ export class VaultFilterService extends BaseVaultFilterService implements OnDest
i18nService,
stateProvider,
collectionService,
accountService,
);
}