mirror of
https://github.com/bitwarden/android.git
synced 2026-06-06 22:42:58 -05:00
Add API support for deleting an attachment (#767)
This commit is contained in:
committed by
Álison Fernandes
parent
049930da40
commit
6223b225c5
@@ -54,6 +54,15 @@ interface CiphersApi {
|
||||
@Path("cipherId") cipherId: String,
|
||||
): Result<Unit>
|
||||
|
||||
/**
|
||||
* Deletes an attachment from a cipher.
|
||||
*/
|
||||
@DELETE("ciphers/{cipherId}/attachment/{attachmentId}")
|
||||
suspend fun deleteCipherAttachment(
|
||||
@Path("cipherId") cipherId: String,
|
||||
@Path("attachmentId") attachmentId: String,
|
||||
): Result<Unit>
|
||||
|
||||
/**
|
||||
* Restores a cipher.
|
||||
*/
|
||||
|
||||
@@ -40,6 +40,14 @@ interface CiphersService {
|
||||
*/
|
||||
suspend fun softDeleteCipher(cipherId: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Attempt to delete an attachment from a cipher.
|
||||
*/
|
||||
suspend fun deleteCipherAttachment(
|
||||
cipherId: String,
|
||||
attachmentId: String,
|
||||
): Result<Unit>
|
||||
|
||||
/**
|
||||
* Attempt to restore a cipher.
|
||||
*/
|
||||
|
||||
@@ -51,6 +51,15 @@ class CiphersServiceImpl constructor(
|
||||
override suspend fun softDeleteCipher(cipherId: String): Result<Unit> =
|
||||
ciphersApi.softDeleteCipher(cipherId = cipherId)
|
||||
|
||||
override suspend fun deleteCipherAttachment(
|
||||
cipherId: String,
|
||||
attachmentId: String,
|
||||
): Result<Unit> =
|
||||
ciphersApi.deleteCipherAttachment(
|
||||
cipherId = cipherId,
|
||||
attachmentId = attachmentId,
|
||||
)
|
||||
|
||||
override suspend fun restoreCipher(cipherId: String): Result<Unit> =
|
||||
ciphersApi.restoreCipher(cipherId = cipherId)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.x8bit.bitwarden.data.vault.manager.VaultLockManager
|
||||
import com.x8bit.bitwarden.data.vault.manager.model.VerificationCodeItem
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.CreateCipherResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.CreateSendResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.DeleteAttachmentResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.DeleteCipherResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.DeleteSendResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.GenerateTotpResult
|
||||
@@ -241,4 +242,13 @@ interface VaultRepository : VaultLockManager {
|
||||
* Attempt to delete a send.
|
||||
*/
|
||||
suspend fun deleteSend(sendId: String): DeleteSendResult
|
||||
|
||||
/**
|
||||
* Attempt to delete an attachment from a send.
|
||||
*/
|
||||
suspend fun deleteCipherAttachment(
|
||||
cipherId: String,
|
||||
attachmentId: String,
|
||||
cipherView: CipherView,
|
||||
): DeleteAttachmentResult
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import com.x8bit.bitwarden.data.vault.manager.VaultLockManager
|
||||
import com.x8bit.bitwarden.data.vault.manager.model.VerificationCodeItem
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.CreateCipherResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.CreateSendResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.DeleteAttachmentResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.DeleteCipherResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.DeleteSendResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.GenerateTotpResult
|
||||
@@ -487,6 +488,40 @@ class VaultRepositoryImpl(
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun deleteCipherAttachment(
|
||||
cipherId: String,
|
||||
attachmentId: String,
|
||||
cipherView: CipherView,
|
||||
): DeleteAttachmentResult {
|
||||
val userId = requireNotNull(activeUserId)
|
||||
return ciphersService
|
||||
.deleteCipherAttachment(
|
||||
cipherId = cipherId,
|
||||
attachmentId = attachmentId,
|
||||
)
|
||||
.flatMap {
|
||||
vaultSdkSource
|
||||
.encryptCipher(
|
||||
userId = userId,
|
||||
cipherView = cipherView.copy(
|
||||
attachments = cipherView.attachments?.mapNotNull {
|
||||
if (it.id == attachmentId) null else it
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
.onSuccess { cipher ->
|
||||
vaultDiskSource.saveCipher(
|
||||
userId = userId,
|
||||
cipher = cipher.toEncryptedNetworkCipherResponse(),
|
||||
)
|
||||
}
|
||||
.fold(
|
||||
onSuccess = { DeleteAttachmentResult.Success },
|
||||
onFailure = { DeleteAttachmentResult.Error },
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun restoreCipher(
|
||||
cipherId: String,
|
||||
cipherView: CipherView,
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.x8bit.bitwarden.data.vault.repository.model
|
||||
|
||||
/**
|
||||
* Models result of deleting an attachment from a cipher.
|
||||
*/
|
||||
sealed class DeleteAttachmentResult {
|
||||
|
||||
/**
|
||||
* Attachment deleted successfully.
|
||||
*/
|
||||
data object Success : DeleteAttachmentResult()
|
||||
|
||||
/**
|
||||
* Generic error while deleting an attachment.
|
||||
*/
|
||||
data object Error : DeleteAttachmentResult()
|
||||
}
|
||||
Reference in New Issue
Block a user