Skip to content

Commit 4d9a19f

Browse files
PM-19645: Remove the new device UI email access flow (#4996)
1 parent dda8237 commit 4d9a19f

28 files changed

+1
-2543
lines changed

app/src/main/java/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSource.kt

-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.x8bit.bitwarden.data.auth.datasource.disk
22

33
import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountTokensJson
4-
import com.x8bit.bitwarden.data.auth.datasource.disk.model.NewDeviceNoticeState
54
import com.x8bit.bitwarden.data.auth.datasource.disk.model.OnboardingStatus
65
import com.x8bit.bitwarden.data.auth.datasource.disk.model.PendingAuthRequestJson
76
import com.x8bit.bitwarden.data.auth.datasource.disk.model.UserStateJson
@@ -344,16 +343,6 @@ interface AuthDiskSource {
344343
*/
345344
fun getShowImportLoginsFlow(userId: String): Flow<Boolean?>
346345

347-
/**
348-
* Gets the new device notice state for the given [userId].
349-
*/
350-
fun getNewDeviceNoticeState(userId: String): NewDeviceNoticeState
351-
352-
/**
353-
* Stores the new device notice state for the given [userId].
354-
*/
355-
fun storeNewDeviceNoticeState(userId: String, newState: NewDeviceNoticeState?)
356-
357346
/**
358347
* Gets the last lock timestamp for the given [userId].
359348
*/

app/src/main/java/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceImpl.kt

-19
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import com.bitwarden.core.data.repository.util.bufferedMutableSharedFlow
55
import com.bitwarden.core.data.util.decodeFromStringOrNull
66
import com.bitwarden.data.datasource.disk.BaseEncryptedDiskSource
77
import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountTokensJson
8-
import com.x8bit.bitwarden.data.auth.datasource.disk.model.NewDeviceNoticeDisplayStatus
9-
import com.x8bit.bitwarden.data.auth.datasource.disk.model.NewDeviceNoticeState
108
import com.x8bit.bitwarden.data.auth.datasource.disk.model.OnboardingStatus
119
import com.x8bit.bitwarden.data.auth.datasource.disk.model.PendingAuthRequestJson
1210
import com.x8bit.bitwarden.data.auth.datasource.disk.model.UserStateJson
@@ -49,7 +47,6 @@ private const val TDE_LOGIN_COMPLETE = "tdeLoginComplete"
4947
private const val USES_KEY_CONNECTOR = "usesKeyConnector"
5048
private const val ONBOARDING_STATUS_KEY = "onboardingStatus"
5149
private const val SHOW_IMPORT_LOGINS_KEY = "showImportLogins"
52-
private const val NEW_DEVICE_NOTICE_STATE = "newDeviceNoticeState"
5350
private const val LAST_LOCK_TIMESTAMP = "lastLockTimestamp"
5451

5552
/**
@@ -489,22 +486,6 @@ class AuthDiskSourceImpl(
489486
getMutableShowImportLoginsFlow(userId)
490487
.onSubscription { emit(getShowImportLogins(userId)) }
491488

492-
override fun getNewDeviceNoticeState(userId: String): NewDeviceNoticeState {
493-
return getString(key = NEW_DEVICE_NOTICE_STATE.appendIdentifier(userId))?.let {
494-
json.decodeFromStringOrNull(it)
495-
} ?: NewDeviceNoticeState(
496-
displayStatus = NewDeviceNoticeDisplayStatus.HAS_NOT_SEEN,
497-
lastSeenDate = null,
498-
)
499-
}
500-
501-
override fun storeNewDeviceNoticeState(userId: String, newState: NewDeviceNoticeState?) {
502-
putString(
503-
key = NEW_DEVICE_NOTICE_STATE.appendIdentifier(userId),
504-
value = newState?.let { json.encodeToString(it) },
505-
)
506-
}
507-
508489
override fun getLastLockTimestamp(userId: String): Instant? {
509490
return getLong(key = LAST_LOCK_TIMESTAMP.appendIdentifier(userId))?.let {
510491
Instant.ofEpochMilli(it)

app/src/main/java/com/x8bit/bitwarden/data/auth/datasource/disk/model/NewDeviceNoticeDisplayStatus.kt

-60
This file was deleted.

app/src/main/java/com/x8bit/bitwarden/data/auth/repository/AuthRepository.kt

-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.x8bit.bitwarden.data.auth.repository
22

33
import com.x8bit.bitwarden.data.auth.datasource.disk.model.ForcePasswordResetReason
4-
import com.x8bit.bitwarden.data.auth.datasource.disk.model.NewDeviceNoticeState
54
import com.x8bit.bitwarden.data.auth.datasource.disk.model.OnboardingStatus
65
import com.x8bit.bitwarden.data.auth.datasource.network.model.GetTokenResponseJson
76
import com.x8bit.bitwarden.data.auth.datasource.network.model.TwoFactorDataModel
@@ -423,19 +422,4 @@ interface AuthRepository : AuthenticatorProvider, AuthRequestManager {
423422
* Update the value of the onboarding status for the user.
424423
*/
425424
fun setOnboardingStatus(status: OnboardingStatus)
426-
427-
/**
428-
* Checks if a new device notice should be displayed.
429-
*/
430-
fun checkUserNeedsNewDeviceTwoFactorNotice(): Boolean
431-
432-
/**
433-
* Gets the new device notice state of active user.
434-
*/
435-
fun getNewDeviceNoticeState(): NewDeviceNoticeState?
436-
437-
/**
438-
* Stores the new device notice state for active user.
439-
*/
440-
fun setNewDeviceNoticeState(newState: NewDeviceNoticeState?)
441425
}

app/src/main/java/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryImpl.kt

-84
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
1919
import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountJson
2020
import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountTokensJson
2121
import com.x8bit.bitwarden.data.auth.datasource.disk.model.ForcePasswordResetReason
22-
import com.x8bit.bitwarden.data.auth.datasource.disk.model.NewDeviceNoticeDisplayStatus
23-
import com.x8bit.bitwarden.data.auth.datasource.disk.model.NewDeviceNoticeState
2422
import com.x8bit.bitwarden.data.auth.datasource.disk.model.OnboardingStatus
2523
import com.x8bit.bitwarden.data.auth.datasource.disk.model.UserStateJson
2624
import com.x8bit.bitwarden.data.auth.datasource.network.model.DeleteAccountResponseJson
@@ -117,7 +115,6 @@ import com.x8bit.bitwarden.data.platform.manager.model.FlagKey
117115
import com.x8bit.bitwarden.data.platform.manager.util.getActivePolicies
118116
import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository
119117
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
120-
import com.x8bit.bitwarden.data.platform.repository.model.Environment
121118
import com.x8bit.bitwarden.data.platform.repository.util.toEnvironmentUrls
122119
import com.x8bit.bitwarden.data.vault.datasource.network.model.OrganizationType
123120
import com.x8bit.bitwarden.data.vault.datasource.network.model.PolicyTypeJson
@@ -149,7 +146,6 @@ import kotlinx.coroutines.flow.onEach
149146
import kotlinx.coroutines.flow.receiveAsFlow
150147
import kotlinx.coroutines.flow.stateIn
151148
import kotlinx.coroutines.flow.update
152-
import java.time.ZonedDateTime
153149
import javax.inject.Singleton
154150

155151
/**
@@ -1408,86 +1404,6 @@ class AuthRepositoryImpl(
14081404
}
14091405
}
14101406

1411-
override fun getNewDeviceNoticeState(): NewDeviceNoticeState? {
1412-
return activeUserId?.let { userId ->
1413-
authDiskSource.getNewDeviceNoticeState(userId = userId)
1414-
}
1415-
}
1416-
1417-
override fun setNewDeviceNoticeState(newState: NewDeviceNoticeState?) {
1418-
activeUserId?.let { userId ->
1419-
authDiskSource.storeNewDeviceNoticeState(userId = userId, newState = newState)
1420-
}
1421-
}
1422-
1423-
override fun checkUserNeedsNewDeviceTwoFactorNotice(): Boolean {
1424-
return activeUserId
1425-
?.let { userId ->
1426-
if (!newDeviceNoticePreConditionsValid()) {
1427-
return false
1428-
}
1429-
1430-
val newDeviceNoticeState = authDiskSource.getNewDeviceNoticeState(userId = userId)
1431-
return when (newDeviceNoticeState.displayStatus) {
1432-
// if the user has already attested email access but permanent flag is enabled,
1433-
// the notice needs to appear again
1434-
NewDeviceNoticeDisplayStatus.CAN_ACCESS_EMAIL -> true
1435-
// if the user has already seen but 7 days have already passed,
1436-
// the notice needs to appear again
1437-
NewDeviceNoticeDisplayStatus.HAS_SEEN -> {
1438-
newDeviceNoticeState.shouldDisplayNoticeIfSeen
1439-
}
1440-
1441-
NewDeviceNoticeDisplayStatus.HAS_NOT_SEEN -> true
1442-
// the user never needs to see the notice again
1443-
NewDeviceNoticeDisplayStatus.CAN_ACCESS_EMAIL_PERMANENT -> false
1444-
}
1445-
}
1446-
?: false
1447-
}
1448-
1449-
/**
1450-
* Checks if the preconditions are met for a user to see a new device notice:
1451-
* - Must be a Bitwarden cloud user.
1452-
* - The account must be at least one week old.
1453-
* - Cannot have an active policy requiring SSO to be enabled.
1454-
* - Cannot have two-factor authentication enabled.
1455-
*/
1456-
private fun newDeviceNoticePreConditionsValid(): Boolean {
1457-
val checkEnvironment = !featureFlagManager.getFeatureFlag(FlagKey.IgnoreEnvironmentCheck)
1458-
val isSelfHosted = environmentRepository.environment.type == Environment.Type.SELF_HOSTED
1459-
if (checkEnvironment && isSelfHosted) {
1460-
return false
1461-
}
1462-
1463-
val userProfile = authDiskSource.userState?.activeAccount?.profile
1464-
val isProfileAtLeastWeekOld = userProfile
1465-
?.let {
1466-
it.creationDate
1467-
?.plusWeeks(1)
1468-
?.isBefore(
1469-
ZonedDateTime.now(),
1470-
)
1471-
}
1472-
?: false
1473-
if (!isProfileAtLeastWeekOld) {
1474-
return false
1475-
}
1476-
1477-
val hasTwoFactorEnabled = userProfile
1478-
?.isTwoFactorEnabled
1479-
?: false
1480-
if (hasTwoFactorEnabled) {
1481-
return false
1482-
}
1483-
1484-
val hasSSOPolicy =
1485-
policyManager.getActivePolicies(type = PolicyTypeJson.REQUIRE_SSO)
1486-
.any { p -> p.isEnabled }
1487-
1488-
return !hasSSOPolicy
1489-
}
1490-
14911407
@Suppress("CyclomaticComplexMethod")
14921408
private suspend fun validatePasswordAgainstPolicy(
14931409
password: String,

app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/newdevicenotice/NewDeviceNoticeEmailAccessNavigation.kt

-58
This file was deleted.

0 commit comments

Comments
 (0)