Skip to content

Commit

Permalink
fix(e2ei): remove E2EI shield and buttons if it's disabled on your te…
Browse files Browse the repository at this point in the history
…am (WPB-6520) (#2698)

Co-authored-by: Mojtaba Chenani <[email protected]>
  • Loading branch information
AndroidBob and mchenani authored Feb 14, 2024
1 parent 8be3239 commit ca11930
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 30 deletions.
5 changes: 5 additions & 0 deletions app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ class UseCaseModule {
fun provideIsMLSEnabledUseCase(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) =
coreLogic.getSessionScope(currentAccount).isMLSEnabled

@ViewModelScoped
@Provides
fun provideIsE2EIEnabledUseCase(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) =
coreLogic.getSessionScope(currentAccount).isE2EIEnabled

@ViewModelScoped
@Provides
fun provideIsFileSharingEnabledUseCase(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ fun DeviceItem(
placeholder: Boolean,
shouldShowVerifyLabel: Boolean,
isCurrentClient: Boolean = false,
shouldShowE2EIInfo: Boolean = false,
background: Color? = null,
icon: @Composable (() -> Unit),
isWholeItemClickable: Boolean = false,
Expand All @@ -87,7 +88,8 @@ fun DeviceItem(
onClickAction = onClickAction,
isWholeItemClickable = isWholeItemClickable,
shouldShowVerifyLabel = shouldShowVerifyLabel,
isCurrentClient = isCurrentClient
isCurrentClient = isCurrentClient,
shouldShowE2EIInfo = shouldShowE2EIInfo
)
}

Expand All @@ -100,7 +102,8 @@ private fun DeviceItemContent(
onClickAction: ((Device) -> Unit)?,
isWholeItemClickable: Boolean,
shouldShowVerifyLabel: Boolean,
isCurrentClient: Boolean
isCurrentClient: Boolean,
shouldShowE2EIInfo: Boolean
) {
Row(
verticalAlignment = Alignment.Top,
Expand All @@ -126,7 +129,7 @@ private fun DeviceItemContent(
modifier = Modifier
.padding(start = MaterialTheme.wireDimensions.removeDeviceItemPadding)
.weight(1f)
) { DeviceItemTexts(device, placeholder, shouldShowVerifyLabel, isCurrentClient) }
) { DeviceItemTexts(device, placeholder, shouldShowVerifyLabel, isCurrentClient, shouldShowE2EIInfo) }
}
if (!placeholder) {
if (onClickAction != null && !isWholeItemClickable) {
Expand Down Expand Up @@ -158,6 +161,7 @@ private fun DeviceItemTexts(
placeholder: Boolean,
shouldShowVerifyLabel: Boolean,
isCurrentClient: Boolean = false,
shouldShowE2EIInfo: Boolean = false,
isDebug: Boolean = BuildConfig.DEBUG
) {
val displayZombieIndicator = remember {
Expand All @@ -178,7 +182,9 @@ private fun DeviceItemTexts(
.shimmerPlaceholder(visible = placeholder)
)
if (shouldShowVerifyLabel) {
MLSVerificationIcon(device.e2eiCertificateStatus)
if (shouldShowE2EIInfo) {
MLSVerificationIcon(device.e2eiCertificateStatus)
}
Spacer(modifier = Modifier.width(MaterialTheme.wireDimensions.spacing8x))
if (device.isVerifiedProteus && !isCurrentClient) ProteusVerifiedIcon(
Modifier
Expand Down Expand Up @@ -256,6 +262,7 @@ fun PreviewDeviceItemWithActionIcon() {
placeholder = false,
shouldShowVerifyLabel = true,
isCurrentClient = true,
shouldShowE2EIInfo = true,
background = null,
{ Icon(painter = painterResource(id = R.drawable.ic_remove), contentDescription = "") }
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fun DeviceDetailsContent(
) {
val screenState = rememberConversationScreenState()
WireScaffold(
topBar = { DeviceDetailsTopBar(onNavigateBack, state.device, state.isCurrentDevice) },
topBar = { DeviceDetailsTopBar(onNavigateBack, state.device, state.isCurrentDevice, state.isE2EIEnabled) },
bottomBar = {
Column(
Modifier
Expand Down Expand Up @@ -187,17 +187,19 @@ fun DeviceDetailsContent(
Divider(color = MaterialTheme.wireColorScheme.background)
}
}
item {
EndToEndIdentityCertificateItem(
isE2eiCertificateActivated = state.isE2eiCertificateActivated,
certificate = state.e2eiCertificate,
isCurrentDevice = state.isCurrentDevice,
isLoadingCertificate = state.isLoadingCertificate,
enrollE2eiCertificate = { enrollE2eiCertificate(context) },
updateE2eiCertificate = {},
showCertificate = onNavigateToE2eiCertificateDetailsScreen
)
Divider(color = colorsScheme().background)

if (state.isE2EIEnabled) {
item {
EndToEndIdentityCertificateItem(
isE2eiCertificateActivated = state.isE2eiCertificateActivated,
certificate = state.e2eiCertificate,
isCurrentDevice = state.isCurrentDevice,
isLoadingCertificate = state.isLoadingCertificate,
enrollE2eiCertificate = { enrollE2eiCertificate(context) },
showCertificate = onNavigateToE2eiCertificateDetailsScreen
)
Divider(color = colorsScheme().background)
}
}
item {
FolderHeader(
Expand Down Expand Up @@ -293,7 +295,8 @@ fun DeviceDetailsContent(
private fun DeviceDetailsTopBar(
onNavigateBack: () -> Unit,
device: Device,
isCurrentDevice: Boolean
isCurrentDevice: Boolean,
shouldShowE2EIInfo: Boolean
) {
WireCenterAlignedTopAppBar(
onNavigationPressed = onNavigateBack,
Expand All @@ -306,7 +309,9 @@ private fun DeviceDetailsTopBar(
maxLines = 2
)

MLSVerificationIcon(device.e2eiCertificateStatus)
if (shouldShowE2EIInfo) {
MLSVerificationIcon(device.e2eiCertificateStatus)
}

if (!isCurrentDevice && device.isVerifiedProteus) {
ProteusVerifiedIcon(Modifier.align(Alignment.CenterVertically))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import com.wire.kalium.logic.feature.e2ei.usecase.E2EIEnrollmentResult
import com.wire.kalium.logic.feature.e2ei.usecase.GetE2EICertificateUseCaseResult
import com.wire.kalium.logic.feature.e2ei.usecase.GetE2eiCertificateUseCase
import com.wire.kalium.logic.feature.user.GetUserInfoResult
import com.wire.kalium.logic.feature.user.IsE2EIEnabledUseCase
import com.wire.kalium.logic.feature.user.IsPasswordRequiredUseCase
import com.wire.kalium.logic.feature.user.ObserveUserInfoUseCase
import com.wire.kalium.logic.functional.fold
Expand All @@ -68,14 +69,20 @@ class DeviceDetailsViewModel @Inject constructor(
private val updateClientVerificationStatus: UpdateClientVerificationStatusUseCase,
private val observeUserInfo: ObserveUserInfoUseCase,
private val e2eiCertificate: GetE2eiCertificateUseCase,
private val enrolE2EICertificateUseCase: GetE2EICertificateUseCase
private val enrolE2EICertificateUseCase: GetE2EICertificateUseCase,
isE2EIEnabledUseCase: IsE2EIEnabledUseCase
) : SavedStateViewModel(savedStateHandle) {

private val deviceDetailsNavArgs: DeviceDetailsNavArgs = savedStateHandle.navArgs()
private val deviceId: ClientId = deviceDetailsNavArgs.clientId
private val userId: UserId = deviceDetailsNavArgs.userId

var state: DeviceDetailsState by mutableStateOf(DeviceDetailsState(isSelfClient = isSelfClient))
var state: DeviceDetailsState by mutableStateOf(
DeviceDetailsState(
isSelfClient = isSelfClient,
isE2EIEnabled = isE2EIEnabledUseCase()
)
)
private set

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ fun EndToEndIdentityCertificateItem(
isCurrentDevice: Boolean,
isLoadingCertificate: Boolean,
enrollE2eiCertificate: () -> Unit,
updateE2eiCertificate: () -> Unit,
showCertificate: (String) -> Unit
) {
Column(
Expand Down Expand Up @@ -206,7 +205,6 @@ fun PreviewEndToEndIdentityCertificateItem() {
),
isLoadingCertificate = false,
enrollE2eiCertificate = {},
updateE2eiCertificate = {},
showCertificate = {}
)
}
Expand All @@ -225,7 +223,6 @@ fun PreviewEndToEndIdentityCertificateSelfItem() {
),
isLoadingCertificate = false,
enrollE2eiCertificate = {},
updateE2eiCertificate = {},
showCertificate = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ fun SelfDevicesScreenContent(
items = listOf(currentDevice),
shouldShowVerifyLabel = true,
isCurrentClient = true,
isE2EIEnabled = state.isE2EIEnabled,
onDeviceClick = onDeviceClick,

)
Expand All @@ -103,6 +104,7 @@ fun SelfDevicesScreenContent(
items = state.deviceList,
shouldShowVerifyLabel = true,
isCurrentClient = false,
isE2EIEnabled = state.isE2EIEnabled,
onDeviceClick = onDeviceClick
)
}
Expand All @@ -111,12 +113,13 @@ fun SelfDevicesScreenContent(
}
)
}

@Suppress("LongParameterList")
private fun LazyListScope.folderDeviceItems(
header: String,
items: List<Device>,
shouldShowVerifyLabel: Boolean,
isCurrentClient: Boolean,
isE2EIEnabled: Boolean,
onDeviceClick: (Device) -> Unit = {}
) {
folderWithElements(
Expand All @@ -137,7 +140,8 @@ private fun LazyListScope.folderDeviceItems(
icon = Icons.Filled.ChevronRight.Icon(),
isWholeItemClickable = true,
shouldShowVerifyLabel = shouldShowVerifyLabel,
isCurrentClient = isCurrentClient
isCurrentClient = isCurrentClient,
shouldShowE2EIInfo = isE2EIEnabled
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.wire.kalium.logic.feature.client.FetchSelfClientsFromRemoteUseCase
import com.wire.kalium.logic.feature.client.ObserveClientsByUserIdUseCase
import com.wire.kalium.logic.feature.client.ObserveCurrentClientIdUseCase
import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificatesUseCase
import com.wire.kalium.logic.feature.user.IsE2EIEnabledUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
Expand All @@ -43,10 +44,11 @@ class SelfDevicesViewModel @Inject constructor(
private val observeClientList: ObserveClientsByUserIdUseCase,
private val currentClientIdUseCase: ObserveCurrentClientIdUseCase,
private val getUserE2eiCertificates: GetUserE2eiCertificatesUseCase,
isE2EIEnabledUseCase: IsE2EIEnabledUseCase
) : ViewModel() {

var state: SelfDevicesState by mutableStateOf(
SelfDevicesState(deviceList = listOf(), isLoadingClientsList = true, currentDevice = null)
SelfDevicesState(deviceList = listOf(), isLoadingClientsList = true, currentDevice = null, isE2EIEnabled = isE2EIEnabledUseCase())
)
private set

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ data class DeviceDetailsState(
val isLoadingCertificate: Boolean = false,
val isE2EICertificateEnrollSuccess: Boolean = false,
val isE2EICertificateEnrollError: Boolean = false,
val isE2EIEnabled: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ import com.wire.android.ui.authentication.devices.model.Device
data class SelfDevicesState (
val currentDevice: Device?,
val deviceList: List<Device>,
val isLoadingClientsList: Boolean
val isLoadingClientsList: Boolean,
val isE2EIEnabled: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.wire.kalium.logic.feature.client.UpdateClientVerificationStatusUseCas
import com.wire.kalium.logic.feature.e2ei.usecase.GetE2EICertificateUseCaseResult
import com.wire.kalium.logic.feature.e2ei.usecase.GetE2eiCertificateUseCase
import com.wire.kalium.logic.feature.user.GetUserInfoResult
import com.wire.kalium.logic.feature.user.IsE2EIEnabledUseCase
import com.wire.kalium.logic.feature.user.IsPasswordRequiredUseCase
import com.wire.kalium.logic.feature.user.ObserveUserInfoUseCase
import io.mockk.Called
Expand Down Expand Up @@ -319,6 +320,9 @@ class DeviceDetailsViewModelTest {
@MockK(relaxed = true)
lateinit var onSuccess: () -> Unit

@MockK
lateinit var isE2EIEnabledUseCase: IsE2EIEnabledUseCase

val currentUserId = UserId("currentUserId", "currentUserDomain")

val viewModel by lazy {
Expand All @@ -332,7 +336,8 @@ class DeviceDetailsViewModelTest {
currentUserId = currentUserId,
observeUserInfo = observeUserInfo,
e2eiCertificate = getE2eiCertificate,
enrolE2EICertificateUseCase = enrolE2EICertificateUseCase
enrolE2EICertificateUseCase = enrolE2EICertificateUseCase,
isE2EIEnabledUseCase = isE2EIEnabledUseCase
)
}

Expand All @@ -341,6 +346,7 @@ class DeviceDetailsViewModelTest {
withFingerprintSuccess()
coEvery { observeUserInfo(any()) } returns flowOf(GetUserInfoResult.Success(TestUser.OTHER_USER, null))
coEvery { getE2eiCertificate(any()) } returns GetE2EICertificateUseCaseResult.Failure.NotActivated
coEvery { isE2EIEnabledUseCase() } returns true
}

fun withUserRequiresPasswordResult(result: IsPasswordRequiredUseCase.Result = IsPasswordRequiredUseCase.Result.Success(true)) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.wire.kalium.logic.feature.client.ObserveClientsByUserIdUseCase
import com.wire.kalium.logic.feature.client.ObserveCurrentClientIdUseCase
import com.wire.kalium.logic.feature.client.SelfClientsResult
import com.wire.kalium.logic.feature.e2ei.usecase.GetUserE2eiCertificatesUseCase
import com.wire.kalium.logic.feature.user.IsE2EIEnabledUseCase
import io.mockk.coEvery
import io.mockk.MockKAnnotations
import io.mockk.impl.annotations.MockK
Expand Down Expand Up @@ -70,6 +71,9 @@ class SelfDevicesViewModelTest {
@MockK
lateinit var getUserE2eiCertificates: GetUserE2eiCertificatesUseCase

@MockK
lateinit var isE2EIEnabledUseCase: IsE2EIEnabledUseCase

val selfId = UserId("selfId", "domain")

private val viewModel by lazy {
Expand All @@ -78,7 +82,8 @@ class SelfDevicesViewModelTest {
currentAccountId = selfId,
currentClientIdUseCase = currentClientId,
fetchSelfClientsFromRemote = fetchSelfClientsFromRemote,
getUserE2eiCertificates = getUserE2eiCertificates
getUserE2eiCertificates = getUserE2eiCertificates,
isE2EIEnabledUseCase = isE2EIEnabledUseCase
)
}

Expand All @@ -95,6 +100,7 @@ class SelfDevicesViewModelTest {
)
)
coEvery { getUserE2eiCertificates.invoke(any()) } returns mapOf()
coEvery { isE2EIEnabledUseCase() } returns true
}

fun arrange() = this to viewModel
Expand Down

0 comments on commit ca11930

Please sign in to comment.