mirror of
https://github.com/bitwarden/android.git
synced 2026-04-27 11:28:41 -05:00
[PM-31615] feat: Updated Send network models to support email verification (#6519)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
@file:Suppress("TooManyFunctions")
|
||||
|
||||
package com.x8bit.bitwarden.data.vault.repository.util
|
||||
|
||||
import com.bitwarden.core.data.repository.util.SpecialCharWithPrecedenceComparator
|
||||
import com.bitwarden.network.model.SendAuthTypeJson
|
||||
import com.bitwarden.network.model.SendJsonRequest
|
||||
import com.bitwarden.network.model.SendTypeJson
|
||||
import com.bitwarden.network.model.SyncResponseJson
|
||||
@@ -31,6 +34,8 @@ fun Send.toEncryptedNetworkSend(fileLength: Long? = null): SendJsonRequest =
|
||||
password = password,
|
||||
isDisabled = disabled,
|
||||
shouldHideEmail = hideEmail,
|
||||
authType = authType.toNetworkSendAuthType(),
|
||||
emails = emails,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -93,10 +98,31 @@ fun SyncResponseJson.Send.toEncryptedSdkSend(): Send =
|
||||
revisionDate = revisionDate.toInstant(),
|
||||
deletionDate = deletionDate.toInstant(),
|
||||
expirationDate = expirationDate?.toInstant(),
|
||||
emails = null,
|
||||
authType = AuthType.NONE,
|
||||
emails = emails,
|
||||
authType = authType?.toSdkAuthType() ?: AuthType.NONE,
|
||||
)
|
||||
|
||||
/**
|
||||
* Converts a Bitwarden SDK [AuthType] object to a corresponding [SendAuthTypeJson] object.
|
||||
*/
|
||||
private fun AuthType.toNetworkSendAuthType(): SendAuthTypeJson =
|
||||
when (this) {
|
||||
AuthType.EMAIL -> SendAuthTypeJson.EMAIL
|
||||
AuthType.PASSWORD -> SendAuthTypeJson.PASSWORD
|
||||
AuthType.NONE -> SendAuthTypeJson.NONE
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a [SendAuthTypeJson] objects to a corresponding
|
||||
* Bitwarden SDK [AuthType].
|
||||
*/
|
||||
private fun SendAuthTypeJson.toSdkAuthType(): AuthType =
|
||||
when (this) {
|
||||
SendAuthTypeJson.PASSWORD -> AuthType.PASSWORD
|
||||
SendAuthTypeJson.EMAIL -> AuthType.EMAIL
|
||||
SendAuthTypeJson.NONE -> AuthType.NONE
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a [SyncResponseJson.Send.Text] object to a corresponding
|
||||
* Bitwarden SDK [SendText] object.
|
||||
|
||||
@@ -584,7 +584,8 @@ private const val SEND_JSON = """
|
||||
"text": "mockText-1"
|
||||
},
|
||||
"key": "mockKey-1",
|
||||
"expirationDate": "2023-10-27T12:00:00.000Z"
|
||||
"expirationDate": "2023-10-27T12:00:00.000Z",
|
||||
"authType": 1
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ fun createMockSdkSend(
|
||||
deletionDate = ZonedDateTime.parse("2023-10-27T12:00:00Z").toInstant(),
|
||||
expirationDate = ZonedDateTime.parse("2023-10-27T12:00:00Z").toInstant(),
|
||||
emails = null,
|
||||
authType = AuthType.NONE,
|
||||
authType = AuthType.PASSWORD,
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.bitwarden.network.model
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import com.bitwarden.core.data.serializer.BaseEnumeratedIntSerializer
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Represents different types of send Authentication.
|
||||
*/
|
||||
@Serializable(SendAuthTypeSerializer::class)
|
||||
enum class SendAuthTypeJson {
|
||||
/**
|
||||
* Email-based OTP authentication.
|
||||
*/
|
||||
@SerialName("0")
|
||||
EMAIL,
|
||||
|
||||
/**
|
||||
* Password-based authentication.
|
||||
*/
|
||||
@SerialName("1")
|
||||
PASSWORD,
|
||||
|
||||
/**
|
||||
* No authentication required.
|
||||
*/
|
||||
@SerialName("2")
|
||||
NONE,
|
||||
}
|
||||
|
||||
@Keep
|
||||
private class SendAuthTypeSerializer : BaseEnumeratedIntSerializer<SendAuthTypeJson>(
|
||||
className = "SendAuthTypeJson",
|
||||
values = SendAuthTypeJson.entries.toTypedArray(),
|
||||
)
|
||||
@@ -9,6 +9,7 @@ import java.time.ZonedDateTime
|
||||
* Represents a send request.
|
||||
*
|
||||
* @property type The type of send.
|
||||
* @property authType The type of authentication method required to access this Send.
|
||||
* @property name The name of the send (nullable).
|
||||
* @property notes The notes of the send (nullable).
|
||||
* @property key The send key.
|
||||
@@ -21,12 +22,16 @@ import java.time.ZonedDateTime
|
||||
* @property password The password protecting this send (nullable).
|
||||
* @property isDisabled Indicate if this send is disabled.
|
||||
* @property shouldHideEmail Should the email address of the sender be hidden (nullable).
|
||||
* @property emails The emails allowed to authenticate this send (nullable).
|
||||
*/
|
||||
@Serializable
|
||||
data class SendJsonRequest(
|
||||
@SerialName("type")
|
||||
val type: SendTypeJson,
|
||||
|
||||
@SerialName("authType")
|
||||
val authType: SendAuthTypeJson?,
|
||||
|
||||
@SerialName("name")
|
||||
val name: String?,
|
||||
|
||||
@@ -64,4 +69,7 @@ data class SendJsonRequest(
|
||||
|
||||
@SerialName("hideEmail")
|
||||
val shouldHideEmail: Boolean?,
|
||||
|
||||
@SerialName("emails")
|
||||
val emails: String?,
|
||||
)
|
||||
|
||||
@@ -899,8 +899,12 @@ data class SyncResponseJson(
|
||||
* @property maxAccessCount The max access count of the send object (nullable).
|
||||
* @property shouldHideEmail If the send object should hide the email.
|
||||
* @property type The type of send object.
|
||||
* @property authType Specifies the authentication method required to access this Send.
|
||||
* @property accessId The access ID of the send object (nullable).
|
||||
* @property password The password of the send object (nullable).
|
||||
* Mutually exclusive with [emails]
|
||||
* @property emails Comma-separated list of emails that may access the send using OTP
|
||||
* authentication. Mutually exclusive with [password]
|
||||
* @property file The file of the send object.
|
||||
* @property deletionDate The max access count of the send object.
|
||||
* @property name The name of the send object (nullable).
|
||||
@@ -931,12 +935,18 @@ data class SyncResponseJson(
|
||||
@SerialName("type")
|
||||
val type: SendTypeJson,
|
||||
|
||||
@SerialName("authType")
|
||||
val authType: SendAuthTypeJson?,
|
||||
|
||||
@SerialName("accessId")
|
||||
val accessId: String?,
|
||||
|
||||
@SerialName("password")
|
||||
val password: String?,
|
||||
|
||||
@SerialName("emails")
|
||||
val emails: String?,
|
||||
|
||||
@SerialName("file")
|
||||
val file: File?,
|
||||
|
||||
|
||||
@@ -226,7 +226,8 @@ private const val CREATE_UPDATE_SEND_SUCCESS_JSON = """
|
||||
"revisionDate": "2023-10-27T12:00:00.00Z",
|
||||
"expirationDate": "2023-10-27T12:00:00.00Z",
|
||||
"deletionDate": "2023-10-27T12:00:00.00Z",
|
||||
"hideEmail": false
|
||||
"hideEmail": false,
|
||||
"authType": 1,
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -258,7 +259,8 @@ private const val CREATE_FILE_SEND_SUCCESS_JSON = """
|
||||
"revisionDate": "2023-10-27T12:00:00.00Z",
|
||||
"expirationDate": "2023-10-27T12:00:00.00Z",
|
||||
"deletionDate": "2023-10-27T12:00:00.00Z",
|
||||
"hideEmail": false
|
||||
"hideEmail": false,
|
||||
"authType": 1
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -388,7 +388,8 @@ private const val SYNC_SUCCESS_JSON = """
|
||||
"text": "mockText-1"
|
||||
},
|
||||
"key": "mockKey-1",
|
||||
"expirationDate": "2023-10-27T12:00:00.00Z"
|
||||
"expirationDate": "2023-10-27T12:00:00.00Z",
|
||||
"authType": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ fun createMockSendJsonRequest(
|
||||
password: String? = "mockPassword-$number",
|
||||
isDisabled: Boolean = false,
|
||||
shouldHideEmail: Boolean? = false,
|
||||
authTypeJson: SendAuthTypeJson = SendAuthTypeJson.PASSWORD,
|
||||
emails: String? = null,
|
||||
): SendJsonRequest =
|
||||
SendJsonRequest(
|
||||
name = name,
|
||||
@@ -36,4 +38,6 @@ fun createMockSendJsonRequest(
|
||||
password = password,
|
||||
isDisabled = isDisabled,
|
||||
shouldHideEmail = shouldHideEmail,
|
||||
authType = authTypeJson,
|
||||
emails = emails,
|
||||
)
|
||||
|
||||
@@ -39,6 +39,8 @@ fun createMockSend(
|
||||
text: SyncResponseJson.Send.Text? = createMockText(number = number),
|
||||
key: String? = "mockKey-$number",
|
||||
expirationDate: ZonedDateTime? = ZonedDateTime.parse("2023-10-27T12:00:00Z"),
|
||||
authTypeJson: SendAuthTypeJson = SendAuthTypeJson.PASSWORD,
|
||||
emails: String? = null,
|
||||
): SyncResponseJson.Send =
|
||||
SyncResponseJson.Send(
|
||||
accessCount = accessCount,
|
||||
@@ -57,6 +59,8 @@ fun createMockSend(
|
||||
text = text,
|
||||
key = key,
|
||||
expirationDate = expirationDate,
|
||||
authType = authTypeJson,
|
||||
emails = emails,
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user