diff --git a/libs/common/src/vault/abstractions/cipher.service.ts b/libs/common/src/vault/abstractions/cipher.service.ts index ac7f7f23ed6..ccdaec1b461 100644 --- a/libs/common/src/vault/abstractions/cipher.service.ts +++ b/libs/common/src/vault/abstractions/cipher.service.ts @@ -222,7 +222,12 @@ export abstract class CipherService implements UserKeyRotationDataProvider; abstract delete(id: string | string[], userId: UserId): Promise; abstract deleteWithServer(id: string, userId: UserId, asAdmin?: boolean): Promise; - abstract deleteManyWithServer(ids: string[], userId: UserId, asAdmin?: boolean): Promise; + abstract deleteManyWithServer( + ids: string[], + userId: UserId, + asAdmin?: boolean, + orgId?: OrganizationId, + ): Promise; abstract deleteAttachment( id: string, revisionDate: string, @@ -240,7 +245,12 @@ export abstract class CipherService implements UserKeyRotationDataProvider number; abstract softDelete(id: string | string[], userId: UserId): Promise; abstract softDeleteWithServer(id: string, userId: UserId, asAdmin?: boolean): Promise; - abstract softDeleteManyWithServer(ids: string[], userId: UserId, asAdmin?: boolean): Promise; + abstract softDeleteManyWithServer( + ids: string[], + userId: UserId, + asAdmin?: boolean, + orgId?: OrganizationId, + ): Promise; abstract restore( cipher: { id: string; revisionDate: string } | { id: string; revisionDate: string }[], userId: UserId, @@ -266,7 +276,7 @@ export abstract class CipherService implements UserKeyRotationDataProvider; /** - * 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. diff --git a/libs/common/src/vault/services/cipher.service.ts b/libs/common/src/vault/services/cipher.service.ts index 5fa20661217..2ec4cb17b1f 100644 --- a/libs/common/src/vault/services/cipher.service.ts +++ b/libs/common/src/vault/services/cipher.service.ts @@ -1447,12 +1447,17 @@ export class CipherService implements CipherServiceAbstraction { await this.clearCache(userId); } - async deleteManyWithServer(ids: string[], userId: UserId, asAdmin = false): Promise { + async deleteManyWithServer( + ids: string[], + userId: UserId, + asAdmin = false, + orgId?: OrganizationId, + ): Promise { 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 { 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 { + async softDeleteManyWithServer( + ids: string[], + userId: UserId, + asAdmin = false, + orgId?: OrganizationId, + ): Promise { 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 { + async softDeleteManyWithServer_sdk( + ids: string[], + userId: UserId, + asAdmin = false, + orgId?: OrganizationId, + ): Promise { 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