From 18ae9784fee5339d8104dad245eaf2020983cb56 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 7 Aug 2024 08:41:29 -0400 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20Do=20not=20send=20data=20to=20Anal?= =?UTF-8?q?ytics=20on=20custom=20backend=20(WPB-10020)=20=F0=9F=8D=92=20(#?= =?UTF-8?q?3295)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: alexandreferris Co-authored-by: Alexandre Ferris --- .../com/wire/android/WireApplication.kt | 5 +- .../ObserveCurrentSessionAnalyticsUseCase.kt | 14 ++- ...serveCurrentSessionAnalyticsUseCaseTest.kt | 85 ++++++++++++++++++- 3 files changed, 99 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/WireApplication.kt b/app/src/main/kotlin/com/wire/android/WireApplication.kt index 82b98bec81e..889c35720a4 100644 --- a/app/src/main/kotlin/com/wire/android/WireApplication.kt +++ b/app/src/main/kotlin/com/wire/android/WireApplication.kt @@ -203,7 +203,10 @@ class WireApplication : BaseApp() { analyticsIdentifierManagerProvider = { coreLogic.get().getSessionScope(it).analyticsIdentifierManager }, - userDataStoreProvider = userDataStoreProvider.get() + userDataStoreProvider = userDataStoreProvider.get(), + currentBackend = { + coreLogic.get().getSessionScope(it).users.serverLinks() + } ).invoke() AnonymousAnalyticsManagerImpl.init( diff --git a/app/src/main/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCase.kt b/app/src/main/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCase.kt index d90cdad547c..c0c7aa79c28 100644 --- a/app/src/main/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCase.kt +++ b/app/src/main/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCase.kt @@ -19,10 +19,12 @@ package com.wire.android.analytics import com.wire.android.datastore.UserDataStoreProvider import com.wire.android.feature.analytics.model.AnalyticsResult +import com.wire.kalium.logic.configuration.server.ServerConfig import com.wire.kalium.logic.data.analytics.AnalyticsIdentifierResult import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.feature.analytics.AnalyticsIdentifierManager import com.wire.kalium.logic.feature.session.CurrentSessionResult +import com.wire.kalium.logic.feature.user.SelfServerConfigUseCase import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged @@ -42,13 +44,14 @@ interface ObserveCurrentSessionAnalyticsUseCase { operator fun invoke(): Flow> } -@Suppress("FunctionNaming") +@Suppress("FunctionNaming", "LongParameterList") fun ObserveCurrentSessionAnalyticsUseCase( currentSessionFlow: Flow, isUserTeamMember: suspend (UserId) -> Boolean, observeAnalyticsTrackingIdentifierStatusFlow: suspend (UserId) -> Flow, analyticsIdentifierManagerProvider: (UserId) -> AnalyticsIdentifierManager, - userDataStoreProvider: UserDataStoreProvider + userDataStoreProvider: UserDataStoreProvider, + currentBackend: suspend (UserId) -> SelfServerConfigUseCase.Result ) = object : ObserveCurrentSessionAnalyticsUseCase { private var previousAnalyticsResult: AnalyticsIdentifierResult? = null @@ -74,7 +77,12 @@ fun ObserveCurrentSessionAnalyticsUseCase( ) { identifierResult, enabled -> previousAnalyticsResult = identifierResult - if (enabled) { + val isProdBackend = when (val serverConfig = currentBackend(userId)) { + is SelfServerConfigUseCase.Result.Success -> serverConfig.serverLinks.links.api == ServerConfig.PRODUCTION.api + is SelfServerConfigUseCase.Result.Failure -> false + } + + if (enabled && isProdBackend) { AnalyticsResult( identifierResult = identifierResult, isTeamMember = isTeamMember, diff --git a/app/src/test/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCaseTest.kt b/app/src/test/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCaseTest.kt index 070f9c30515..50e963991b8 100644 --- a/app/src/test/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCaseTest.kt +++ b/app/src/test/kotlin/com/wire/android/analytics/ObserveCurrentSessionAnalyticsUseCaseTest.kt @@ -22,11 +22,15 @@ import com.wire.android.assertIs import com.wire.android.datastore.UserDataStore import com.wire.android.datastore.UserDataStoreProvider import com.wire.android.framework.TestUser +import com.wire.kalium.logic.CoreFailure +import com.wire.kalium.logic.configuration.server.CommonApiVersionType +import com.wire.kalium.logic.configuration.server.ServerConfig import com.wire.kalium.logic.data.analytics.AnalyticsIdentifierResult import com.wire.kalium.logic.data.auth.AccountInfo import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.feature.analytics.AnalyticsIdentifierManager import com.wire.kalium.logic.feature.session.CurrentSessionResult +import com.wire.kalium.logic.feature.user.SelfServerConfigUseCase import io.mockk.MockKAnnotations import io.mockk.coEvery import io.mockk.every @@ -66,6 +70,7 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { setCurrentSession(CurrentSessionResult.Success(AccountInfo.Valid(TestUser.SELF_USER.id))) setIsTeamMember(TestUser.SELF_USER.id) setObservingTrackingIdentifierStatus(AnalyticsIdentifierResult.ExistingIdentifier(Arrangement.CURRENT_TRACKING_IDENTIFIER)) + setSelfServerConfig(Arrangement.SEVER_CONFIG_PRODUCTION) }.arrange() // when @@ -89,6 +94,61 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { setObservingTrackingIdentifierStatus( AnalyticsIdentifierResult.ExistingIdentifier(Arrangement.CURRENT_TRACKING_IDENTIFIER) ) + setSelfServerConfig(Arrangement.SEVER_CONFIG_PRODUCTION) + }.arrange() + + // when + useCase.invoke().test { + // then + val item = awaitItem() + assertIs(item.identifierResult) + assertEquals(true, item.isTeamMember) + assertEquals(true, item.manager != null) + } + } + + @Test + fun givenThereIsAValidSessionButCustomBackend_whenObservingCurrentSessionAnalytics_thenDisabledAnalyticsResultIsReturned() = + runTest { + // given + val (_, useCase) = Arrangement() + .withIsAnonymousUsageDataEnabled(true) + .apply { + setCurrentSession(CurrentSessionResult.Success(AccountInfo.Valid(TestUser.SELF_USER.id))) + setIsTeamMember(TestUser.SELF_USER.id) + setObservingTrackingIdentifierStatus( + AnalyticsIdentifierResult.ExistingIdentifier(Arrangement.CURRENT_TRACKING_IDENTIFIER) + ) + setSelfServerConfig( + Arrangement.SEVER_CONFIG_PRODUCTION.copy( + serverLinks = Arrangement.SEVER_CONFIG_PRODUCTION.serverLinks.copy(links = ServerConfig.STAGING) + ) + ) + }.arrange() + + // when + useCase.invoke().test { + // then + val item = awaitItem() + assertIs(item.identifierResult) + assertEquals(true, item.isTeamMember) + assertEquals(true, item.manager != null) + } + } + + @Test + fun givenThereIsAValidSessionButFailureOnCustomBackend_whenObservingCurrentSessionAnalytics_thenDisabledAnalyticsResultIsReturned() = + runTest { + // given + val (_, useCase) = Arrangement() + .withIsAnonymousUsageDataEnabled(true) + .apply { + setCurrentSession(CurrentSessionResult.Success(AccountInfo.Valid(TestUser.SELF_USER.id))) + setIsTeamMember(TestUser.SELF_USER.id) + setObservingTrackingIdentifierStatus( + AnalyticsIdentifierResult.ExistingIdentifier(Arrangement.CURRENT_TRACKING_IDENTIFIER) + ) + setSelfServerConfig(SelfServerConfigUseCase.Result.Failure(CoreFailure.Unknown(null))) }.arrange() // when @@ -110,6 +170,7 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { setCurrentSession(CurrentSessionResult.Success(AccountInfo.Valid(TestUser.SELF_USER.id))) setIsTeamMember(TestUser.SELF_USER.id) setObservingTrackingIdentifierStatus(AnalyticsIdentifierResult.ExistingIdentifier(Arrangement.CURRENT_TRACKING_IDENTIFIER)) + setSelfServerConfig(Arrangement.SEVER_CONFIG_PRODUCTION) }.arrange() // when @@ -124,6 +185,7 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { arrangement.setObservingTrackingIdentifierStatus( AnalyticsIdentifierResult.ExistingIdentifier(Arrangement.OTHER_TRACKING_IDENTIFIER) ) + arrangement.setSelfServerConfig(Arrangement.SEVER_CONFIG_PRODUCTION) arrangement.withIsAnonymousUsageDataEnabled(true) // then @@ -148,6 +210,8 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { private val analyticsTrackingIdentifierStatusChannel = Channel(Channel.UNLIMITED) + private val selfServerConfigChannel = Channel(Channel.UNLIMITED) + private val teamMembers = mutableSetOf() private val isTeamMember: (UserId) -> Boolean = { teamMembers.contains(it) } @@ -169,6 +233,10 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { analyticsTrackingIdentifierStatusChannel.send(result) } + suspend fun setSelfServerConfig(result: SelfServerConfigUseCase.Result) { + selfServerConfigChannel.send(result) + } + fun withIsAnonymousUsageDataEnabled(result: Boolean): Arrangement = apply { every { userDataStoreProvider.getOrCreate(any()) } returns userDataStore coEvery { userDataStore.isAnonymousUsageDataEnabled() } returns flowOf(result) @@ -183,7 +251,10 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { analyticsIdentifierManagerProvider = { analyticsIdentifierManager }, - userDataStoreProvider = userDataStoreProvider + userDataStoreProvider = userDataStoreProvider, + currentBackend = { + selfServerConfigChannel.receive() + } ) fun arrange() = this to useCase @@ -191,6 +262,18 @@ class ObserveCurrentSessionAnalyticsUseCaseTest { companion object { const val CURRENT_TRACKING_IDENTIFIER = "abcd-1234" const val OTHER_TRACKING_IDENTIFIER = "aaaa-bbbb-1234" + + val SEVER_CONFIG_PRODUCTION = SelfServerConfigUseCase.Result.Success( + serverLinks = ServerConfig( + id = "server_id", + links = ServerConfig.PRODUCTION, + metaData = ServerConfig.MetaData( + federation = false, + commonApiVersion = CommonApiVersionType.New, + domain = null + ) + ) + ) } } } From cdab6d01fac2fe748eca825899f9ba03df164370 Mon Sep 17 00:00:00 2001 From: Yamil Medina Date: Thu, 8 Aug 2024 14:55:27 +0200 Subject: [PATCH 2/2] ci: Update build-prod-app.yml --- .github/workflows/build-prod-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-prod-app.yml b/.github/workflows/build-prod-app.yml index 5fb7c463f96..bbfab4a32c7 100644 --- a/.github/workflows/build-prod-app.yml +++ b/.github/workflows/build-prod-app.yml @@ -2,7 +2,7 @@ name: "Prod build" on: release: - types: [ created ] + types: [ published ] concurrency: group: ${{ github.workflow }}-${{ github.event.release.tag_name }}