Add needsMasterPassword field to userState (#1105)

This commit is contained in:
David Perez
2024-03-07 09:37:18 -06:00
committed by Álison Fernandes
parent f854f70613
commit 274aa620b1
20 changed files with 66 additions and 8 deletions

View File

@@ -41,6 +41,8 @@ data class UserState(
* authentication to view their vault.
* @property isVaultUnlocked Whether or not the user's vault is currently unlocked.
* @property needsPasswordReset If the user needs to reset their password.
* @property needsMasterPassword Indicates whether the user needs to create a password (e.g.
* they logged in using SSO and don't yet have one).
* @property organizations List of [Organization]s the user is associated with, if any.
* @property isBiometricsEnabled Indicates that the biometrics mechanism for unlocking the
* user's vault is enabled.
@@ -56,6 +58,7 @@ data class UserState(
val isLoggedIn: Boolean,
val isVaultUnlocked: Boolean,
val needsPasswordReset: Boolean,
val needsMasterPassword: Boolean,
val organizations: List<Organization>,
val isBiometricsEnabled: Boolean,
val vaultUnlockType: VaultUnlockType = VaultUnlockType.MASTER_PASSWORD,

View File

@@ -58,21 +58,22 @@ fun UserStateJson.toUserState(
.accounts
.values
.map { accountJson ->
val userId = accountJson.profile.userId
val profile = accountJson.profile
val userId = profile.userId
val vaultUnlocked = vaultState.statusFor(userId) == VaultUnlockData.Status.UNLOCKED
val needsPasswordReset = accountJson.profile.forcePasswordResetReason != null
val needsPasswordReset = profile.forcePasswordResetReason != null
val needsMasterPassword = profile.userDecryptionOptions?.hasMasterPassword == false
UserState.Account(
userId = accountJson.profile.userId,
name = accountJson.profile.name,
email = accountJson.profile.email,
avatarColorHex = accountJson.profile.avatarColorHex
?: accountJson.profile.userId.toHexColorRepresentation(),
userId = userId,
name = profile.name,
email = profile.email,
avatarColorHex = profile.avatarColorHex ?: userId.toHexColorRepresentation(),
environment = accountJson
.settings
.environmentUrlData
.toEnvironmentUrlsOrDefault(),
isPremium = accountJson.profile.hasPremium == true,
isPremium = profile.hasPremium == true,
isLoggedIn = isLoggedInProvider(userId),
isVaultUnlocked = vaultUnlocked && !needsPasswordReset,
needsPasswordReset = needsPasswordReset,
@@ -82,6 +83,7 @@ fun UserStateJson.toUserState(
.orEmpty(),
isBiometricsEnabled = isBiometricsEnabledProvider(userId),
vaultUnlockType = vaultUnlockTypeProvider(userId),
needsMasterPassword = needsMasterPassword,
)
},
hasPendingAccountAddition = hasPendingAccountAddition,