BIT-874: Expose Collections data from VaultRepository (#382)

This commit is contained in:
Brian Yencho
2023-12-13 10:00:15 -06:00
committed by Álison Fernandes
parent 12a816e678
commit 3d6111cd8b
10 changed files with 241 additions and 3 deletions

View File

@@ -951,7 +951,7 @@ data class SyncResponseJson(
*
* @property organizationId The organization ID of the collection.
* @property shouldHidePasswords If the collection should hide passwords.
* @property name The name of the collection (nullable).
* @property name The name of the collection.
* @property externalId The external ID of the collection (nullable).
* @property isReadOnly If the collection is marked as read only.
* @property id The ID of the collection.
@@ -965,7 +965,7 @@ data class SyncResponseJson(
val shouldHidePasswords: Boolean,
@SerialName("name")
val name: String?,
val name: String,
@SerialName("externalId")
val externalId: String?,

View File

@@ -29,6 +29,7 @@ import com.x8bit.bitwarden.data.vault.repository.model.VaultState
import com.x8bit.bitwarden.data.vault.repository.model.VaultUnlockResult
import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedNetworkCipher
import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedSdkCipherList
import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedSdkCollectionList
import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedSdkFolderList
import com.x8bit.bitwarden.data.vault.repository.util.toEncryptedSdkSendList
import com.x8bit.bitwarden.data.vault.repository.util.toVaultUnlockResult
@@ -399,9 +400,19 @@ class VaultRepositoryImpl constructor(
.toEncryptedSdkFolderList(),
)
},
) { decryptedCipherList, decryptedFolderList ->
{
vaultSdkSource
.decryptCollectionList(
collectionList = syncResponse
.collections
.orEmpty()
.toEncryptedSdkCollectionList(),
)
},
) { decryptedCipherList, decryptedFolderList, decryptedCollectionList ->
VaultData(
cipherViewList = decryptedCipherList,
collectionViewList = decryptedCollectionList,
folderViewList = decryptedFolderList,
)
}

View File

@@ -1,15 +1,18 @@
package com.x8bit.bitwarden.data.vault.repository.model
import com.bitwarden.core.CipherView
import com.bitwarden.core.CollectionView
import com.bitwarden.core.FolderView
/**
* Represents decrypted vault data.
*
* @param cipherViewList List of decrypted ciphers.
* @param collectionViewList List of decrypted collections.
* @param folderViewList List of decrypted folders.
*/
data class VaultData(
val cipherViewList: List<CipherView>,
val collectionViewList: List<CollectionView>,
val folderViewList: List<FolderView>,
)

View File

@@ -0,0 +1,25 @@
package com.x8bit.bitwarden.data.vault.repository.util
import com.bitwarden.core.Collection
import com.x8bit.bitwarden.data.vault.datasource.network.model.SyncResponseJson
/**
* Converts a [SyncResponseJson.Collection] object to a corresponding Bitwarden SDK [Collection]
* object.
*/
fun SyncResponseJson.Collection.toEncryptedSdkCollection(): Collection =
Collection(
id = this.id,
organizationId = this.organizationId,
name = this.name,
externalId = this.externalId,
hidePasswords = this.shouldHidePasswords,
readOnly = this.isReadOnly,
)
/**
* Converts a list of [SyncResponseJson.Collection] objects to a list of corresponding
* Bitwarden SDK [Collection] objects.
*/
fun List<SyncResponseJson.Collection>.toEncryptedSdkCollectionList(): List<Collection> =
map { it.toEncryptedSdkCollection() }