From 52a06931f47d6f86d0e54fe1ff31859486c75e1d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 31 Aug 2023 15:51:18 +0200 Subject: [PATCH] Change the test to hide multi signout of devices. We do not need an external account management URL, which is optional, but we need to know if account management is delegate to Oidc. --- .../api/session/homeserver/HomeServerCapabilities.kt | 2 ++ .../features/settings/devices/v2/DevicesViewModel.kt | 10 ++++++---- .../features/settings/devices/v2/DevicesViewState.kt | 2 +- .../devices/v2/VectorSettingsDevicesFragment.kt | 8 ++++---- .../devices/v2/othersessions/OtherSessionsFragment.kt | 4 ++-- .../devices/v2/othersessions/OtherSessionsViewModel.kt | 10 ++++++---- .../devices/v2/othersessions/OtherSessionsViewState.kt | 2 +- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/homeserver/HomeServerCapabilities.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/homeserver/HomeServerCapabilities.kt index b7d4ea3cdc..6b94452e39 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/homeserver/HomeServerCapabilities.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/homeserver/HomeServerCapabilities.kt @@ -146,6 +146,8 @@ data class HomeServerCapabilities( return cap?.preferred ?: cap?.support?.lastOrNull() } + val delegatedOidcAuthEnabled: Boolean = authenticationIssuer != null + companion object { const val MAX_UPLOAD_FILE_SIZE_UNKNOWN = -1L const val ROOM_CAP_KNOCK = "knock" diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt index 369150d45e..43530cb17c 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewModel.kt @@ -35,6 +35,7 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch +import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.uia.DefaultBaseAuth import timber.log.Timber @@ -69,16 +70,17 @@ class DevicesViewModel @AssistedInject constructor( refreshDeviceList() refreshIpAddressVisibility() observePreferences() - initExternalAccountManagementUrl() + initDelegatedOidcAuthEnabled() } - private fun initExternalAccountManagementUrl() { + private fun initDelegatedOidcAuthEnabled() { setState { copy( - externalAccountManagementUrl = activeSessionHolder.getSafeActiveSession() + delegatedOidcAuthEnabled = activeSessionHolder.getSafeActiveSession() ?.homeServerCapabilitiesService() ?.getHomeServerCapabilities() - ?.externalAccountManagementUrl + ?.delegatedOidcAuthEnabled + .orFalse() ) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewState.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewState.kt index 863ecd17a3..6d6baa9d5f 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewState.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/DevicesViewState.kt @@ -26,7 +26,7 @@ data class DevicesViewState( val devices: Async = Uninitialized, val isLoading: Boolean = false, val isShowingIpAddress: Boolean = false, - val externalAccountManagementUrl: String? = null, + val delegatedOidcAuthEnabled: Boolean = false, ) : MavericksState data class DeviceFullInfoList( diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt index 2850064609..bf90120b96 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt @@ -355,8 +355,8 @@ class VectorSettingsDevicesFragment : views.deviceListHeaderOtherSessions.isVisible = true val colorDestructive = colorProvider.getColorFromAttribute(R.attr.colorError) val multiSignoutItem = views.deviceListHeaderOtherSessions.menu.findItem(R.id.otherSessionsHeaderMultiSignout) - // Hide multi signout if we have an external account manager - multiSignoutItem.isVisible = state.externalAccountManagementUrl == null + // Hide multi signout if the homeserver delegates the account management + multiSignoutItem.isVisible = state.delegatedOidcAuthEnabled.not() val nbDevices = otherDevices.size multiSignoutItem.title = stringProvider.getQuantityString(R.plurals.device_manager_other_sessions_multi_signout_all, nbDevices, nbDevices) multiSignoutItem.setTextColor(colorDestructive) @@ -396,8 +396,8 @@ class VectorSettingsDevicesFragment : signoutSessionItem.setTextColor(colorDestructive) val signoutOtherSessionsItem = views.deviceListHeaderCurrentSession.menu.findItem(R.id.currentSessionHeaderSignoutOtherSessions) signoutOtherSessionsItem.setTextColor(colorDestructive) - // Hide signout other sessions if we have an external account manager - signoutOtherSessionsItem.isVisible = hasOtherDevices && state.externalAccountManagementUrl == null + // Hide signout other sessions if the homeserver delegates the account management + signoutOtherSessionsItem.isVisible = hasOtherDevices && state.delegatedOidcAuthEnabled.not() } private fun renderCurrentSessionListView(currentDeviceInfo: DeviceFullInfo) { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsFragment.kt index f935cb83ab..a5897be58c 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsFragment.kt @@ -103,8 +103,8 @@ class OtherSessionsFragment : val nbDevices = viewState.devices()?.size ?: 0 stringProvider.getQuantityString(R.plurals.device_manager_other_sessions_multi_signout_all, nbDevices, nbDevices) } - multiSignoutItem.isVisible = if (viewState.externalAccountManagementUrl != null) { - // Hide multi signout if we have an external account manager + multiSignoutItem.isVisible = if (viewState.delegatedOidcAuthEnabled) { + // Hide multi signout if the homeserver delegates the account management false } else { if (viewState.isSelectModeEnabled) { diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt index 3d41850027..fd463a933c 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModel.kt @@ -36,6 +36,7 @@ import im.vector.app.features.settings.devices.v2.signout.SignoutSessionsReAuthN import im.vector.app.features.settings.devices.v2.signout.SignoutSessionsUseCase import kotlinx.coroutines.Job import kotlinx.coroutines.launch +import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.uia.DefaultBaseAuth import timber.log.Timber @@ -65,16 +66,17 @@ class OtherSessionsViewModel @AssistedInject constructor( observeDevices(initialState.currentFilter) refreshIpAddressVisibility() observePreferences() - initExternalAccountManagementUrl() + initDelegatedOidcAuthEnabled() } - private fun initExternalAccountManagementUrl() { + private fun initDelegatedOidcAuthEnabled() { setState { copy( - externalAccountManagementUrl = activeSessionHolder.getSafeActiveSession() + delegatedOidcAuthEnabled = activeSessionHolder.getSafeActiveSession() ?.homeServerCapabilitiesService() ?.getHomeServerCapabilities() - ?.externalAccountManagementUrl + ?.delegatedOidcAuthEnabled + .orFalse() ) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewState.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewState.kt index ccb3e57f41..dcff652768 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewState.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewState.kt @@ -29,7 +29,7 @@ data class OtherSessionsViewState( val isSelectModeEnabled: Boolean = false, val isLoading: Boolean = false, val isShowingIpAddress: Boolean = false, - val externalAccountManagementUrl: String? = null, + val delegatedOidcAuthEnabled: Boolean = false, ) : MavericksState { constructor(args: OtherSessionsArgs) : this(excludeCurrentDevice = args.excludeCurrentDevice)