mirror of
https://github.com/bitwarden/browser
synced 2026-02-09 05:00:10 +00:00
Adds originalCipherId and collectionIds to updateCipher
This commit is contained in:
@@ -126,6 +126,7 @@ export abstract class CipherService implements UserKeyRotationDataProvider<Ciphe
|
||||
abstract updateWithServer(
|
||||
cipherView: CipherView,
|
||||
userId: UserId,
|
||||
originalCipherView?: CipherView,
|
||||
orgAdmin?: boolean,
|
||||
): Promise<CipherView>;
|
||||
|
||||
|
||||
@@ -334,13 +334,14 @@ export class CipherView implements View, InitializerMetadata {
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps CipherView to SdkCipherView
|
||||
* Maps CipherView to an SDK CipherCreateRequest
|
||||
*
|
||||
* @returns {SdkCipherView} The SDK cipher view object
|
||||
* @returns {CipherCreateRequest} The SDK cipher create request object
|
||||
*/
|
||||
toSdkCreateCipherRequest(): CipherCreateRequest {
|
||||
const sdkCipherCreateRequest: CipherCreateRequest = {
|
||||
organizationId: this.organizationId ? asUuid(this.organizationId) : undefined,
|
||||
collectionIds: this.collectionIds ? this.collectionIds.map((i) => asUuid(i)) : [],
|
||||
folderId: this.folderId ? asUuid(this.folderId) : undefined,
|
||||
name: this.name ?? "",
|
||||
notes: this.notes,
|
||||
@@ -354,9 +355,9 @@ export class CipherView implements View, InitializerMetadata {
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps CipherView to SdkCipherView
|
||||
* Maps CipherView to an SDK CipherEditRequest
|
||||
*
|
||||
* @returns {SdkCipherView} The SDK cipher view object
|
||||
* @returns {CipherEditRequest} The SDK cipher edit request object
|
||||
*/
|
||||
toSdkUpdateCipherRequest(): CipherEditRequest {
|
||||
const sdkCipherEditRequest: CipherEditRequest = {
|
||||
@@ -378,6 +379,11 @@ export class CipherView implements View, InitializerMetadata {
|
||||
return sdkCipherEditRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SDK CipherViewType object for the cipher.
|
||||
*
|
||||
* @returns {CipherViewType} The SDK CipherViewType for the cipher.
|
||||
*/
|
||||
getSdkCipherViewType(): CipherViewType {
|
||||
let viewType: CipherViewType;
|
||||
switch (this.type) {
|
||||
|
||||
@@ -960,6 +960,7 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
async updateWithServer(
|
||||
cipherView: CipherView,
|
||||
userId: UserId,
|
||||
originalCipherView?: CipherView,
|
||||
orgAdmin?: boolean,
|
||||
): Promise<CipherView> {
|
||||
// const sdkCipherEncryptionEnabled = false;
|
||||
@@ -968,7 +969,7 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
);
|
||||
|
||||
if (sdkCipherEncryptionEnabled) {
|
||||
return await this.updateWithServer_sdk(cipherView, userId, orgAdmin);
|
||||
return await this.updateWithServer_sdk(cipherView, userId, originalCipherView, orgAdmin);
|
||||
} else {
|
||||
const encrypted = await this.encrypt(cipherView, userId);
|
||||
const updatedCipher = await this.updateWithServer_legacy(encrypted, orgAdmin);
|
||||
@@ -980,6 +981,7 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
async updateWithServer_sdk(
|
||||
cipher: CipherView,
|
||||
userId: UserId,
|
||||
originalCipherView?: CipherView,
|
||||
orgAdmin?: boolean,
|
||||
): Promise<CipherView> {
|
||||
return firstValueFrom(
|
||||
@@ -996,8 +998,7 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
.vault()
|
||||
.ciphers()
|
||||
.admin()
|
||||
// TODO: Need to take actual "origCipher" instead of passing the literal same object.
|
||||
.edit(sdkUpdateRequest, cipher.toSdkCipherView());
|
||||
.edit(sdkUpdateRequest, originalCipherView?.toSdkCipherView());
|
||||
} else {
|
||||
result = await ref.value.vault().ciphers().edit(sdkUpdateRequest);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ export class DefaultCipherFormService implements CipherFormService {
|
||||
if (config.originalCipher == null) {
|
||||
throw new Error("Original cipher is required for updating an existing cipher");
|
||||
}
|
||||
const originalCipherView = await this.decryptCipher(config.originalCipher);
|
||||
|
||||
// Updating an existing cipher
|
||||
|
||||
@@ -67,6 +68,7 @@ export class DefaultCipherFormService implements CipherFormService {
|
||||
const savedCipherView = await this.cipherService.updateWithServer(
|
||||
cipher,
|
||||
activeUserId,
|
||||
originalCipherView,
|
||||
config.admin,
|
||||
);
|
||||
// Temporary
|
||||
@@ -80,6 +82,7 @@ export class DefaultCipherFormService implements CipherFormService {
|
||||
const newCipher = await this.cipherService.updateWithServer(
|
||||
cipher,
|
||||
activeUserId,
|
||||
originalCipherView,
|
||||
config.admin || originalCollectionIds.size === 0,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user