Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use entered email for old flow when new is not supported [WPB-16058] #3905

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import com.wire.android.navigation.startDestination
import com.wire.android.navigation.style.BackgroundStyle
import com.wire.android.navigation.style.BackgroundType
import com.wire.android.ui.authentication.login.LoginPasswordPath
import com.wire.android.ui.authentication.login.PreFilledUserIdentifierType
import com.wire.android.ui.authentication.login.WireAuthBackgroundLayout
import com.wire.android.ui.calling.getIncomingCallIntent
import com.wire.android.ui.calling.getOutgoingCallIntent
Expand Down Expand Up @@ -769,8 +770,8 @@ class WireActivity : AppCompatActivity() {
navigate(
NavigationCommand(
when (loginTypeSelector.canUseNewLogin()) {
true -> NewLoginScreenDestination(userHandle = it.userHandle)
false -> LoginScreenDestination(userHandle = it.userHandle)
true -> NewLoginScreenDestination(userHandle = PreFilledUserIdentifierType.PreFilled(it.userHandle))
false -> LoginScreenDestination(userHandle = PreFilledUserIdentifierType.PreFilled(it.userHandle))
},
// if "welcome empty start" screen then switch "start" screen to proper one
when (navigator.shouldReplaceWelcomeLoginStartDestination()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,26 @@ import com.wire.android.util.deeplink.DeepLinkResult
import com.wire.kalium.logic.configuration.server.ServerConfig
import kotlinx.serialization.Serializable

@Serializable
data class LoginNavArgs(
val userHandle: String? = null,
val userHandle: PreFilledUserIdentifierType.PreFilled? = null,
val ssoLoginResult: DeepLinkResult.SSOLogin? = null,
val loginPasswordPath: LoginPasswordPath? = null,
)

@Serializable
sealed interface PreFilledUserIdentifierType {
@Serializable
data object None : PreFilledUserIdentifierType
@Serializable
data class PreFilled(val userIdentifier: String, val editable: Boolean = false) : PreFilledUserIdentifierType

val userIdentifierEditable: Boolean get() = when (this) {
is PreFilled -> this.editable
is None -> true
}
}

@Serializable
data class LoginPasswordPath(
val customServerConfig: ServerConfig.Links? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,5 @@ fun AddAuthenticatedUserUseCase.Result.Failure.toLoginError(): LoginState.Error
AddAuthenticatedUserUseCase.Result.Failure.UserAlreadyExists -> LoginState.Error.DialogError.UserAlreadyExists
}

sealed interface PreFilledUserIdentifierType {
data object None : PreFilledUserIdentifierType
data class PreFilled(val userIdentifier: String) : PreFilledUserIdentifierType
}

val ServerConfig.Links.isProxyEnabled get() = this.apiProxy != null
val ServerConfig.Links.isProxyAuthRequired get() = apiProxy?.needsAuthentication ?: false
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@ class LoginEmailViewModel @Inject constructor(
coreLogic
) {
val loginNavArgs: LoginNavArgs = savedStateHandle.navArgs()
private val preFilledUserIdentifier: PreFilledUserIdentifierType = loginNavArgs.userHandle.let {
if (it.isNullOrEmpty()) PreFilledUserIdentifierType.None else PreFilledUserIdentifierType.PreFilled(it)
}
private val preFilledUserIdentifier: PreFilledUserIdentifierType = loginNavArgs.userHandle ?: PreFilledUserIdentifierType.None

val userIdentifierTextState: TextFieldState = TextFieldState()
val passwordTextState: TextFieldState = TextFieldState()
val proxyIdentifierTextState: TextFieldState = TextFieldState()
val proxyPasswordTextState: TextFieldState = TextFieldState()
var loginState by mutableStateOf(LoginEmailState(preFilledUserIdentifier is PreFilledUserIdentifierType.None))
var loginState by mutableStateOf(LoginEmailState(preFilledUserIdentifier.userIdentifierEditable))

val secondFactorVerificationCodeTextState: TextFieldState = TextFieldState()
var secondFactorVerificationCodeState by mutableStateOf(VerificationCodeState())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.wire.android.navigation.LoginTypeSelector
import com.wire.android.navigation.NavigationCommand
import com.wire.android.navigation.Navigator
import com.wire.android.navigation.WireDestination
import com.wire.android.ui.authentication.login.PreFilledUserIdentifierType
import com.wire.android.ui.common.SettingUpWireScreenContent
import com.wire.android.ui.common.SettingUpWireScreenType
import com.wire.android.ui.destinations.HomeScreenDestination
Expand All @@ -62,8 +63,10 @@ fun MigrationScreen(
is MigrationState.LoginRequired -> navigator.navigate(
NavigationCommand(
when {
loginTypeSelector.canUseNewLogin() -> NewLoginScreenDestination(userHandle = state.userHandle)
else -> LoginScreenDestination(userHandle = state.userHandle)
loginTypeSelector.canUseNewLogin() ->
NewLoginScreenDestination(userHandle = PreFilledUserIdentifierType.PreFilled(state.userHandle))
else ->
LoginScreenDestination(userHandle = PreFilledUserIdentifierType.PreFilled(state.userHandle))
},
BackStackMode.CLEAR_WHOLE
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.wire.android.ui.authentication.login.sso.SSOUrlConfig
import com.wire.kalium.logic.configuration.server.ServerConfig

sealed interface NewLoginAction {
data object EnterpriseLoginNotSupported : NewLoginAction
data class EnterpriseLoginNotSupported(val userIdentifier: String) : NewLoginAction
data class EmailPassword(val userIdentifier: String, val loginPasswordPath: LoginPasswordPath) : NewLoginAction
data class CustomConfig(val userIdentifier: String, val customServerConfig: ServerConfig.Links) : NewLoginAction
data class SSO(val url: String, val config: SSOUrlConfig) : NewLoginAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import com.wire.android.ui.authentication.login.LoginErrorDialog
import com.wire.android.ui.authentication.login.LoginNavArgs
import com.wire.android.ui.authentication.login.LoginPasswordPath
import com.wire.android.ui.authentication.login.NewLoginNavGraph
import com.wire.android.ui.authentication.login.PreFilledUserIdentifierType
import com.wire.android.ui.authentication.login.WireAuthBackgroundLayout
import com.wire.android.ui.authentication.login.sso.SSOUrlConfigHolder
import com.wire.android.ui.authentication.login.toLoginDialogErrorData
Expand All @@ -76,6 +77,7 @@ import com.wire.android.ui.common.typography
import com.wire.android.ui.destinations.E2EIEnrollmentScreenDestination
import com.wire.android.ui.destinations.HomeScreenDestination
import com.wire.android.ui.destinations.InitialSyncScreenDestination
import com.wire.android.ui.destinations.LoginScreenDestination
import com.wire.android.ui.destinations.NewLoginPasswordScreenDestination
import com.wire.android.ui.destinations.NewLoginScreenDestination
import com.wire.android.ui.destinations.RemoveDeviceScreenDestination
Expand Down Expand Up @@ -103,15 +105,15 @@ fun NewLoginScreen(
when (newLoginAction) {
is NewLoginAction.EmailPassword -> {
val loginNavArgs = LoginNavArgs(
userHandle = newLoginAction.userIdentifier,
userHandle = PreFilledUserIdentifierType.PreFilled(newLoginAction.userIdentifier),
loginPasswordPath = newLoginAction.loginPasswordPath
)
navigator.navigate(NavigationCommand(NewLoginPasswordScreenDestination(loginNavArgs)))
}

is NewLoginAction.CustomConfig -> {
val loginNavArgs = LoginNavArgs(
userHandle = newLoginAction.userIdentifier,
userHandle = PreFilledUserIdentifierType.PreFilled(newLoginAction.userIdentifier),
loginPasswordPath = LoginPasswordPath(customServerConfig = newLoginAction.customServerConfig)
)
navigator.navigate(NavigationCommand(NewLoginScreenDestination(loginNavArgs), BackStackMode.CLEAR_WHOLE))
Expand All @@ -134,7 +136,12 @@ fun NewLoginScreen(
}

is NewLoginAction.EnterpriseLoginNotSupported -> {
navigator.navigate(NavigationCommand(WelcomeScreenDestination(viewModel.serverConfig)))
navigator.navigate(NavigationCommand(WelcomeScreenDestination(viewModel.serverConfig), BackStackMode.CLEAR_WHOLE))
val loginNavArgs = LoginNavArgs(
userHandle = PreFilledUserIdentifierType.PreFilled(userIdentifier = newLoginAction.userIdentifier, editable = true),
loginPasswordPath = LoginPasswordPath(viewModel.serverConfig),
)
navigator.navigate(NavigationCommand(LoginScreenDestination(loginNavArgs)))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ class NewLoginViewModel(
)

private val loginNavArgs: LoginNavArgs = savedStateHandle.navArgs()
private val preFilledUserIdentifier: PreFilledUserIdentifierType = loginNavArgs.userHandle.let {
if (it.isNullOrEmpty()) PreFilledUserIdentifierType.None else PreFilledUserIdentifierType.PreFilled(it)
}
private val preFilledUserIdentifier: PreFilledUserIdentifierType = loginNavArgs.userHandle ?: PreFilledUserIdentifierType.None
var serverConfig: ServerConfig.Links by mutableStateOf(loginNavArgs.loginPasswordPath?.customServerConfig.orDefault())
private set

Expand Down Expand Up @@ -163,7 +161,8 @@ class NewLoginViewModel(
}

is EnterpriseLoginResult.Failure.NotSupported -> withContext(dispatchers.main()) {
action(NewLoginAction.EnterpriseLoginNotSupported)
action(NewLoginAction.EnterpriseLoginNotSupported(email))
updateLoginFlowState(NewLoginFlowState.Default)
}

is EnterpriseLoginResult.Success -> {
Expand Down Expand Up @@ -250,6 +249,7 @@ class NewLoginViewModel(
withContext(dispatchers.main()) {
updateLoginFlowState(NewLoginFlowState.Default)
action(NewLoginAction.SSO(requestUrl, SSOUrlConfig(serverConfig, ssoCode)))
updateLoginFlowState(NewLoginFlowState.Default)
}
}
)
Expand All @@ -275,16 +275,23 @@ class NewLoginViewModel(
loginExtension.registerClient(storedUserId, null).let { result ->
withContext(dispatchers.main()) {
when (result) {
is RegisterClientResult.Success -> when (loginExtension.isInitialSyncCompleted(storedUserId)) {
true -> action(NewLoginAction.Success(NewLoginAction.Success.NextStep.None))
false -> action(NewLoginAction.Success(NewLoginAction.Success.NextStep.InitialSync))
is RegisterClientResult.Success -> {
when (loginExtension.isInitialSyncCompleted(storedUserId)) {
true -> action(NewLoginAction.Success(NewLoginAction.Success.NextStep.None))
false -> action(NewLoginAction.Success(NewLoginAction.Success.NextStep.InitialSync))
}
updateLoginFlowState(NewLoginFlowState.Default)
}

is RegisterClientResult.E2EICertificateRequired ->
is RegisterClientResult.E2EICertificateRequired -> {
action(NewLoginAction.Success(NewLoginAction.Success.NextStep.E2EIEnrollment))
updateLoginFlowState(NewLoginFlowState.Default)
}

is RegisterClientResult.Failure.TooManyClients ->
is RegisterClientResult.Failure.TooManyClients -> {
action(NewLoginAction.Success(NewLoginAction.Success.NextStep.TooManyDevices))
updateLoginFlowState(NewLoginFlowState.Default)
}

is RegisterClientResult.Failure.Generic ->
updateLoginFlowState(NewLoginFlowState.Error.DialogError.GenericError(result.genericFailure))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.wire.android.ui.authentication.login.LoginErrorDialog
import com.wire.android.ui.authentication.login.LoginNavArgs
import com.wire.android.ui.authentication.login.LoginState
import com.wire.android.ui.authentication.login.NewLoginNavGraph
import com.wire.android.ui.authentication.login.PreFilledUserIdentifierType
import com.wire.android.ui.authentication.login.WireAuthBackgroundLayout
import com.wire.android.ui.authentication.login.email.ForgotPasswordLabel
import com.wire.android.ui.authentication.login.email.LoginButton
Expand Down Expand Up @@ -104,7 +105,7 @@ fun NewLoginPasswordScreen(
if (loginEmailViewModel.secondFactorVerificationCodeState.isCodeInputNecessary) {
val verificationCodeNavArgs = LoginNavArgs(
loginPasswordPath = navArgs.loginPasswordPath,
userHandle = loginEmailViewModel.userIdentifierTextState.text.toString()
userHandle = PreFilledUserIdentifierType.PreFilled(loginEmailViewModel.userIdentifierTextState.text.toString())
)
navigator.navigate(NavigationCommand(NewLoginVerificationCodeScreenDestination(verificationCodeNavArgs)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ class NewLoginViewModelTest {
fun `given not supported failure, when enterprise login, then call EnterpriseLoginNotSupported action`() =
testEnterpriseLoginActions(
result = EnterpriseLoginResult.Failure.NotSupported,
expected = NewLoginAction.EnterpriseLoginNotSupported,
expected = NewLoginAction.EnterpriseLoginNotSupported(email),
)

@Test
Expand Down