1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-12 22:44:11 +00:00

Update callers in cli

This commit is contained in:
gbubemismith
2024-11-06 19:39:45 -05:00
parent 2584759539
commit c2cc509113
8 changed files with 42 additions and 26 deletions

View File

@@ -22,6 +22,8 @@ import { CipherResponse } from "../vault/models/cipher.response";
import { FolderResponse } from "../vault/models/folder.response";
export class EditCommand {
private activeUserId$ = this.accountService.activeAccount$.pipe(map((a) => a?.id));
constructor(
private cipherService: CipherService,
private folderService: FolderService,
@@ -119,12 +121,12 @@ export class EditCommand {
cipher.collectionIds = req;
try {
const activeUserId = await firstValueFrom(
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
);
const updatedCipher = await this.cipherService.saveCollectionsWithServer(cipher);
const decCipher = await updatedCipher.decrypt(
await this.cipherService.getKeyForCipherKeyDecryption(updatedCipher, activeUserId),
await this.cipherService.getKeyForCipherKeyDecryption(
updatedCipher,
await firstValueFrom(this.activeUserId$),
),
);
const res = new CipherResponse(decCipher);
return Response.success(res);
@@ -134,7 +136,7 @@ export class EditCommand {
}
private async editFolder(id: string, req: FolderExport) {
const folder = await this.folderService.getFromState(id);
const folder = await this.folderService.getFromState(id, this.activeUserId$);
if (folder == null) {
return Response.notFound();
}
@@ -147,7 +149,7 @@ export class EditCommand {
const encFolder = await this.folderService.encrypt(folderView, userKey);
try {
await this.folderApiService.save(encFolder);
const updatedFolder = await this.folderService.get(folder.id);
const updatedFolder = await this.folderService.get(folder.id, this.activeUserId$);
const decFolder = await updatedFolder.decrypt();
const res = new FolderResponse(decFolder);
return Response.success(res);

View File

@@ -50,6 +50,8 @@ import { FolderResponse } from "../vault/models/folder.response";
import { DownloadCommand } from "./download.command";
export class GetCommand extends DownloadCommand {
private activeUserId$ = this.accountService.activeAccount$.pipe(map((a) => a?.id));
constructor(
private cipherService: CipherService,
private folderService: FolderService,
@@ -113,12 +115,12 @@ export class GetCommand extends DownloadCommand {
let decCipher: CipherView = null;
if (Utils.isGuid(id)) {
const cipher = await this.cipherService.get(id);
const activeUserId = await firstValueFrom(
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
);
if (cipher != null) {
decCipher = await cipher.decrypt(
await this.cipherService.getKeyForCipherKeyDecryption(cipher, activeUserId),
await this.cipherService.getKeyForCipherKeyDecryption(
cipher,
await firstValueFrom(this.activeUserId$),
),
);
}
} else if (id.trim() !== "") {
@@ -384,12 +386,12 @@ export class GetCommand extends DownloadCommand {
private async getFolder(id: string) {
let decFolder: FolderView = null;
if (Utils.isGuid(id)) {
const folder = await this.folderService.getFromState(id);
const folder = await this.folderService.getFromState(id, this.activeUserId$);
if (folder != null) {
decFolder = await folder.decrypt();
}
} else if (id.trim() !== "") {
let folders = await this.folderService.getAllDecryptedFromState();
let folders = await this.folderService.getAllDecryptedFromState(this.activeUserId$);
folders = CliUtils.searchFolders(folders, id);
if (folders.length > 1) {
return Response.multipleResults(folders.map((f) => f.id));
@@ -551,11 +553,9 @@ export class GetCommand extends DownloadCommand {
private async getFingerprint(id: string) {
let fingerprint: string[] = null;
if (id === "me") {
const activeUserId = await firstValueFrom(
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
);
const publicKey = await firstValueFrom(this.keyService.userPublicKey$(activeUserId));
fingerprint = await this.keyService.getFingerprint(activeUserId, publicKey);
const userId = await firstValueFrom(this.activeUserId$);
const publicKey = await firstValueFrom(this.keyService.userPublicKey$(userId));
fingerprint = await this.keyService.getFingerprint(userId, publicKey);
} else if (Utils.isGuid(id)) {
try {
const response = await this.apiService.getUserPublicKey(id);

View File

@@ -1,4 +1,4 @@
import { firstValueFrom } from "rxjs";
import { firstValueFrom, map } from "rxjs";
import {
OrganizationUserApiService,
@@ -12,6 +12,7 @@ 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 { 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 +39,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> {
@@ -135,7 +137,8 @@ export class ListCommand {
}
private async listFolders(options: Options) {
let folders = await this.folderService.getAllDecryptedFromState();
const activeUserId$ = this.accountService.activeAccount$.pipe(map((a) => a?.id));
let folders = await this.folderService.getAllDecryptedFromState(activeUserId$);
if (options.search != null && options.search.trim() !== "") {
folders = CliUtils.searchFolders(folders, options.search);

View File

@@ -75,6 +75,7 @@ export class OssServeConfigurator {
this.serviceContainer.organizationUserApiService,
this.serviceContainer.apiService,
this.serviceContainer.eventCollectionService,
this.serviceContainer.accountService,
);
this.createCommand = new CreateCommand(
this.serviceContainer.cipherService,
@@ -114,6 +115,7 @@ export class OssServeConfigurator {
this.serviceContainer.folderApiService,
this.serviceContainer.billingAccountProfileStateService,
this.serviceContainer.cipherAuthorizationService,
this.serviceContainer.accountService,
);
this.confirmCommand = new ConfirmCommand(
this.serviceContainer.apiService,

View File

@@ -671,7 +671,11 @@ export class ServiceContainer {
this.stateProvider,
);
this.folderApiService = new FolderApiService(this.folderService, this.apiService);
this.folderApiService = new FolderApiService(
this.folderService,
this.apiService,
this.accountService,
);
const lockedCallback = async (userId?: string) =>
await this.keyService.clearStoredUserKey(KeySuffixOptions.Auto);

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);
@@ -320,6 +321,7 @@ export class VaultProgram extends BaseProgram {
this.serviceContainer.folderApiService,
this.serviceContainer.billingAccountProfileStateService,
this.serviceContainer.cipherAuthorizationService,
this.serviceContainer.accountService,
);
const response = await command.run(object, id, cmd);
this.processResponse(response);

View File

@@ -28,6 +28,8 @@ import { CipherResponse } from "./models/cipher.response";
import { FolderResponse } from "./models/folder.response";
export class CreateCommand {
private activeUserId$ = this.accountService.activeAccount$.pipe(map((a) => a?.id));
constructor(
private cipherService: CipherService,
private folderService: FolderService,
@@ -150,9 +152,7 @@ export class CreateCommand {
}
try {
const activeUserId = await firstValueFrom(
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
);
const activeUserId = await firstValueFrom(this.activeUserId$);
const updatedCipher = await this.cipherService.saveAttachmentRawWithServer(
cipher,
fileName,
@@ -174,7 +174,7 @@ export class CreateCommand {
const folder = await this.folderService.encrypt(FolderExport.toView(req), userKey);
try {
await this.folderApiService.save(folder);
const newFolder = await this.folderService.get(folder.id);
const newFolder = await this.folderService.get(folder.id, this.activeUserId$);
const decFolder = await newFolder.decrypt();
const res = new FolderResponse(decFolder);
return Response.success(res);

View File

@@ -1,6 +1,7 @@
import { firstValueFrom } from "rxjs";
import { firstValueFrom, map } from "rxjs";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
@@ -19,6 +20,7 @@ export class DeleteCommand {
private folderApiService: FolderApiServiceAbstraction,
private accountProfileService: BillingAccountProfileStateService,
private cipherAuthorizationService: CipherAuthorizationService,
private accountService: AccountService,
) {}
async run(object: string, id: string, cmdOptions: Record<string, any>): Promise<Response> {
@@ -103,7 +105,8 @@ export class DeleteCommand {
}
private async deleteFolder(id: string) {
const folder = await this.folderService.getFromState(id);
const activeUserId$ = this.accountService.activeAccount$.pipe(map((a) => a?.id));
const folder = await this.folderService.getFromState(id, activeUserId$);
if (folder == null) {
return Response.notFound();
}