mirror of
https://github.com/bitwarden/browser
synced 2026-02-14 07:23:45 +00:00
Fix broken CipherView conversion functions
This commit is contained in:
@@ -282,7 +282,21 @@ export class CipherView implements View, InitializerMetadata {
|
||||
cipherView.folderId = uuidAsString(obj.folderId);
|
||||
cipherView.name = obj.name;
|
||||
cipherView.notes = obj.notes;
|
||||
cipherView.type = obj.type;
|
||||
|
||||
// SDK returns type as a discriminated union object, extract the actual CipherType
|
||||
const sdkType = (obj.type as any) ?? { login: {} };
|
||||
if ("login" in sdkType) {
|
||||
cipherView.type = CipherType.Login;
|
||||
} else if ("card" in sdkType) {
|
||||
cipherView.type = CipherType.Card;
|
||||
} else if ("identity" in sdkType) {
|
||||
cipherView.type = CipherType.Identity;
|
||||
} else if ("secureNote" in sdkType) {
|
||||
cipherView.type = CipherType.SecureNote;
|
||||
} else if ("sshKey" in sdkType) {
|
||||
cipherView.type = CipherType.SshKey;
|
||||
}
|
||||
|
||||
cipherView.favorite = obj.favorite;
|
||||
cipherView.organizationUseTotp = obj.organizationUseTotp;
|
||||
cipherView.permissions = obj.permissions
|
||||
@@ -291,12 +305,21 @@ export class CipherView implements View, InitializerMetadata {
|
||||
cipherView.edit = obj.edit;
|
||||
cipherView.viewPassword = obj.viewPassword;
|
||||
cipherView.localData = fromSdkLocalData(obj.localData);
|
||||
// Convert iterables to arrays to ensure .map() works
|
||||
cipherView.attachments =
|
||||
obj.attachments?.map((a) => AttachmentView.fromSdkAttachmentView(a)!) ?? [];
|
||||
cipherView.fields = obj.fields?.map((f) => FieldView.fromSdkFieldView(f)!) ?? [];
|
||||
obj.attachments != null
|
||||
? Array.from(obj.attachments).map((a) => AttachmentView.fromSdkAttachmentView(a)!)
|
||||
: [];
|
||||
cipherView.fields =
|
||||
obj.fields != null ? Array.from(obj.fields).map((f) => FieldView.fromSdkFieldView(f)!) : [];
|
||||
cipherView.passwordHistory =
|
||||
obj.passwordHistory?.map((ph) => PasswordHistoryView.fromSdkPasswordHistoryView(ph)!) ?? [];
|
||||
cipherView.collectionIds = obj.collectionIds?.map((i) => uuidAsString(i)) ?? [];
|
||||
obj.passwordHistory != null
|
||||
? Array.from(obj.passwordHistory).map(
|
||||
(ph) => PasswordHistoryView.fromSdkPasswordHistoryView(ph)!,
|
||||
)
|
||||
: [];
|
||||
cipherView.collectionIds =
|
||||
obj.collectionIds != null ? Array.from(obj.collectionIds).map((i) => uuidAsString(i)) : [];
|
||||
cipherView.revisionDate = new Date(obj.revisionDate);
|
||||
cipherView.creationDate = new Date(obj.creationDate);
|
||||
cipherView.deletedDate = obj.deletedDate == null ? undefined : new Date(obj.deletedDate);
|
||||
|
||||
@@ -509,10 +509,21 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
|
||||
const decryptResult = await ref.value.vault().ciphers().list();
|
||||
|
||||
const successViews = decryptResult.successes.map((sdkCipherView: any) =>
|
||||
// Convert successes - SDK returns array of SdkCipherView
|
||||
const successArray = Array.isArray(decryptResult.successes)
|
||||
? decryptResult.successes
|
||||
: Array.from(decryptResult.successes ?? []);
|
||||
|
||||
const successViews = successArray.map((sdkCipherView: any) =>
|
||||
CipherView.fromSdkCipherView(sdkCipherView),
|
||||
);
|
||||
const failureViews: CipherView[] = decryptResult.failures.map((failure) => {
|
||||
|
||||
// Convert failures to CipherView with error markers
|
||||
const failureArray = Array.isArray(decryptResult.failures)
|
||||
? decryptResult.failures
|
||||
: Array.from(decryptResult.failures ?? []);
|
||||
|
||||
const failureViews: CipherView[] = failureArray.map((failure: any) => {
|
||||
const cipher = Cipher.fromSdkCipher(failure);
|
||||
const cipherView = new CipherView(cipher);
|
||||
cipherView.name = DECRYPT_ERROR;
|
||||
@@ -805,7 +816,6 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
.admin()
|
||||
.list_org_ciphers(asUuid(organizationId), includeMemberItems);
|
||||
|
||||
// Convert successful decryptions to CipherView[]
|
||||
const cipherViews = decryptResult.successes.map((sdkCipherView: any) =>
|
||||
CipherView.fromSdkCipherView(sdkCipherView),
|
||||
);
|
||||
|
||||
@@ -242,7 +242,7 @@ export class CipherViewLikeUtils {
|
||||
_copyField = "usernameIdentity";
|
||||
}
|
||||
|
||||
return cipher.copyableFields.includes(copyActionToCopyableFieldMap[_copyField]);
|
||||
return cipher.copyableFields?.includes(copyActionToCopyableFieldMap[_copyField]) ?? false;
|
||||
}
|
||||
|
||||
// When the full cipher is available, check the specific field
|
||||
|
||||
Reference in New Issue
Block a user