mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 23:25:45 +03:00
Move the 'isPremiumUser' flag from a common VaultItem property to a Login specific property (#486)
This commit is contained in:
parent
c88825f134
commit
11fcaa6678
7 changed files with 18 additions and 34 deletions
|
@ -96,7 +96,7 @@ fun VaultItemLoginContent(
|
||||||
item {
|
item {
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
TotpField(
|
TotpField(
|
||||||
isPremiumUser = commonState.isPremiumUser,
|
isPremiumUser = loginItemState.isPremiumUser,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = 16.dp),
|
.padding(horizontal = 16.dp),
|
||||||
|
|
|
@ -496,7 +496,6 @@ data class VaultItemState(
|
||||||
* @property lastUpdated A formatted date string indicating when the item was last
|
* @property lastUpdated A formatted date string indicating when the item was last
|
||||||
* updated.
|
* updated.
|
||||||
* @property notes Contains general notes taken by the user.
|
* @property notes Contains general notes taken by the user.
|
||||||
* @property isPremiumUser Indicates if the user has subscribed to a premium account.
|
|
||||||
* @property customFields A list of custom fields that user has added.
|
* @property customFields A list of custom fields that user has added.
|
||||||
* @property requiresReprompt Indicates if a master password prompt is required to view
|
* @property requiresReprompt Indicates if a master password prompt is required to view
|
||||||
* secure fields.
|
* secure fields.
|
||||||
|
@ -506,7 +505,6 @@ data class VaultItemState(
|
||||||
val name: String,
|
val name: String,
|
||||||
val lastUpdated: String,
|
val lastUpdated: String,
|
||||||
val notes: String?,
|
val notes: String?,
|
||||||
val isPremiumUser: Boolean,
|
|
||||||
val customFields: List<Custom>,
|
val customFields: List<Custom>,
|
||||||
val requiresReprompt: Boolean,
|
val requiresReprompt: Boolean,
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
|
@ -570,8 +568,11 @@ data class VaultItemState(
|
||||||
* @property passwordHistoryCount An integer indicating how many times the password
|
* @property passwordHistoryCount An integer indicating how many times the password
|
||||||
* has been changed.
|
* has been changed.
|
||||||
* @property uris The URI associated with the login item.
|
* @property uris The URI associated with the login item.
|
||||||
* @property passwordRevisionDate
|
* @property passwordRevisionDate An optional string indicating the last time the
|
||||||
* @property totp
|
* password was changed.
|
||||||
|
* @property totp The optional TOTP string value to be displayed.
|
||||||
|
* @property isPremiumUser Indicates if the user has subscribed to a premium
|
||||||
|
* account.
|
||||||
*/
|
*/
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class Login(
|
data class Login(
|
||||||
|
@ -581,6 +582,7 @@ data class VaultItemState(
|
||||||
val uris: List<UriData>,
|
val uris: List<UriData>,
|
||||||
val passwordRevisionDate: String?,
|
val passwordRevisionDate: String?,
|
||||||
val totp: String?,
|
val totp: String?,
|
||||||
|
val isPremiumUser: Boolean,
|
||||||
) : ItemType() {
|
) : ItemType() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,7 +32,6 @@ fun CipherView.toViewState(
|
||||||
VaultItemState.ViewState.Content(
|
VaultItemState.ViewState.Content(
|
||||||
common = VaultItemState.ViewState.Content.Common(
|
common = VaultItemState.ViewState.Content.Common(
|
||||||
name = name,
|
name = name,
|
||||||
isPremiumUser = isPremiumUser,
|
|
||||||
requiresReprompt = reprompt == CipherRepromptType.PASSWORD,
|
requiresReprompt = reprompt == CipherRepromptType.PASSWORD,
|
||||||
customFields = fields.orEmpty().map { it.toCustomField() },
|
customFields = fields.orEmpty().map { it.toCustomField() },
|
||||||
lastUpdated = dateTimeFormatter.format(revisionDate),
|
lastUpdated = dateTimeFormatter.format(revisionDate),
|
||||||
|
@ -55,6 +54,7 @@ fun CipherView.toViewState(
|
||||||
},
|
},
|
||||||
passwordHistoryCount = passwordHistory?.count(),
|
passwordHistoryCount = passwordHistory?.count(),
|
||||||
totp = loginValues.totp,
|
totp = loginValues.totp,
|
||||||
|
isPremiumUser = isPremiumUser,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -528,6 +528,7 @@ class VaultItemScreenTest : BaseComposeTest() {
|
||||||
uris = emptyList(),
|
uris = emptyList(),
|
||||||
passwordRevisionDate = null,
|
passwordRevisionDate = null,
|
||||||
totp = null,
|
totp = null,
|
||||||
|
isPremiumUser = true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -1064,7 +1065,6 @@ private val DEFAULT_COMMON: VaultItemState.ViewState.Content.Common =
|
||||||
lastUpdated = "12/31/69 06:16 PM",
|
lastUpdated = "12/31/69 06:16 PM",
|
||||||
name = "cipher",
|
name = "cipher",
|
||||||
notes = "Lots of notes",
|
notes = "Lots of notes",
|
||||||
isPremiumUser = true,
|
|
||||||
customFields = listOf(
|
customFields = listOf(
|
||||||
VaultItemState.ViewState.Content.Common.Custom.TextField(
|
VaultItemState.ViewState.Content.Common.Custom.TextField(
|
||||||
name = "text",
|
name = "text",
|
||||||
|
@ -1102,6 +1102,7 @@ private val DEFAULT_LOGIN: VaultItemState.ViewState.Content.ItemType.Login =
|
||||||
),
|
),
|
||||||
passwordRevisionDate = "4/14/83 3:56 PM",
|
passwordRevisionDate = "4/14/83 3:56 PM",
|
||||||
totp = "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example",
|
totp = "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example",
|
||||||
|
isPremiumUser = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
private val DEFAULT_IDENTITY: VaultItemState.ViewState.Content.ItemType.Identity =
|
private val DEFAULT_IDENTITY: VaultItemState.ViewState.Content.ItemType.Identity =
|
||||||
|
@ -1122,7 +1123,6 @@ private val EMPTY_COMMON: VaultItemState.ViewState.Content.Common =
|
||||||
name = "cipher",
|
name = "cipher",
|
||||||
lastUpdated = "12/31/69 06:16 PM",
|
lastUpdated = "12/31/69 06:16 PM",
|
||||||
notes = null,
|
notes = null,
|
||||||
isPremiumUser = true,
|
|
||||||
customFields = emptyList(),
|
customFields = emptyList(),
|
||||||
requiresReprompt = true,
|
requiresReprompt = true,
|
||||||
)
|
)
|
||||||
|
@ -1135,6 +1135,7 @@ private val EMPTY_LOGIN_TYPE: VaultItemState.ViewState.Content.ItemType.Login =
|
||||||
uris = emptyList(),
|
uris = emptyList(),
|
||||||
passwordRevisionDate = null,
|
passwordRevisionDate = null,
|
||||||
totp = null,
|
totp = null,
|
||||||
|
isPremiumUser = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
private val EMPTY_IDENTITY_TYPE: VaultItemState.ViewState.Content.ItemType.Identity =
|
private val EMPTY_IDENTITY_TYPE: VaultItemState.ViewState.Content.ItemType.Identity =
|
||||||
|
|
|
@ -681,6 +681,7 @@ class VaultItemViewModelTest : BaseViewModelTest() {
|
||||||
passwordRevisionDate = "12/31/69 06:16 PM",
|
passwordRevisionDate = "12/31/69 06:16 PM",
|
||||||
totp = "otpauth://totp/Example:alice@google.com" +
|
totp = "otpauth://totp/Example:alice@google.com" +
|
||||||
"?secret=JBSWY3DPEHPK3PXP&issuer=Example",
|
"?secret=JBSWY3DPEHPK3PXP&issuer=Example",
|
||||||
|
isPremiumUser = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
private val DEFAULT_COMMON: VaultItemState.ViewState.Content.Common =
|
private val DEFAULT_COMMON: VaultItemState.ViewState.Content.Common =
|
||||||
|
@ -688,7 +689,6 @@ class VaultItemViewModelTest : BaseViewModelTest() {
|
||||||
name = "login cipher",
|
name = "login cipher",
|
||||||
lastUpdated = "12/31/69 06:16 PM",
|
lastUpdated = "12/31/69 06:16 PM",
|
||||||
notes = "Lots of notes",
|
notes = "Lots of notes",
|
||||||
isPremiumUser = true,
|
|
||||||
customFields = listOf(
|
customFields = listOf(
|
||||||
VaultItemState.ViewState.Content.Common.Custom.TextField(
|
VaultItemState.ViewState.Content.Common.Custom.TextField(
|
||||||
name = "text",
|
name = "text",
|
||||||
|
|
|
@ -45,8 +45,8 @@ class CipherViewExtensionsTest {
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
VaultItemState.ViewState.Content(
|
VaultItemState.ViewState.Content(
|
||||||
common = createCommonContent(isEmpty = false).copy(isPremiumUser = isPremiumUser),
|
common = createCommonContent(isEmpty = false),
|
||||||
type = createLoginContent(isEmpty = false),
|
type = createLoginContent(isEmpty = false).copy(isPremiumUser = isPremiumUser),
|
||||||
),
|
),
|
||||||
viewState,
|
viewState,
|
||||||
)
|
)
|
||||||
|
@ -66,9 +66,8 @@ class CipherViewExtensionsTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `toViewState should transform full CipherView into ViewState Identity Content with premium`() {
|
fun `toViewState should transform full CipherView into ViewState Identity Content`() {
|
||||||
val viewState = createCipherView(type = CipherType.IDENTITY, isEmpty = false)
|
val viewState = createCipherView(type = CipherType.IDENTITY, isEmpty = false)
|
||||||
.toViewState(isPremiumUser = true)
|
.toViewState(isPremiumUser = true)
|
||||||
|
|
||||||
|
@ -81,22 +80,6 @@ class CipherViewExtensionsTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
|
||||||
fun `toViewState should transform full CipherView into ViewState Identity Content without premium`() {
|
|
||||||
val isPremiumUser = false
|
|
||||||
val viewState = createCipherView(type = CipherType.IDENTITY, isEmpty = false)
|
|
||||||
.toViewState(isPremiumUser = isPremiumUser)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
VaultItemState.ViewState.Content(
|
|
||||||
common = createCommonContent(isEmpty = false).copy(isPremiumUser = isPremiumUser),
|
|
||||||
type = createIdentityContent(isEmpty = false),
|
|
||||||
),
|
|
||||||
viewState,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `toViewState should transform empty CipherView into ViewState Identity Content`() {
|
fun `toViewState should transform empty CipherView into ViewState Identity Content`() {
|
||||||
val viewState = createCipherView(type = CipherType.IDENTITY, isEmpty = true)
|
val viewState = createCipherView(type = CipherType.IDENTITY, isEmpty = true)
|
||||||
|
@ -171,9 +154,8 @@ class CipherViewExtensionsTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
|
||||||
@Test
|
@Test
|
||||||
fun `toViewState should transform full CipherView into ViewState Secure Note Content with premium`() {
|
fun `toViewState should transform full CipherView into ViewState Secure Note Content`() {
|
||||||
val viewState = createCipherView(type = CipherType.SECURE_NOTE, isEmpty = false)
|
val viewState = createCipherView(type = CipherType.SECURE_NOTE, isEmpty = false)
|
||||||
.toViewState(isPremiumUser = true)
|
.toViewState(isPremiumUser = true)
|
||||||
|
|
||||||
|
@ -193,7 +175,7 @@ class CipherViewExtensionsTest {
|
||||||
.toViewState(isPremiumUser = true)
|
.toViewState(isPremiumUser = true)
|
||||||
|
|
||||||
val expectedState = VaultItemState.ViewState.Content(
|
val expectedState = VaultItemState.ViewState.Content(
|
||||||
common = createCommonContent(isEmpty = true).copy(isPremiumUser = true),
|
common = createCommonContent(isEmpty = true),
|
||||||
type = VaultItemState.ViewState.Content.ItemType.SecureNote,
|
type = VaultItemState.ViewState.Content.ItemType.SecureNote,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,6 @@ fun createCommonContent(isEmpty: Boolean): VaultItemState.ViewState.Content.Comm
|
||||||
name = "mockName",
|
name = "mockName",
|
||||||
lastUpdated = "1/1/70 12:16 AM",
|
lastUpdated = "1/1/70 12:16 AM",
|
||||||
notes = null,
|
notes = null,
|
||||||
isPremiumUser = true,
|
|
||||||
customFields = emptyList(),
|
customFields = emptyList(),
|
||||||
requiresReprompt = true,
|
requiresReprompt = true,
|
||||||
)
|
)
|
||||||
|
@ -146,7 +145,6 @@ fun createCommonContent(isEmpty: Boolean): VaultItemState.ViewState.Content.Comm
|
||||||
name = "mockName",
|
name = "mockName",
|
||||||
lastUpdated = "1/1/70 12:16 AM",
|
lastUpdated = "1/1/70 12:16 AM",
|
||||||
notes = "Lots of notes",
|
notes = "Lots of notes",
|
||||||
isPremiumUser = true,
|
|
||||||
customFields = listOf(
|
customFields = listOf(
|
||||||
VaultItemState.ViewState.Content.Common.Custom.TextField(
|
VaultItemState.ViewState.Content.Common.Custom.TextField(
|
||||||
name = "text",
|
name = "text",
|
||||||
|
@ -199,6 +197,7 @@ fun createLoginContent(isEmpty: Boolean): VaultItemState.ViewState.Content.ItemT
|
||||||
passwordRevisionDate = "1/1/70 12:16 AM".takeUnless { isEmpty },
|
passwordRevisionDate = "1/1/70 12:16 AM".takeUnless { isEmpty },
|
||||||
totp = "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
|
totp = "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"
|
||||||
.takeUnless { isEmpty },
|
.takeUnless { isEmpty },
|
||||||
|
isPremiumUser = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun createIdentityContent(
|
fun createIdentityContent(
|
||||||
|
|
Loading…
Reference in a new issue