1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-13 23:13:36 +00:00

Add orgId to interface for admin deleteMany calls

This commit is contained in:
Nik Gilmore
2026-01-08 14:28:36 -08:00
parent 087d18ff24
commit 8dbc41992e
2 changed files with 39 additions and 12 deletions

View File

@@ -222,7 +222,12 @@ export abstract class CipherService implements UserKeyRotationDataProvider<Ciphe
abstract moveManyWithServer(ids: string[], folderId: string, userId: UserId): Promise<any>;
abstract delete(id: string | string[], userId: UserId): Promise<any>;
abstract deleteWithServer(id: string, userId: UserId, asAdmin?: boolean): Promise<any>;
abstract deleteManyWithServer(ids: string[], userId: UserId, asAdmin?: boolean): Promise<any>;
abstract deleteManyWithServer(
ids: string[],
userId: UserId,
asAdmin?: boolean,
orgId?: OrganizationId,
): Promise<any>;
abstract deleteAttachment(
id: string,
revisionDate: string,
@@ -240,7 +245,12 @@ export abstract class CipherService implements UserKeyRotationDataProvider<Ciphe
abstract getLocaleSortingFunction(): (a: CipherViewLike, b: CipherViewLike) => number;
abstract softDelete(id: string | string[], userId: UserId): Promise<any>;
abstract softDeleteWithServer(id: string, userId: UserId, asAdmin?: boolean): Promise<any>;
abstract softDeleteManyWithServer(ids: string[], userId: UserId, asAdmin?: boolean): Promise<any>;
abstract softDeleteManyWithServer(
ids: string[],
userId: UserId,
asAdmin?: boolean,
orgId?: OrganizationId,
): Promise<any>;
abstract restore(
cipher: { id: string; revisionDate: string } | { id: string; revisionDate: string }[],
userId: UserId,
@@ -266,7 +276,7 @@ export abstract class CipherService implements UserKeyRotationDataProvider<Ciphe
abstract getNextIdentityCipher(userId: UserId): Promise<CipherView>;
/**
* Decrypts a cipher using either the SDK or the legacy method based on the feature flag.
* Decrypts a cipher using either the use-sdk-cipheroperationsSDK or the legacy method based on the feature flag.
* @param cipher The cipher to decrypt.
* @param userId The user ID to use for decryption.
* @returns A promise that resolves to the decrypted cipher view.

View File

@@ -1447,12 +1447,17 @@ export class CipherService implements CipherServiceAbstraction {
await this.clearCache(userId);
}
async deleteManyWithServer(ids: string[], userId: UserId, asAdmin = false): Promise<any> {
async deleteManyWithServer(
ids: string[],
userId: UserId,
asAdmin = false,
orgId?: OrganizationId,
): Promise<any> {
const useSdk = await this.configService.getFeatureFlag(
FeatureFlag.PM27632_SdkCipherCrudOperations,
);
if (useSdk) {
return this.deleteManyWithServer_sdk(ids, userId, asAdmin);
return this.deleteManyWithServer_sdk(ids, userId, asAdmin, orgId);
}
const request = new CipherBulkDeleteRequest(ids);
@@ -1468,6 +1473,7 @@ export class CipherService implements CipherServiceAbstraction {
ids: string[],
userId: UserId,
asAdmin = false,
orgId?: OrganizationId,
): Promise<any> {
await firstValueFrom(
this.sdkService.userClient$(userId).pipe(
@@ -1477,14 +1483,16 @@ export class CipherService implements CipherServiceAbstraction {
}
using ref = sdk.take();
if (asAdmin) {
if (orgId == null) {
throw new Error("Organization ID is required for admin delete.");
}
await ref.value
.vault()
.ciphers()
.admin()
.delete_many(
ids.map((id) => asUuid(id)),
null, // TODO: This is required in the SDK - need to remove from SDK or require here
// But how did it work before????? The server also throws a 404 if not provided....
asUuid(orgId),
);
} else {
await ref.value
@@ -1701,12 +1709,17 @@ export class CipherService implements CipherServiceAbstraction {
await this.clearCache(userId);
}
async softDeleteManyWithServer(ids: string[], userId: UserId, asAdmin = false): Promise<any> {
async softDeleteManyWithServer(
ids: string[],
userId: UserId,
asAdmin = false,
orgId?: OrganizationId,
): Promise<any> {
const useSdk = await this.configService.getFeatureFlag(
FeatureFlag.PM27632_SdkCipherCrudOperations,
);
if (useSdk) {
return this.softDeleteManyWithServer_sdk(ids, userId, asAdmin);
return this.softDeleteManyWithServer_sdk(ids, userId, asAdmin, orgId);
}
const request = new CipherBulkDeleteRequest(ids);
@@ -1719,7 +1732,12 @@ export class CipherService implements CipherServiceAbstraction {
await this.softDelete(ids, userId);
}
async softDeleteManyWithServer_sdk(ids: string[], userId: UserId, asAdmin = false): Promise<any> {
async softDeleteManyWithServer_sdk(
ids: string[],
userId: UserId,
asAdmin = false,
orgId?: OrganizationId,
): Promise<any> {
await firstValueFrom(
this.sdkService.userClient$(userId).pipe(
switchMap(async (sdk) => {
@@ -1734,8 +1752,7 @@ export class CipherService implements CipherServiceAbstraction {
.admin()
.soft_delete_many(
ids.map((id) => asUuid(id)),
null, // TODO: This is required in the SDK - need to remove from SDK or require here
// But how did it work before????? The server also throws a 404 if not provided....
asUuid(orgId),
);
} else {
await ref.value