Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4af61650 authored by Arnau Mora's avatar Arnau Mora Committed by Ricki Hirner
Browse files

Backport login_credentials_lock for password change in account settings (bitfireAT/davx5#643)



---------

Signed-off-by: default avatarArnau Mora <arnyminerz@proton.me>
parent fb202376
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import java.util.Collections
import java.util.logging.Level
import java.util.logging.Logger
import javax.inject.Provider
import kotlin.collections.mutableSetOf

/**
 * Manages settings of an account.
@@ -128,6 +127,15 @@ class AccountSettings @AssistedInject constructor(
        accountManager.setAndVerifyUserData(account, KEY_AUTH_STATE, credentials.authState?.jsonSerializeString())
    }

    /**
     * Returns whether users can modify credentials from the account settings screen.
     * Checks the value of [CREDENTIALS_LOCK] to be `0` or not equal to [CREDENTIALS_LOCK_AT_LOGIN_AND_SETTINGS].
     */
    fun changingCredentialsAllowed(): Boolean {
        val credentialsLock = settingsManager.getIntOrNull(CREDENTIALS_LOCK)
        return credentialsLock == null || credentialsLock != CREDENTIALS_LOCK_AT_LOGIN_AND_SETTINGS
    }


    // sync. settings

@@ -368,6 +376,11 @@ class AccountSettings @AssistedInject constructor(
        const val KEY_USERNAME = "user_name"
        const val KEY_CERTIFICATE_ALIAS = "certificate_alias"

        const val CREDENTIALS_LOCK = "login_credentials_lock"
        const val CREDENTIALS_LOCK_NO_LOCK = 0
        const val CREDENTIALS_LOCK_AT_LOGIN = 1
        const val CREDENTIALS_LOCK_AT_LOGIN_AND_SETTINGS = 2

        /** OAuth [AuthState] (serialized as JSON) */
        const val KEY_AUTH_STATE = "auth_state"

+2 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ class AccountSettingsModel @AssistedInject constructor(
        val ignoreVpns: Boolean = false,

        val credentials: Credentials = Credentials(),
        val allowCredentialsChange: Boolean = true,

        val timeRangePastDays: Int? = null,
        val defaultAlarmMinBefore: Int? = null,
@@ -119,6 +120,7 @@ class AccountSettingsModel @AssistedInject constructor(
            ignoreVpns = accountSettings.getIgnoreVpns(),

            credentials = accountSettings.credentials(),
            allowCredentialsChange = accountSettings.changingCredentialsAllowed(),

            timeRangePastDays = accountSettings.getTimeRangePastDays(),
            defaultAlarmMinBefore = accountSettings.getDefaultAlarm(),
+10 −0
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ fun AccountSettingsScreen(
            // Authentication Settings
            credentials = uiState.credentials,
            onUpdateCredentials = model::updateCredentials,
            isCredentialsUpdateAllowed = uiState.allowCredentialsChange,

            // CalDav Settings
            timeRangePastDays = uiState.timeRangePastDays,
@@ -152,6 +153,7 @@ fun AccountSettingsScreen(
    // Authentication Settings
    credentials: Credentials?,
    onUpdateCredentials: (Credentials) -> Unit = {},
    isCredentialsUpdateAllowed: Boolean,

    // CalDav Settings
    timeRangePastDays: Int?,
@@ -227,6 +229,7 @@ fun AccountSettingsScreen(
                // Authentication Settings
                credentials = credentials,
                onUpdateCredentials = onUpdateCredentials,
                isCredentialsUpdateAllowed = isCredentialsUpdateAllowed,

                // CalDav Settings
                timeRangePastDays = timeRangePastDays,
@@ -272,6 +275,7 @@ fun AccountSettings_FromModel(
    // Authentication Settings
    credentials: Credentials?,
    onUpdateCredentials: (Credentials) -> Unit = {},
    isCredentialsUpdateAllowed: Boolean,

    // CalDav Settings
    timeRangePastDays: Int?,
@@ -312,6 +316,7 @@ fun AccountSettings_FromModel(
            AuthenticationSettings(
                snackbarHostState = snackbarHostState,
                credentials = credentials,
                isEnabled = isCredentialsUpdateAllowed,
                onUpdateCredentials = onUpdateCredentials
            )
        }
@@ -494,6 +499,7 @@ fun SyncIntervalSetting(
fun AuthenticationSettings(
    credentials: Credentials,
    snackbarHostState: SnackbarHostState = SnackbarHostState(),
    isEnabled: Boolean = true,
    onUpdateCredentials: (Credentials) -> Unit = {}
) {
    val context = LocalContext.current
@@ -511,6 +517,7 @@ fun AuthenticationSettings(
                    icon = Icons.Default.AccountCircle,
                    name = stringResource(R.string.settings_username),
                    summary = credentials.username,
                    enabled = isEnabled,
                    onClick = {
                        showUsernameDialog = true
                    }
@@ -530,6 +537,7 @@ fun AuthenticationSettings(
                    icon = Icons.Default.Password,
                    name = stringResource(R.string.settings_password),
                    summary = stringResource(R.string.settings_password_summary),
                    enabled = isEnabled,
                    onClick = {
                        showPasswordDialog = true
                    }
@@ -552,6 +560,7 @@ fun AuthenticationSettings(
                icon = null,
                name = stringResource(R.string.settings_certificate_alias),
                summary = credentials.certificateAlias ?: stringResource(R.string.settings_certificate_alias_empty),
                enabled = isEnabled,
                onClick = {
                    val activity = context as Activity
                    KeyChain.choosePrivateKeyAlias(activity, { newAlias ->
@@ -733,6 +742,7 @@ fun AccountSettingsScreen_Preview() {
            // Authentication Settings
            credentials = Credentials(username = "test", password = "test"),
            onUpdateCredentials = {},
            isCredentialsUpdateAllowed = true,

            // CalDav Settings
            timeRangePastDays = 365,