-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: add use case to decide if a user can create password protected invite links [WPB-1531] #1950
Merged
MohamadJaara
merged 7 commits into
feat/create-password-protected-invite-code/epic
from
feat/use-case-for-is-a-user-can-create-password-protected-guest-links
Aug 5, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
450cd7e
CanCreatePasswordProtectedLinksUseCase
MohamadJaara 6de5bf0
docs
MohamadJaara 85e0067
detekt
MohamadJaara 71f615c
test
MohamadJaara e29ac79
Update logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/conv…
MohamadJaara 389be5c
Merge branch 'develop' into feat/use-case-for-is-a-user-can-create-pa…
ohassine 50b235c
Merge branch 'feat/create-password-protected-invite-code/epic' into f…
MohamadJaara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...kalium/logic/feature/conversation/guestroomlink/CanCreatePasswordProtectedLinksUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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.conversation.guestroomlink | ||
|
||
import com.wire.kalium.logic.configuration.server.ServerConfigRepository | ||
import com.wire.kalium.logic.data.user.UserId | ||
import com.wire.kalium.logic.functional.fold | ||
|
||
/** | ||
* Use case to check if the current user can create password protected invite links. | ||
* This is only possible if the server api version is greater or equal to 4. | ||
*/ | ||
class CanCreatePasswordProtectedLinksUseCase internal constructor( | ||
private val serverConfigRepository: ServerConfigRepository, | ||
private val selfUserId: UserId | ||
) { | ||
suspend operator fun invoke(): Boolean = | ||
serverConfigRepository.configForUser(selfUserId).fold( | ||
{ false }, | ||
{ | ||
it.metaData.commonApiVersion.version >= MIN_API_TO_SUPPORT_PASSWORD_LINKS | ||
} | ||
) | ||
|
||
private companion object { | ||
const val MIN_API_TO_SUPPORT_PASSWORD_LINKS = 4 | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
...um/logic/feature/conversation/guestroomlink/CanCreatePasswordProtectedLinksUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* 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.conversation.guestroomlink | ||
|
||
import com.wire.kalium.logic.configuration.server.CommonApiVersionType | ||
import com.wire.kalium.logic.data.user.UserId | ||
import com.wire.kalium.logic.functional.Either | ||
import com.wire.kalium.logic.util.arrangement.repository.ServerConfigRepositoryArrangement | ||
import com.wire.kalium.logic.util.arrangement.repository.ServerConfigRepositoryArrangementImpl | ||
import com.wire.kalium.logic.util.stubs.newServerConfig | ||
import io.mockative.eq | ||
import io.mockative.once | ||
import io.mockative.verify | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertTrue | ||
|
||
class CanCreatePasswordProtectedLinksUseCaseTest { | ||
|
||
@Test | ||
fun givenApiIs4_whenInvokingUseCase_thenReturnTrue() = runTest { | ||
val expected = newServerConfig(1).let { | ||
it.copy(metaData = it.metaData.copy(commonApiVersion = CommonApiVersionType.Valid(4))) | ||
} | ||
val (arrangement, useCase) = Arrangement().arrange { | ||
withServerConfigForUser(Either.Right(expected)) | ||
} | ||
|
||
useCase().also { | ||
assertTrue(it) | ||
} | ||
|
||
verify(arrangement.serverConfigRepository) | ||
.suspendFunction(arrangement.serverConfigRepository::configForUser) | ||
.with(eq(SELF_USER_ID)) | ||
.wasInvoked(exactly = once) | ||
} | ||
|
||
@Test | ||
fun givenApiIsGraterThan4_whenInvokingUseCase_thenReturnTrue() = runTest { | ||
val expected = newServerConfig(1).let { | ||
it.copy(metaData = it.metaData.copy(commonApiVersion = CommonApiVersionType.Valid(5))) | ||
} | ||
val (arrangement, useCase) = Arrangement().arrange { | ||
withServerConfigForUser(Either.Right(expected)) | ||
} | ||
|
||
useCase().also { | ||
assertTrue(it) | ||
} | ||
|
||
verify(arrangement.serverConfigRepository) | ||
.suspendFunction(arrangement.serverConfigRepository::configForUser) | ||
.with(eq(SELF_USER_ID)) | ||
.wasInvoked(exactly = once) | ||
} | ||
|
||
@Test | ||
fun givenApiIsLessThan4_whenInvokingUseCase_thenReturnFalse() = runTest { | ||
val expected = newServerConfig(1).let { | ||
it.copy(metaData = it.metaData.copy(commonApiVersion = CommonApiVersionType.Valid(3))) | ||
} | ||
val (arrangement, useCase) = Arrangement().arrange { | ||
withServerConfigForUser(Either.Right(expected)) | ||
} | ||
|
||
useCase().also { | ||
assertFalse(it) | ||
} | ||
|
||
verify(arrangement.serverConfigRepository) | ||
.suspendFunction(arrangement.serverConfigRepository::configForUser) | ||
.with(eq(SELF_USER_ID)) | ||
.wasInvoked(exactly = once) | ||
} | ||
|
||
private companion object { | ||
val SELF_USER_ID = UserId("selfUser", "domain") | ||
} | ||
private class Arrangement : ServerConfigRepositoryArrangement by ServerConfigRepositoryArrangementImpl() { | ||
|
||
private val useCase: CanCreatePasswordProtectedLinksUseCase = CanCreatePasswordProtectedLinksUseCase( | ||
serverConfigRepository, | ||
SELF_USER_ID | ||
) | ||
|
||
fun arrange(block: Arrangement.() -> Unit): Pair<Arrangement, CanCreatePasswordProtectedLinksUseCase> { | ||
apply(block) | ||
return this to useCase | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...in/com/wire/kalium/logic/util/arrangement/repository/ServerConfigRepositoryArrangement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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.util.arrangement.repository | ||
|
||
import com.wire.kalium.logic.StorageFailure | ||
import com.wire.kalium.logic.configuration.server.ServerConfig | ||
import com.wire.kalium.logic.configuration.server.ServerConfigRepository | ||
import com.wire.kalium.logic.data.user.UserId | ||
import com.wire.kalium.logic.functional.Either | ||
import io.mockative.Mock | ||
import io.mockative.any | ||
import io.mockative.given | ||
import io.mockative.matchers.Matcher | ||
import io.mockative.mock | ||
|
||
internal interface ServerConfigRepositoryArrangement { | ||
@Mock | ||
val serverConfigRepository: ServerConfigRepository | ||
|
||
fun withServerConfigForUser( | ||
result: Either<StorageFailure, ServerConfig>, | ||
userId: Matcher<UserId> = any() | ||
) { | ||
given(serverConfigRepository) | ||
.suspendFunction(serverConfigRepository::configForUser) | ||
.whenInvokedWith(userId) | ||
.then { result } | ||
} | ||
} | ||
|
||
internal class ServerConfigRepositoryArrangementImpl : ServerConfigRepositoryArrangement { | ||
|
||
@Mock | ||
override val serverConfigRepository: ServerConfigRepository = mock(ServerConfigRepository::class) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!