-
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: new login use case chooser for context enterprise vs fallback (WPB-15966) #3287
Merged
yamilmedina
merged 11 commits into
epic/new-sso-login-flow
from
feat/new-login-oldnewversion-usecase
Feb 14, 2025
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
91c2572
feat: create use case to observe current user server config
yamilmedina 5202e39
chore: cleanup code for not needed funtions
yamilmedina d8dedbf
feat: use case to get the login context based on api version and proxy
yamilmedina 2ee2d00
feat: load login context based on api and proxy
yamilmedina a540005
feat: detekt
yamilmedina bef8b41
feat: address pr comments
yamilmedina 3032a2b
chore: fix test
yamilmedina d06b0b9
chore: fix test
yamilmedina 6009969
chore: add more tests
yamilmedina 1d30e8d
chore: add more tests
yamilmedina 70d4290
Merge branch 'epic/new-sso-login-flow' into feat/new-login-oldnewvers…
yamilmedina 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
104 changes: 104 additions & 0 deletions
104
...Main/kotlin/com/wire/kalium/logic/configuration/server/ServerConfigRepositoryExtension.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,104 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2025 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.configuration.server | ||
|
||
import com.benasher44.uuid.uuid4 | ||
import com.wire.kalium.logic.CoreFailure | ||
import com.wire.kalium.logic.StorageFailure | ||
import com.wire.kalium.logic.failure.ServerConfigFailure | ||
import com.wire.kalium.logic.functional.Either | ||
import com.wire.kalium.logic.functional.flatMap | ||
import com.wire.kalium.logic.functional.map | ||
import com.wire.kalium.logic.wrapApiRequest | ||
import com.wire.kalium.logic.wrapStorageRequest | ||
import com.wire.kalium.network.api.base.unbound.versioning.VersionApi | ||
import com.wire.kalium.network.api.unbound.configuration.ApiVersionDTO | ||
import com.wire.kalium.persistence.daokaliumdb.ServerConfigurationDAO | ||
import io.ktor.http.Url | ||
|
||
/** | ||
* Common operations for the server configuration repository. | ||
*/ | ||
internal abstract class ServerConfigRepositoryExtension( | ||
open val versionApi: VersionApi, | ||
open val serverConfigurationDAO: ServerConfigurationDAO, | ||
open val serverConfigMapper: ServerConfigMapper, | ||
) { | ||
|
||
suspend fun storeServerLinksAndMetadata( | ||
links: ServerConfig.Links, | ||
metadata: ServerConfig.MetaData | ||
): Either<StorageFailure, ServerConfig> = | ||
wrapStorageRequest { | ||
// check if such config is already inserted | ||
val storedConfigId = serverConfigurationDAO.configByLinks(serverConfigMapper.toEntity(links))?.id | ||
if (storedConfigId != null) { | ||
// if already exists then just update it | ||
serverConfigurationDAO.updateServerMetaData( | ||
id = storedConfigId, | ||
federation = metadata.federation, | ||
commonApiVersion = metadata.commonApiVersion.version | ||
) | ||
if (metadata.federation) serverConfigurationDAO.setFederationToTrue(storedConfigId) | ||
storedConfigId | ||
} else { | ||
// otherwise insert new config | ||
val newId = uuid4().toString() | ||
serverConfigurationDAO.insert( | ||
ServerConfigurationDAO.InsertData( | ||
id = newId, | ||
apiBaseUrl = links.api, | ||
accountBaseUrl = links.accounts, | ||
webSocketBaseUrl = links.webSocket, | ||
blackListUrl = links.blackList, | ||
teamsUrl = links.teams, | ||
websiteUrl = links.website, | ||
isOnPremises = links.isOnPremises, | ||
title = links.title, | ||
federation = metadata.federation, | ||
domain = metadata.domain, | ||
commonApiVersion = metadata.commonApiVersion.version, | ||
apiProxyHost = links.apiProxy?.host, | ||
apiProxyNeedsAuthentication = links.apiProxy?.needsAuthentication, | ||
apiProxyPort = links.apiProxy?.port | ||
) | ||
) | ||
newId | ||
} | ||
}.flatMap { storedConfigId -> | ||
wrapStorageRequest { serverConfigurationDAO.configById(storedConfigId) } | ||
}.map { | ||
serverConfigMapper.fromEntity(it) | ||
} | ||
|
||
suspend fun fetchMetadata(serverLinks: ServerConfig.Links): Either<CoreFailure, ServerConfig.MetaData> = | ||
wrapApiRequest { versionApi.fetchApiVersion(Url(serverLinks.api)) } | ||
.flatMap { | ||
when (it.commonApiVersion) { | ||
ApiVersionDTO.Invalid.New -> Either.Left(ServerConfigFailure.NewServerVersion) | ||
ApiVersionDTO.Invalid.Unknown -> Either.Left(ServerConfigFailure.UnknownServerVersion) | ||
is ApiVersionDTO.Valid -> Either.Right(it) | ||
} | ||
}.map { serverConfigMapper.fromDTO(it) } | ||
|
||
suspend fun fetchApiVersionAndStore(links: ServerConfig.Links): Either<CoreFailure, ServerConfig> = | ||
fetchMetadata(links) | ||
.flatMap { metaData -> | ||
storeServerLinksAndMetadata(links, metaData) | ||
} | ||
} |
Oops, something went wrong.
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.
We missed to cover this class with test
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.
Good point, in fact these are covered by the classes extending this one
ServerConfigDataSource
andCustomServerConfigDataSource
, so they are covered as can be seen here. https://app.codecov.io/gh/wireapp/kalium/pull/3287/blob/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/server/ServerConfigRepositoryExtension.ktBut, there is one actually missing for the new function in CustomServerConfigDataSource
observeServerConfigByLinks
I will add one to cover this.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.
Yeah but it's unclear exactly what is being tested, we are only sure that the test runs through those lines of code.
We need to isolate the class during testing. This way, we can validate its behavior independently, without interference from external classes/dependencies, ensuring that it behaves correctly in all cases.
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.
I can take a look at a later point since this is the epic still, but the problem with this is, given is an abstract class, it is not straight forward to test, and the functions are covered indeed by the inherited testable classes