Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/e2ei/upgrade_cc_1.0.0-pre.6…
Browse files Browse the repository at this point in the history
…' into feat/e2ei/upgrade_cc_1.0.0-pre.6
  • Loading branch information
mchenani committed Jul 19, 2023
2 parents 15c5a80 + f3765fa commit 7ffe5c8
Show file tree
Hide file tree
Showing 32 changed files with 594 additions and 59 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/cherry-pick-rc-to-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "Cherry-pick from rc to develop"

on:
pull_request:
branches:
- release/candidate
types:
- closed

jobs:
cherry-pick:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Append -cherry-pick to branch name
id: extract
run: |
PR_BRANCH="${{ github.event.pull_request.head.ref }}"
NEW_BRANCH_NAME="${PR_BRANCH}-cherry-pick"
echo "New branch name: $NEW_BRANCH_NAME"
echo "::set-output name=newBranchName::$NEW_BRANCH_NAME"
- uses: fregante/setup-git-user@v2

- name: Cherry-pick commits
run: |
git fetch origin develop:develop
git checkout -b ${{ steps.extract.outputs.newBranchName }} develop
# Cherry-picking the last commit on the base branch
git cherry-pick ${{ github.event.pull_request.merge_commit_sha }} --strategy-option theirs || true
git add .
git cherry-pick --continue || true
git push origin ${{ steps.extract.outputs.newBranchName }}
- name: Create PR
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BRANCH: ${{ steps.extract.outputs.newBranchName }}
PR_ASSIGNEE: ${{ github.event.pull_request.user.login }}
PR_BODY: "${{ format('Cherry pick from the original PR: \n- #{0}\n\n ---- \n{1}', github.event.pull_request.number, github.event.pull_request.body) }}"
run: gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base develop --head $PR_BRANCH --label "cherry-pick" --assignee "$PR_ASSIGNEE"
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ interface UserConfigRepository {
fun setGuestRoomStatus(status: Boolean, isStatusChanged: Boolean?): Either<StorageFailure, Unit>
fun getGuestRoomLinkStatus(): Either<StorageFailure, GuestRoomLinkStatus>
fun observeGuestRoomLinkFeatureFlag(): Flow<Either<StorageFailure, GuestRoomLinkStatus>>
suspend fun setScreenshotCensoringConfig(enabled: Boolean): Either<StorageFailure, Unit>
suspend fun observeScreenshotCensoringConfig(): Flow<Either<StorageFailure, Boolean>>

suspend fun getTeamSettingsSelfDeletionStatus(): Either<StorageFailure, TeamSettingsSelfDeletionStatus>
suspend fun setTeamSettingsSelfDeletionStatus(
Expand Down Expand Up @@ -247,4 +249,10 @@ class UserConfigDataSource(
)
}
}

override suspend fun setScreenshotCensoringConfig(enabled: Boolean): Either<StorageFailure, Unit> =
wrapStorageRequest { userConfigStorage.persistScreenshotCensoring(enabled) }

override suspend fun observeScreenshotCensoringConfig(): Flow<Either<StorageFailure, Boolean>> =
userConfigStorage.isScreenshotCensoringEnabledFlow().wrapStorageRequest()
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.wire.kalium.persistence.dao.client.ClientTypeEntity
import com.wire.kalium.persistence.dao.client.DeviceTypeEntity
import com.wire.kalium.persistence.dao.client.InsertClientParam
import com.wire.kalium.persistence.dao.newclient.NewClientEntity
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import com.wire.kalium.network.api.base.model.UserId as UserIdDTO
import com.wire.kalium.persistence.dao.client.Client as ClientEntity
Expand Down Expand Up @@ -64,6 +65,7 @@ class ClientMapper(
id = ClientId(client.clientId),
type = fromClientTypeDTO(client.type),
registrationTime = Instant.parse(client.registrationTime),
lastActive = client.lastActive?.let { Instant.parse(it).coerceAtMost(Clock.System.now()) },
deviceType = fromDeviceTypeDTO(client.deviceType),
label = client.label,
model = client.model,
Expand All @@ -76,6 +78,7 @@ class ClientMapper(
id = ClientId(id),
type = clientType?.let { fromClientTypeEntity(it) },
registrationTime = registrationDate,
lastActive = lastActive,
deviceType = deviceType?.let { fromDeviceTypeEntity(deviceType) },
label = label,
model = model,
Expand All @@ -89,6 +92,7 @@ class ClientMapper(
id = ClientId(id),
type = null,
registrationTime = registrationDate,
lastActive = null,
deviceType = deviceType?.let { fromDeviceTypeEntity(deviceType) },
label = null,
model = model,
Expand All @@ -107,7 +111,8 @@ class ClientMapper(
clientType = null,
label = null,
model = null,
registrationDate = null
registrationDate = null,
lastActive = null
)
}
}
Expand All @@ -121,7 +126,8 @@ class ClientMapper(
clientType = toClientTypeEntity(type),
label = label,
model = model,
registrationDate = Instant.parse(registrationTime)
registrationDate = Instant.parse(registrationTime),
lastActive = lastActive?.let { Instant.parse(it).coerceAtMost(Clock.System.now()) }
)
}

Expand All @@ -134,7 +140,8 @@ class ClientMapper(
clientType = null,
label = null,
model = null,
registrationDate = null
registrationDate = null,
lastActive = null
)
}

Expand All @@ -146,7 +153,8 @@ class ClientMapper(
clientType = event.client.type?.let { toClientTypeEntity(it) },
label = event.client.label,
model = event.client.model,
registrationDate = event.client.registrationTime
registrationDate = event.client.registrationTime,
lastActive = event.client.lastActive
)

private fun toClientTypeDTO(clientType: ClientType): ClientTypeDTO = when (clientType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ data class DeleteClientParam(
data class Client(
val id: ClientId,
val type: ClientType?,
val registrationTime: Instant?, // yyyy-mm-ddThh:MM:ss.qqq
/**
* Time when client was registered / created.
*/
val registrationTime: Instant?,
/**
* last time the client was active.
*
* Note that the timestamp has reduced precision, it's only safe
* to operate on the precision of weeks.
* */
val lastActive: Instant?,
val isVerified: Boolean,
val isValid: Boolean,
val deviceType: DeviceType?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ import com.wire.kalium.logic.feature.user.guestroomlink.MarkGuestLinkFeatureFlag
import com.wire.kalium.logic.feature.user.guestroomlink.MarkGuestLinkFeatureFlagAsNotChangedUseCaseImpl
import com.wire.kalium.logic.feature.user.guestroomlink.ObserveGuestRoomLinkFeatureFlagUseCase
import com.wire.kalium.logic.feature.user.guestroomlink.ObserveGuestRoomLinkFeatureFlagUseCaseImpl
import com.wire.kalium.logic.feature.user.screenshotCensoring.ObserveScreenshotCensoringConfigUseCase
import com.wire.kalium.logic.feature.user.screenshotCensoring.ObserveScreenshotCensoringConfigUseCaseImpl
import com.wire.kalium.logic.feature.user.screenshotCensoring.PersistScreenshotCensoringConfigUseCase
import com.wire.kalium.logic.feature.user.screenshotCensoring.PersistScreenshotCensoringConfigUseCaseImpl
import com.wire.kalium.logic.feature.user.webSocketStatus.GetPersistentWebSocketStatus
import com.wire.kalium.logic.feature.user.webSocketStatus.GetPersistentWebSocketStatusImpl
import com.wire.kalium.logic.feature.user.webSocketStatus.PersistPersistentWebSocketConnectionStatusUseCase
Expand Down Expand Up @@ -1350,6 +1354,12 @@ class UserSessionScope internal constructor(
val getOtherUserSecurityClassificationLabel: GetOtherUserSecurityClassificationLabelUseCase
get() = GetOtherUserSecurityClassificationLabelUseCaseImpl(userConfigRepository)

val persistScreenshotCensoringConfig: PersistScreenshotCensoringConfigUseCase
get() = PersistScreenshotCensoringConfigUseCaseImpl(userConfigRepository = userConfigRepository)

val observeScreenshotCensoringConfig: ObserveScreenshotCensoringConfigUseCase
get() = ObserveScreenshotCensoringConfigUseCaseImpl(userConfigRepository = userConfigRepository)

val kaliumFileSystem: KaliumFileSystem by lazy {
// Create the cache and asset storage directories
KaliumFileSystemImpl(dataStoragePaths).also {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

package com.wire.kalium.logic.feature.user.screenshotCensoring

import com.wire.kalium.logic.configuration.UserConfigRepository
import com.wire.kalium.logic.feature.selfDeletingMessages.TeamSelfDeleteTimer
import com.wire.kalium.logic.functional.mapRight
import com.wire.kalium.logic.functional.mapToRightOr
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine

/**
* UseCase that allow us to get the configuration of screenshot censoring enabled or not
*/
interface ObserveScreenshotCensoringConfigUseCase {
suspend operator fun invoke(): Flow<ObserveScreenshotCensoringConfigResult>
}

internal class ObserveScreenshotCensoringConfigUseCaseImpl(
private val userConfigRepository: UserConfigRepository,
) : ObserveScreenshotCensoringConfigUseCase {

override suspend fun invoke(): Flow<ObserveScreenshotCensoringConfigResult> {
return combine(
userConfigRepository.observeScreenshotCensoringConfig()
.mapToRightOr(true), // for safety it's set to true if we can't determine it
userConfigRepository.observeTeamSettingsSelfDeletingStatus()
.mapRight { it.enforcedSelfDeletionTimer is TeamSelfDeleteTimer.Enforced }
.mapToRightOr(true), // for safety it's set to true if we can't determine it
) { screenshotCensoringEnabled, teamSelfDeletingEnforced ->
when {
teamSelfDeletingEnforced -> ObserveScreenshotCensoringConfigResult.Enabled.EnforcedByTeamSelfDeletingSettings
screenshotCensoringEnabled -> ObserveScreenshotCensoringConfigResult.Enabled.ChosenByUser
else -> ObserveScreenshotCensoringConfigResult.Disabled
}
}
}
}

sealed class ObserveScreenshotCensoringConfigResult {
object Disabled : ObserveScreenshotCensoringConfigResult()
sealed class Enabled : ObserveScreenshotCensoringConfigResult() {
object ChosenByUser : Enabled()
object EnforcedByTeamSelfDeletingSettings : Enabled()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

package com.wire.kalium.logic.feature.user.screenshotCensoring

import com.wire.kalium.logger.KaliumLogger.Companion.ApplicationFlow.LOCAL_STORAGE
import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.configuration.UserConfigRepository
import com.wire.kalium.logic.functional.fold
import com.wire.kalium.logic.kaliumLogger

/**
* UseCase that allow us to persist the configuration of screenshot censoring to enabled or not
*/
interface PersistScreenshotCensoringConfigUseCase {
suspend operator fun invoke(enabled: Boolean): PersistScreenshotCensoringConfigResult
}

internal class PersistScreenshotCensoringConfigUseCaseImpl(
private val userConfigRepository: UserConfigRepository,
) : PersistScreenshotCensoringConfigUseCase {

private val logger by lazy { kaliumLogger.withFeatureId(LOCAL_STORAGE) }

override suspend fun invoke(enabled: Boolean): PersistScreenshotCensoringConfigResult =
userConfigRepository.setScreenshotCensoringConfig(enabled)
.fold({
logger.e("Failed trying to update screenshot censoring configuration")
PersistScreenshotCensoringConfigResult.Failure(it)
}) {
PersistScreenshotCensoringConfigResult.Success
}
}

sealed class PersistScreenshotCensoringConfigResult {
object Success : PersistScreenshotCensoringConfigResult()
data class Failure(val cause: CoreFailure) : PersistScreenshotCensoringConfigResult()
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import kotlin.contracts.contract
import kotlin.time.Duration
import kotlin.time.Duration.Companion.ZERO

private const val DAYS_IN_WEEK = 7

val Duration.inWholeWeeks: Long
get() = inWholeDays / DAYS_IN_WEEK

@OptIn(ExperimentalContracts::class)
fun Duration?.isPositiveNotNull(): Boolean {
contract {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class ClientRepositoryTest {
clientId = "client_id_1",
type = ClientTypeDTO.Permanent,
registrationTime = "1969-05-12T10:52:02.671Z",
lastActive = "1969-05-12T10:52:02.671Z",
deviceType = DeviceTypeDTO.Desktop,
label = null,
model = "Mac ox",
Expand All @@ -261,6 +262,7 @@ class ClientRepositoryTest {
clientId = "client_id_2",
type = ClientTypeDTO.Permanent,
registrationTime = "2021-05-12T10:52:02.671Z",
lastActive = "2021-05-12T10:52:02.671Z",
deviceType = DeviceTypeDTO.Phone,
label = null,
model = "iphone 15",
Expand All @@ -279,6 +281,7 @@ class ClientRepositoryTest {
id = PlainId(value = "client_id_1"),
type = ClientType.Permanent,
registrationTime = Instant.parse("1969-05-12T10:52:02.671Z"),
lastActive = Instant.parse("1969-05-12T10:52:02.671Z"),
deviceType = DeviceType.Desktop,
label = null,
model = "Mac ox",
Expand All @@ -289,6 +292,7 @@ class ClientRepositoryTest {
id = PlainId(value = "client_id_2"),
type = ClientType.Permanent,
registrationTime = Instant.parse("2021-05-12T10:52:02.671Z"),
lastActive = Instant.parse("2021-05-12T10:52:02.671Z"),
deviceType = DeviceType.Phone,
label = null,
model = "iphone 15",
Expand Down Expand Up @@ -349,6 +353,7 @@ class ClientRepositoryTest {
id = "client-id",
clientType = ClientTypeEntity.Permanent,
registrationDate = null,
lastActive = null,
deviceType = DeviceTypeEntity.Desktop,
label = null,
model = null,
Expand All @@ -363,6 +368,7 @@ class ClientRepositoryTest {
id = ClientId("client-id"),
type = ClientType.Permanent,
registrationTime = null,
lastActive = null,
deviceType = DeviceType.Desktop,
label = null,
model = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ class ConversationRepositoryTest {
true,
null,
null,
null,
null
)
)
Expand Down
Loading

0 comments on commit 7ffe5c8

Please sign in to comment.