Don't show OAuth 2.0 option for POP3 accounts

This commit is contained in:
cketti 2023-07-03 17:16:00 +02:00
parent 0f6a50df73
commit 37ea82bd8f
4 changed files with 41 additions and 9 deletions

View file

@ -27,13 +27,6 @@ enum class AuthenticationType(
val DEFAULT = PasswordCleartext
fun all() = values().toList().toImmutableList()
fun incoming() = listOf(
PasswordCleartext,
PasswordEncrypted,
ClientCertificate,
OAuth2,
).toImmutableList()
fun outgoing() = all()
}
}

View file

@ -26,7 +26,6 @@ import app.k9mail.core.ui.compose.theme.K9Theme
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.ThunderbirdTheme
import app.k9mail.feature.account.setup.R
import app.k9mail.feature.account.setup.domain.entity.AuthenticationType
import app.k9mail.feature.account.setup.domain.entity.ConnectionSecurity
import app.k9mail.feature.account.setup.domain.entity.IncomingProtocolType
import app.k9mail.feature.account.setup.ui.common.item.ErrorItem
@ -136,7 +135,7 @@ internal fun AccountIncomingConfigContent(
item {
SelectInput(
options = AuthenticationType.incoming(),
options = state.allowedAuthenticationTypes,
optionToStringTransformation = { it.toResourceString(resources) },
selectedOption = state.authenticationType,
onOptionChange = { onEvent(Event.AuthenticationTypeChanged(it)) },

View file

@ -1,4 +1,36 @@
package app.k9mail.feature.account.setup.ui.incoming
import app.k9mail.feature.account.setup.domain.entity.AuthenticationType
import app.k9mail.feature.account.setup.domain.entity.AuthenticationType.ClientCertificate
import app.k9mail.feature.account.setup.domain.entity.AuthenticationType.OAuth2
import app.k9mail.feature.account.setup.domain.entity.AuthenticationType.PasswordCleartext
import app.k9mail.feature.account.setup.domain.entity.AuthenticationType.PasswordEncrypted
import app.k9mail.feature.account.setup.domain.entity.IncomingProtocolType
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
internal val AccountIncomingConfigContract.State.isPasswordFieldVisible: Boolean
get() = authenticationType.isPasswordRequired
internal val AccountIncomingConfigContract.State.allowedAuthenticationTypes: ImmutableList<AuthenticationType>
get() = protocolType.allowedAuthenticationTypes.toImmutableList()
internal val IncomingProtocolType.allowedAuthenticationTypes: List<AuthenticationType>
get() = when (this) {
IncomingProtocolType.IMAP -> {
listOf(
PasswordCleartext,
PasswordEncrypted,
ClientCertificate,
OAuth2,
)
}
IncomingProtocolType.POP3 -> {
listOf(
PasswordCleartext,
PasswordEncrypted,
ClientCertificate,
)
}
}

View file

@ -69,12 +69,20 @@ internal class AccountIncomingConfigViewModel(
private fun updateProtocolType(protocolType: IncomingProtocolType) {
updateState {
val allowedAuthenticationTypesForNewProtocol = protocolType.allowedAuthenticationTypes
val newAuthenticationType = if (it.authenticationType in allowedAuthenticationTypesForNewProtocol) {
it.authenticationType
} else {
allowedAuthenticationTypesForNewProtocol.first()
}
it.copy(
protocolType = protocolType,
security = protocolType.defaultConnectionSecurity,
port = it.port.updateValue(
protocolType.toDefaultPort(protocolType.defaultConnectionSecurity),
),
authenticationType = newAuthenticationType,
)
}
}