Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: display the app lock enforce dialogue when it is enforced but no… #2487

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,17 @@ class FeatureFlagNotificationViewModel @Inject constructor(
viewModelScope.launch {
coreLogic.getSessionScope(userId).appLockTeamFeatureConfigObserver()
.distinctUntilChanged()
.collectLatest {
it?.isStatusChanged?.let { isStatusChanged ->
.collectLatest { appLockConfig ->
appLockConfig?.isStatusChanged?.let { isStatusChanged ->
val shouldBlockApp = if (isStatusChanged) {
true
} else {
(!isUserAppLockSet() && appLockConfig.isEnforced)
}

featureFlagState = featureFlagState.copy(
isTeamAppLockEnabled = it.isEnforced,
shouldShowTeamAppLockDialog = isStatusChanged
isTeamAppLockEnabled = appLockConfig.isEnforced,
shouldShowTeamAppLockDialog = shouldBlockApp
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import com.wire.android.feature.DisableAppLockUseCase
import com.wire.android.framework.TestUser
import com.wire.android.ui.home.FeatureFlagState
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.configuration.AppLockTeamConfig
import com.wire.kalium.logic.configuration.FileSharingStatus
import com.wire.kalium.logic.configuration.GuestRoomLinkStatus
import com.wire.kalium.logic.data.auth.AccountInfo
import com.wire.kalium.logic.data.sync.SyncState
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.applock.AppLockTeamFeatureConfigObserver
import com.wire.kalium.logic.feature.session.CurrentSessionResult
import com.wire.kalium.logic.feature.session.CurrentSessionUseCase
import com.wire.kalium.logic.feature.user.E2EIRequiredResult
Expand All @@ -30,8 +32,10 @@ import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.internal.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import kotlin.time.Duration
import kotlin.time.Duration.Companion.days

@OptIn(ExperimentalCoroutinesApi::class)
Expand Down Expand Up @@ -114,6 +118,20 @@ class FeatureFlagNotificationViewModelTest {
assertEquals(false, viewModel.featureFlagState.shouldShowSelfDeletingMessagesDialog)
}

@Test
fun givenTeamAppLockIsEnforceButNotChanged_whenAppHaveNotAppLockSetup_thenDisplayTheAppLockDialog() = runTest {
val (_, viewModel) = Arrangement()
.withCurrentSessions(CurrentSessionResult.Success(AccountInfo.Valid(UserId("value", "domain"))))
.withIsAppLockSetup(false)
.withTeamAppLockEnforce(AppLockTeamConfig(true, Duration.ZERO, false))
.arrange()

viewModel.initialSync()
advanceUntilIdle()

assertTrue(viewModel.featureFlagState.shouldShowTeamAppLockDialog)
}

@Test
fun givenE2EIRequired_thenShowDialog() = runTest {
val (arrangement, viewModel) = Arrangement()
Expand Down Expand Up @@ -247,7 +265,6 @@ class FeatureFlagNotificationViewModelTest {
coEvery { currentSession() } returns CurrentSessionResult.Success(AccountInfo.Valid(TestUser.USER_ID))
coEvery { coreLogic.getSessionScope(any()).observeSyncState() } returns flowOf(SyncState.Live)
coEvery { coreLogic.getSessionScope(any()).observeTeamSettingsSelfDeletionStatus() } returns flowOf()
coEvery { coreLogic.getSessionScope(any()).appLockTeamFeatureConfigObserver() } returns flowOf()
}

@MockK
Expand All @@ -265,6 +282,9 @@ class FeatureFlagNotificationViewModelTest {
@MockK
lateinit var markE2EIRequiredAsNotified: MarkEnablingE2EIAsNotifiedUseCase

@MockK
lateinit var ppLockTeamFeatureConfigObserver: AppLockTeamFeatureConfigObserver

@MockK
lateinit var disableAppLockUseCase: DisableAppLockUseCase

Expand All @@ -282,16 +302,22 @@ class FeatureFlagNotificationViewModelTest {
every { coreLogic.getSessionScope(any()).markGuestLinkFeatureFlagAsNotChanged } returns markGuestLinkFeatureFlagAsNotChanged
every { coreLogic.getSessionScope(any()).markSelfDeletingMessagesAsNotified } returns markSelfDeletingStatusAsNotified
every { coreLogic.getSessionScope(any()).markE2EIRequiredAsNotified } returns markE2EIRequiredAsNotified
coEvery { coreLogic.getSessionScope(any()).appLockTeamFeatureConfigObserver } returns ppLockTeamFeatureConfigObserver
coEvery { coreLogic.getSessionScope(any()).observeFileSharingStatus.invoke() } returns flowOf()
coEvery { coreLogic.getSessionScope(any()).observeGuestRoomLinkFeatureFlag.invoke() } returns flowOf()
coEvery { coreLogic.getSessionScope(any()).observeE2EIRequired.invoke() } returns flowOf()
coEvery { coreLogic.getSessionScope(any()).calls.observeEndCallDialog() } returns flowOf()
coEvery { ppLockTeamFeatureConfigObserver() } returns flowOf(null)
}

fun withCurrentSessions(result: CurrentSessionResult) = apply {
coEvery { currentSession() } returns result
}

fun withIsAppLockSetup(result: Boolean) = apply {
coEvery { globalDataStore.isAppLockPasscodeSet() } returns result
}

fun withSyncState(stateFlow: Flow<SyncState>) = apply {
coEvery { coreLogic.getSessionScope(any()).observeSyncState() } returns stateFlow
}
Expand Down Expand Up @@ -320,6 +346,10 @@ class FeatureFlagNotificationViewModelTest {
coEvery { coreLogic.getSessionScope(any()).calls.observeEndCallDialog() } returns flowOf(Unit)
}

fun withTeamAppLockEnforce(result: AppLockTeamConfig?) = apply {
coEvery { ppLockTeamFeatureConfigObserver() } returns flowOf(result)
}

fun arrange() = this to viewModel
}
}