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: bring back current login flow and add a feature flag for enterprise login [WPB-15543] #3817

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

package com.wire.android.feature

import com.wire.android.BuildConfig
import com.wire.android.appLogger
import com.wire.android.di.ApplicationScope
import com.wire.android.di.AuthServerConfigProvider
import com.wire.android.navigation.BackStackMode
import com.wire.android.navigation.NavigationCommand
import com.wire.android.ui.destinations.HomeScreenDestination
import com.wire.android.ui.destinations.NewWelcomeScreenDestination
import com.wire.android.ui.destinations.WelcomeScreenDestination
import com.wire.kalium.logic.data.auth.AccountInfo
import com.wire.kalium.logic.data.logout.LogoutReason
Expand Down Expand Up @@ -212,5 +214,10 @@ interface SwitchAccountActions {

class NavigationSwitchAccountActions(val navigate: (NavigationCommand) -> Unit) : SwitchAccountActions {
override fun switchedToAnotherAccount() = navigate(NavigationCommand(HomeScreenDestination, BackStackMode.CLEAR_WHOLE))
override fun noOtherAccountToSwitch() = navigate(NavigationCommand(WelcomeScreenDestination, BackStackMode.CLEAR_WHOLE))
override fun noOtherAccountToSwitch() = navigate(
NavigationCommand(
if (BuildConfig.ENTERPRISE_LOGIN_ENABLED) NewWelcomeScreenDestination else WelcomeScreenDestination,
BackStackMode.CLEAR_WHOLE
)
)
}
29 changes: 24 additions & 5 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import com.wire.android.navigation.Navigator
import com.wire.android.navigation.rememberNavigator
import com.wire.android.navigation.style.BackgroundStyle
import com.wire.android.navigation.style.BackgroundType
import com.wire.android.ui.authentication.login.LoginNavArgs
import com.wire.android.ui.authentication.login.WireAuthBackgroundLayout
import com.wire.android.ui.calling.getIncomingCallIntent
import com.wire.android.ui.calling.getOutgoingCallIntent
Expand All @@ -92,6 +91,8 @@ import com.wire.android.ui.destinations.HomeScreenDestination
import com.wire.android.ui.destinations.ImportMediaScreenDestination
import com.wire.android.ui.destinations.LoginScreenDestination
import com.wire.android.ui.destinations.MigrationScreenDestination
import com.wire.android.ui.destinations.NewLoginScreenDestination
import com.wire.android.ui.destinations.NewWelcomeScreenDestination
import com.wire.android.ui.destinations.OtherUserProfileScreenDestination
import com.wire.android.ui.destinations.SelfDevicesScreenDestination
import com.wire.android.ui.destinations.SelfUserProfileScreenDestination
Expand Down Expand Up @@ -184,7 +185,10 @@ class WireActivity : AppCompatActivity() {
appLogger.i("$TAG start destination")
val startDestination = when (viewModel.initialAppState()) {
InitialAppState.NOT_MIGRATED -> MigrationScreenDestination
InitialAppState.NOT_LOGGED_IN -> WelcomeScreenDestination
InitialAppState.NOT_LOGGED_IN -> when {
BuildConfig.ENTERPRISE_LOGIN_ENABLED -> NewWelcomeScreenDestination
else -> WelcomeScreenDestination
}
InitialAppState.ENROLL_E2EI -> E2EIEnrollmentScreenDestination
InitialAppState.LOGGED_IN -> HomeScreenDestination
}
Expand Down Expand Up @@ -541,7 +545,12 @@ class WireActivity : AppCompatActivity() {
viewModel::dismissCustomBackendDialog,
onConfirm = {
viewModel.customBackendDialogProceedButtonClicked {
navigate(NavigationCommand(LoginScreenDestination(LoginNavArgs())))
navigate(
NavigationCommand(
if (BuildConfig.ENTERPRISE_LOGIN_ENABLED) NewWelcomeScreenDestination else WelcomeScreenDestination,
BackStackMode.UPDATE_EXISTED
)
)
}
},
onTryAgain = viewModel::onCustomServerConfig
Expand Down Expand Up @@ -650,6 +659,10 @@ class WireActivity : AppCompatActivity() {
}

@Suppress("ComplexCondition", "LongMethod")
/*
* This method is responsible for handling deep links from given intent
* @return true if there was any deep link in given intent to handle, false otherwise
*/
private fun handleDeepLink(
intent: Intent?,
savedInstanceState: Bundle? = null
Expand Down Expand Up @@ -711,7 +724,10 @@ class WireActivity : AppCompatActivity() {
onMigrationLogin = {
navigate(
NavigationCommand(
LoginScreenDestination(it.userHandle),
when {
BuildConfig.ENTERPRISE_LOGIN_ENABLED -> NewLoginScreenDestination(userHandle = it.userHandle)
else -> LoginScreenDestination(userHandle = it.userHandle)
},
BackStackMode.UPDATE_EXISTED
)
)
Expand All @@ -735,7 +751,10 @@ class WireActivity : AppCompatActivity() {
onSSOLogin = {
navigate(
NavigationCommand(
LoginScreenDestination(ssoLoginResult = it),
when {
BuildConfig.ENTERPRISE_LOGIN_ENABLED -> NewLoginScreenDestination(ssoLoginResult = it)
else -> LoginScreenDestination(ssoLoginResult = it)
},
BackStackMode.UPDATE_EXISTED
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* Wire
* Copyright (C) 2025 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.ui.authentication.login

import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.window.DialogProperties
import com.wire.android.R
import com.wire.android.ui.common.WireDialog
import com.wire.android.ui.common.WireDialogButtonProperties
import com.wire.android.ui.common.WireDialogButtonType
import com.wire.android.util.deeplink.DeepLinkResult
import com.wire.android.util.dialogErrorStrings

@Composable
fun LoginErrorDialog(
error: LoginState.Error,
onDialogDismiss: () -> Unit,
updateTheApp: () -> Unit,
ssoLoginResult: DeepLinkResult.SSOLogin? = null
) {
val dialogErrorData: LoginDialogErrorData = when (error) {
is LoginState.Error.DialogError.InvalidCredentialsError -> LoginDialogErrorData(
title = stringResource(R.string.login_error_invalid_credentials_title),
body = AnnotatedString(stringResource(R.string.login_error_invalid_credentials_message)),
onDismiss = onDialogDismiss
)

is LoginState.Error.DialogError.UserAlreadyExists -> LoginDialogErrorData(
title = stringResource(R.string.login_error_user_already_logged_in_title),
body = AnnotatedString(stringResource(R.string.login_error_user_already_logged_in_message)),
onDismiss = onDialogDismiss
)

is LoginState.Error.DialogError.ProxyError -> {
LoginDialogErrorData(
title = stringResource(R.string.error_socket_title),
body = AnnotatedString(stringResource(R.string.error_socket_message)),
onDismiss = onDialogDismiss
)
}

is LoginState.Error.DialogError.GenericError -> {
val strings = error.coreFailure.dialogErrorStrings(LocalContext.current.resources)
LoginDialogErrorData(
strings.title,
strings.annotatedMessage,
onDialogDismiss
)
}

is LoginState.Error.DialogError.InvalidSSOCodeError -> LoginDialogErrorData(
title = stringResource(R.string.login_error_invalid_credentials_title),
body = AnnotatedString(stringResource(R.string.login_error_invalid_sso_code)),
onDismiss = onDialogDismiss
)

is LoginState.Error.DialogError.InvalidSSOCookie -> LoginDialogErrorData(
title = stringResource(R.string.login_sso_error_invalid_cookie_title),
body = AnnotatedString(stringResource(R.string.login_sso_error_invalid_cookie_message)),
onDismiss = onDialogDismiss
)

is LoginState.Error.DialogError.SSOResultError -> {
with(ssoLoginResult as DeepLinkResult.SSOLogin.Failure) {
LoginDialogErrorData(
title = stringResource(R.string.sso_error_dialog_title),
body = AnnotatedString(stringResource(R.string.sso_error_dialog_message, this.ssoError.errorCode)),
onDismiss = onDialogDismiss
)
}
}

is LoginState.Error.DialogError.ServerVersionNotSupported -> LoginDialogErrorData(
title = stringResource(R.string.api_versioning_server_version_not_supported_title),
body = AnnotatedString(stringResource(R.string.api_versioning_server_version_not_supported_message)),
onDismiss = onDialogDismiss,
actionTextId = R.string.label_close,
dismissOnClickOutside = false
)

is LoginState.Error.DialogError.ClientUpdateRequired -> LoginDialogErrorData(
title = stringResource(R.string.api_versioning_client_update_required_title),
body = AnnotatedString(stringResource(R.string.api_versioning_client_update_required_message)),
onDismiss = onDialogDismiss,
actionTextId = R.string.label_update,
onAction = updateTheApp,
dismissOnClickOutside = false
)

LoginState.Error.DialogError.Request2FAWithHandle -> {
LoginDialogErrorData(
title = stringResource(R.string.login_error_request_2fa_with_handle_title),
body = AnnotatedString(stringResource(R.string.login_error_request_2fa_with_handle_message)),
onDismiss = onDialogDismiss
)
}

LoginState.Error.TextFieldError.InvalidValue,
LoginState.Error.DialogError.PasswordNeededToRegisterClient,
LoginState.Error.TooManyDevicesError -> {
LoginDialogErrorData(
title = stringResource(R.string.error_unknown_title),
body = AnnotatedString(stringResource(R.string.error_unknown_message)),
onDismiss = onDialogDismiss
)
}
}

WireDialog(
title = dialogErrorData.title,
text = dialogErrorData.body,
onDismiss = dialogErrorData.onDismiss,
optionButton1Properties = WireDialogButtonProperties(
text = stringResource(dialogErrorData.actionTextId),
onClick = dialogErrorData.onAction,
type = WireDialogButtonType.Primary
),
properties = DialogProperties(
dismissOnBackPress = true,
dismissOnClickOutside = dialogErrorData.dismissOnClickOutside,
usePlatformDefaultWidth = false
)
)
}

data class LoginDialogErrorData(
val title: String,
val body: AnnotatedString,
val onDismiss: () -> Unit,
@StringRes val actionTextId: Int = R.string.label_ok,
val onAction: () -> Unit = onDismiss,
val dismissOnClickOutside: Boolean = true
)
Loading
Loading