Merge pull request #6682 from element-hq/feature/bma/customMasScheme
Add a way to tweak MAS url.
This commit is contained in:
commit
2f45ca8835
41 changed files with 656 additions and 17 deletions
|
|
@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.Flow
|
|||
interface EnterpriseService {
|
||||
val isEnterpriseBuild: Boolean
|
||||
suspend fun isEnterpriseUser(sessionId: SessionId): Boolean
|
||||
suspend fun tweakMasUrl(url: String, homeserver: String): String
|
||||
fun defaultHomeserverList(): List<String>
|
||||
suspend fun isAllowedToConnectToHomeserver(homeserverUrl: String): Boolean
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ package io.element.android.features.enterprise.api
|
|||
|
||||
interface SessionEnterpriseService {
|
||||
suspend fun isElementCallAvailable(): Boolean
|
||||
suspend fun tweakMasUrl(url: String): String
|
||||
|
||||
suspend fun init()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class DefaultEnterpriseService : EnterpriseService {
|
|||
override val isEnterpriseBuild = false
|
||||
|
||||
override suspend fun isEnterpriseUser(sessionId: SessionId) = false
|
||||
|
||||
override suspend fun tweakMasUrl(url: String, homeserver: String) = url
|
||||
override fun defaultHomeserverList(): List<String> = emptyList()
|
||||
override suspend fun isAllowedToConnectToHomeserver(homeserverUrl: String) = true
|
||||
|
||||
|
|
|
|||
|
|
@ -15,5 +15,6 @@ import io.element.android.libraries.di.SessionScope
|
|||
@ContributesBinding(SessionScope::class)
|
||||
class DefaultSessionEnterpriseService : SessionEnterpriseService {
|
||||
override suspend fun init() = Unit
|
||||
override suspend fun tweakMasUrl(url: String): String = url
|
||||
override suspend fun isElementCallAvailable(): Boolean = true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class FakeEnterpriseService(
|
|||
private val firebasePushGatewayResult: () -> String? = { lambdaError() },
|
||||
private val unifiedPushDefaultPushGatewayResult: () -> String? = { lambdaError() },
|
||||
private val getNoisyNotificationChannelIdResult: (SessionId?) -> String? = { lambdaError() },
|
||||
private val tweakMasUrlResult: (String, String) -> String = { _, _ -> lambdaError() },
|
||||
) : EnterpriseService {
|
||||
private val brandColorState = MutableStateFlow(initialBrandColor)
|
||||
private val semanticColorsState = MutableStateFlow(initialSemanticColors)
|
||||
|
|
@ -38,6 +39,10 @@ class FakeEnterpriseService(
|
|||
isEnterpriseUserResult(sessionId)
|
||||
}
|
||||
|
||||
override suspend fun tweakMasUrl(url: String, homeserver: String): String = simulateLongTask {
|
||||
tweakMasUrlResult(url, homeserver)
|
||||
}
|
||||
|
||||
override fun defaultHomeserverList(): List<String> {
|
||||
return defaultHomeserverListResult()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,15 @@ import io.element.android.tests.testutils.simulateLongTask
|
|||
|
||||
class FakeSessionEnterpriseService(
|
||||
private val isElementCallAvailableResult: () -> Boolean = { lambdaError() },
|
||||
private val tweakMasUrlResult: (String) -> String = { lambdaError() },
|
||||
) : SessionEnterpriseService {
|
||||
override suspend fun init() {
|
||||
}
|
||||
|
||||
override suspend fun tweakMasUrl(url: String): String = simulateLongTask {
|
||||
tweakMasUrlResult(url)
|
||||
}
|
||||
|
||||
override suspend fun isElementCallAvailable(): Boolean = simulateLongTask {
|
||||
isElementCallAvailableResult()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import dev.zacsweers.metro.Assisted
|
|||
import dev.zacsweers.metro.AssistedInject
|
||||
import io.element.android.annotations.ContributesNode
|
||||
import io.element.android.compound.theme.ElementTheme
|
||||
import io.element.android.features.enterprise.api.SessionEnterpriseService
|
||||
import io.element.android.features.linknewdevice.api.LinkNewDeviceEntryPoint
|
||||
import io.element.android.features.linknewdevice.impl.screens.confirmation.CodeConfirmationNode
|
||||
import io.element.android.features.linknewdevice.impl.screens.desktop.DesktopNoticeNode
|
||||
|
|
@ -65,6 +66,7 @@ class LinkNewDeviceFlowNode(
|
|||
private val sessionCoroutineScope: CoroutineScope,
|
||||
private val linkNewMobileHandler: LinkNewMobileHandler,
|
||||
private val linkNewDesktopHandler: LinkNewDesktopHandler,
|
||||
private val sessionEnterpriseService: SessionEnterpriseService,
|
||||
) : BaseFlowNode<LinkNewDeviceFlowNode.NavTarget>(
|
||||
backstack = BackStack(
|
||||
initialElement = NavTarget.Root,
|
||||
|
|
@ -298,8 +300,12 @@ class LinkNewDeviceFlowNode(
|
|||
}
|
||||
}
|
||||
|
||||
private fun navigateToBrowser(url: String) {
|
||||
activity?.openUrlInChromeCustomTab(null, darkTheme, url)
|
||||
private suspend fun navigateToBrowser(url: String) {
|
||||
activity?.openUrlInChromeCustomTab(
|
||||
session = null,
|
||||
darkTheme = darkTheme,
|
||||
url = sessionEnterpriseService.tweakMasUrl(url),
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
|||
import com.bumble.appyx.core.modality.BuildContext
|
||||
import com.bumble.appyx.testing.junit4.util.MainDispatcherRule
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.features.enterprise.test.FakeSessionEnterpriseService
|
||||
import io.element.android.features.linknewdevice.api.LinkNewDeviceEntryPoint
|
||||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||
import io.element.android.tests.testutils.lambda.lambdaError
|
||||
|
|
@ -37,6 +38,7 @@ class DefaultLinkNewDeviceEntryPointTest {
|
|||
sessionCoroutineScope = backgroundScope,
|
||||
linkNewMobileHandler = LinkNewMobileHandler(client),
|
||||
linkNewDesktopHandler = LinkNewDesktopHandler(client),
|
||||
sessionEnterpriseService = FakeSessionEnterpriseService(),
|
||||
)
|
||||
}
|
||||
val callback: LinkNewDeviceEntryPoint.Callback = object : LinkNewDeviceEntryPoint.Callback {
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ dependencies {
|
|||
implementation(projects.appconfig)
|
||||
implementation(projects.libraries.core)
|
||||
implementation(projects.libraries.architecture)
|
||||
implementation(projects.libraries.cachestore.api)
|
||||
implementation(projects.libraries.matrix.api)
|
||||
implementation(projects.libraries.designsystem)
|
||||
implementation(projects.libraries.featureflag.api)
|
||||
|
|
@ -115,6 +116,7 @@ dependencies {
|
|||
testImplementation(projects.features.logout.test)
|
||||
testImplementation(projects.libraries.indicator.test)
|
||||
testImplementation(projects.libraries.pushproviders.test)
|
||||
testImplementation(projects.libraries.cachestore.test)
|
||||
testImplementation(projects.libraries.sessionStorage.test)
|
||||
testImplementation(projects.services.appnavstate.impl)
|
||||
testImplementation(projects.services.analytics.test)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import dev.zacsweers.metro.Inject
|
||||
import io.element.android.features.enterprise.api.SessionEnterpriseService
|
||||
import io.element.android.features.logout.api.direct.DirectLogoutState
|
||||
import io.element.android.features.preferences.impl.utils.ShowDeveloperSettingsProvider
|
||||
import io.element.android.features.rageshake.api.RageshakeFeatureAvailability
|
||||
|
|
@ -55,6 +56,7 @@ class PreferencesRootPresenter(
|
|||
private val rageshakeFeatureAvailability: RageshakeFeatureAvailability,
|
||||
private val featureFlagService: FeatureFlagService,
|
||||
private val sessionStore: SessionStore,
|
||||
private val sessionEnterpriseService: SessionEnterpriseService,
|
||||
) : Presenter<PreferencesRootState> {
|
||||
@Composable
|
||||
override fun present(): PreferencesRootState {
|
||||
|
|
@ -158,6 +160,10 @@ class PreferencesRootPresenter(
|
|||
private fun CoroutineScope.initAccountManagementUrl(
|
||||
accountManagementUrl: MutableState<String?>,
|
||||
) = launch {
|
||||
accountManagementUrl.value = matrixClient.getAccountManagementUrl(null).getOrNull()
|
||||
accountManagementUrl.value = matrixClient.getAccountManagementUrl(null)
|
||||
.getOrNull()
|
||||
?.let {
|
||||
sessionEnterpriseService.tweakMasUrl(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import dev.zacsweers.metro.ContributesBinding
|
|||
import dev.zacsweers.metro.Provider
|
||||
import io.element.android.features.invite.api.SeenInvitesStore
|
||||
import io.element.android.features.preferences.impl.DefaultCacheService
|
||||
import io.element.android.libraries.cachestore.api.CacheStore
|
||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.di.SessionScope
|
||||
import io.element.android.libraries.di.annotations.ApplicationContext
|
||||
|
|
@ -37,8 +38,11 @@ class DefaultClearCacheUseCase(
|
|||
private val pushService: PushService,
|
||||
private val seenInvitesStore: SeenInvitesStore,
|
||||
private val activeRoomsHolder: ActiveRoomsHolder,
|
||||
private val cacheStore: CacheStore,
|
||||
) : ClearCacheUseCase {
|
||||
override suspend fun invoke() = withContext(coroutineDispatchers.io) {
|
||||
// Clear cache store
|
||||
cacheStore.deleteAll()
|
||||
// Active rooms should be disposed of before clearing the cache
|
||||
activeRoomsHolder.clear(matrixClient.sessionId)
|
||||
// Clear Matrix cache
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ package io.element.android.features.preferences.impl.root
|
|||
|
||||
import app.cash.turbine.ReceiveTurbine
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.features.enterprise.api.SessionEnterpriseService
|
||||
import io.element.android.features.enterprise.test.FakeSessionEnterpriseService
|
||||
import io.element.android.features.logout.api.direct.aDirectLogoutState
|
||||
import io.element.android.features.preferences.impl.utils.ShowDeveloperSettingsProvider
|
||||
import io.element.android.features.rageshake.api.RageshakeFeatureAvailability
|
||||
|
|
@ -65,6 +67,9 @@ class PreferencesRootPresenterTest {
|
|||
)
|
||||
createPresenter(
|
||||
matrixClient = matrixClient,
|
||||
sessionEnterpriseService = FakeSessionEnterpriseService(
|
||||
tweakMasUrlResult = { "tweaked $it" },
|
||||
),
|
||||
).test {
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.myUser).isEqualTo(
|
||||
|
|
@ -100,7 +105,7 @@ class PreferencesRootPresenterTest {
|
|||
val finalState = awaitItem()
|
||||
accountManagementUrlResult.assertions().isCalledOnce()
|
||||
.with(value(null))
|
||||
assertThat(finalState.accountManagementUrl).isEqualTo("null url")
|
||||
assertThat(finalState.accountManagementUrl).isEqualTo("tweaked null url")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -327,6 +332,7 @@ class PreferencesRootPresenterTest {
|
|||
indicatorService: IndicatorService = FakeIndicatorService(),
|
||||
featureFlagService: FeatureFlagService = FakeFeatureFlagService(),
|
||||
sessionStore: SessionStore = InMemorySessionStore(),
|
||||
sessionEnterpriseService: SessionEnterpriseService = FakeSessionEnterpriseService(),
|
||||
) = PreferencesRootPresenter(
|
||||
matrixClient = matrixClient,
|
||||
sessionVerificationService = sessionVerificationService,
|
||||
|
|
@ -339,5 +345,6 @@ class PreferencesRootPresenterTest {
|
|||
rageshakeFeatureAvailability = rageshakeFeatureAvailability,
|
||||
featureFlagService = featureFlagService,
|
||||
sessionStore = sessionStore,
|
||||
sessionEnterpriseService = sessionEnterpriseService,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import io.element.android.libraries.matrix.test.A_SESSION_ID
|
|||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||
import io.element.android.libraries.matrix.test.room.FakeJoinedRoom
|
||||
import io.element.android.libraries.push.test.FakePushService
|
||||
import io.element.android.libraries.sessionstorage.test.InMemoryCacheStore
|
||||
import io.element.android.libraries.sessionstorage.test.aCacheData
|
||||
import io.element.android.services.appnavstate.impl.DefaultActiveRoomsHolder
|
||||
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
||||
import io.element.android.tests.testutils.lambda.value
|
||||
|
|
@ -49,6 +51,9 @@ class DefaultClearCacheUseCaseTest {
|
|||
)
|
||||
val seenInvitesStore = InMemorySeenInvitesStore(setOf(A_ROOM_ID))
|
||||
assertThat(seenInvitesStore.seenRoomIds().first()).isNotEmpty()
|
||||
val cacheStore = InMemoryCacheStore(
|
||||
initialData = mapOf("key1" to aCacheData())
|
||||
)
|
||||
val sut = DefaultClearCacheUseCase(
|
||||
context = InstrumentationRegistry.getInstrumentation().context,
|
||||
matrixClient = matrixClient,
|
||||
|
|
@ -58,9 +63,11 @@ class DefaultClearCacheUseCaseTest {
|
|||
pushService = pushService,
|
||||
seenInvitesStore = seenInvitesStore,
|
||||
activeRoomsHolder = activeRoomsHolder,
|
||||
cacheStore = cacheStore,
|
||||
)
|
||||
defaultCacheService.clearedCacheEventFlow.test {
|
||||
sut.invoke()
|
||||
assertThat(cacheStore.dataMap).isEmpty()
|
||||
clearCacheLambda.assertions().isCalledOnce()
|
||||
setIgnoreRegistrationErrorLambda.assertions().isCalledOnce()
|
||||
.with(value(matrixClient.sessionId), value(false))
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ setupDependencyInjection()
|
|||
|
||||
dependencies {
|
||||
implementation(projects.appconfig)
|
||||
implementation(projects.features.enterprise.api)
|
||||
implementation(projects.libraries.core)
|
||||
implementation(projects.libraries.androidutils)
|
||||
implementation(projects.libraries.architecture)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import dev.zacsweers.metro.Assisted
|
|||
import dev.zacsweers.metro.AssistedInject
|
||||
import io.element.android.annotations.ContributesNode
|
||||
import io.element.android.compound.theme.ElementTheme
|
||||
import io.element.android.features.enterprise.api.SessionEnterpriseService
|
||||
import io.element.android.features.securebackup.impl.reset.password.ResetIdentityPasswordNode
|
||||
import io.element.android.features.securebackup.impl.reset.root.ResetIdentityRootNode
|
||||
import io.element.android.libraries.androidutils.browser.openUrlInChromeCustomTab
|
||||
|
|
@ -53,6 +54,7 @@ class ResetIdentityFlowNode(
|
|||
private val resetIdentityFlowManager: ResetIdentityFlowManager,
|
||||
@SessionCoroutineScope
|
||||
private val sessionCoroutineScope: CoroutineScope,
|
||||
private val sessionEnterpriseService: SessionEnterpriseService,
|
||||
) : BaseFlowNode<ResetIdentityFlowNode.NavTarget>(
|
||||
backstack = BackStack(initialElement = NavTarget.Root, savedStateMap = buildContext.savedStateMap),
|
||||
buildContext = buildContext,
|
||||
|
|
@ -125,7 +127,8 @@ class ResetIdentityFlowNode(
|
|||
}
|
||||
is IdentityOAuthResetHandle -> {
|
||||
Timber.d("Launching reset confirmation in MAS")
|
||||
activity.openUrlInChromeCustomTab(null, darkTheme, handle.url)
|
||||
val url = sessionEnterpriseService.tweakMasUrl(handle.url)
|
||||
activity.openUrlInChromeCustomTab(null, darkTheme, url)
|
||||
Timber.d("Starting resetOAuth")
|
||||
resetJob = launch { handle.resetOAuth() }
|
||||
resetJob?.invokeOnCompletion { Timber.d("resetOAuth ended") }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue