mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
[gitlab] Consider server URIs starting with HTTP/HTTPS the same (IJPL-148811)
GitOrigin-RevId: 6de72d9a4260e63bd515ff7ef46d47f20d32eb4d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6e93f5d72d
commit
d7013bf733
@@ -4,6 +4,7 @@ package org.jetbrains.plugins.gitlab.api
|
||||
import com.intellij.collaboration.api.ServerPath
|
||||
import com.intellij.collaboration.util.resolveRelative
|
||||
import com.intellij.openapi.util.NlsSafe
|
||||
import com.intellij.util.withScheme
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.net.URI
|
||||
import java.net.URL
|
||||
@@ -60,4 +61,12 @@ class GitLabServerPath : ServerPath {
|
||||
companion object {
|
||||
val DEFAULT_SERVER = GitLabServerPath("https://gitlab.com")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URI for this server path with HTTP schemas replaced with HTTPS.
|
||||
*/
|
||||
internal fun GitLabServerPath.toHttpsNormalizedURI(): URI {
|
||||
val uri = toURI()
|
||||
return uri.withScheme(if (uri.scheme == "http") "https" else uri.scheme)
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import com.intellij.util.asSafely
|
||||
import com.intellij.util.concurrency.annotations.RequiresEdt
|
||||
import org.jetbrains.annotations.Nls
|
||||
import org.jetbrains.plugins.gitlab.api.GitLabServerPath
|
||||
import org.jetbrains.plugins.gitlab.api.toHttpsNormalizedURI
|
||||
import org.jetbrains.plugins.gitlab.authentication.accounts.GitLabAccount
|
||||
import org.jetbrains.plugins.gitlab.authentication.accounts.GitLabProjectDefaultAccountHolder
|
||||
import org.jetbrains.plugins.gitlab.authentication.ui.GitLabChooseAccountDialog
|
||||
@@ -127,7 +128,7 @@ object GitLabLoginUtil {
|
||||
}
|
||||
|
||||
fun isAccountUnique(accounts: Collection<GitLabAccount>, server: GitLabServerPath, username: String): Boolean =
|
||||
accounts.none { it.server == server && it.name == username }
|
||||
accounts.none { it.server.toHttpsNormalizedURI() == server.toHttpsNormalizedURI() && it.name == username }
|
||||
}
|
||||
|
||||
sealed interface LoginResult {
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import org.jetbrains.plugins.gitlab.api.GitLabServerPath
|
||||
import org.jetbrains.plugins.gitlab.api.toHttpsNormalizedURI
|
||||
import org.jetbrains.plugins.gitlab.util.GitLabUtil
|
||||
|
||||
internal interface GitLabAccountManager : AccountManager<GitLabAccount, String>, Disposable {
|
||||
@@ -31,7 +32,7 @@ class PersistentGitLabAccountManager :
|
||||
|
||||
override fun isAccountUnique(server: GitLabServerPath, accountName: String): Boolean {
|
||||
return accountsState.value.none { account: GitLabAccount ->
|
||||
account.server == server && account.name == accountName
|
||||
account.server.toHttpsNormalizedURI() == server.toHttpsNormalizedURI() && account.name == accountName
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.jetbrains.plugins.gitlab.GitLabServersManager
|
||||
import org.jetbrains.plugins.gitlab.api.GitLabServerPath
|
||||
import org.jetbrains.plugins.gitlab.api.toHttpsNormalizedURI
|
||||
import org.jetbrains.plugins.gitlab.authentication.GitLabLoginUtil
|
||||
import org.jetbrains.plugins.gitlab.authentication.LoginResult
|
||||
import org.jetbrains.plugins.gitlab.authentication.accounts.GitLabAccountManager
|
||||
@@ -69,7 +70,7 @@ private suspend fun findKnownMatchingServer(url: String): GitLabServerPath? {
|
||||
private suspend fun getLoginResult(project: Project, url: String, server: GitLabServerPath, login: String?): LoginResult {
|
||||
val accountManager = service<GitLabAccountManager>()
|
||||
val accountsWithTokens = accountManager.accountsState.value
|
||||
.filter { it.server == server }
|
||||
.filter { it.server.toHttpsNormalizedURI() == server.toHttpsNormalizedURI() }
|
||||
.associateWith { accountManager.findCredentials(it) }
|
||||
|
||||
val loginResult = withContext(Dispatchers.EDT + ModalityState.any().asContextElement()) {
|
||||
|
||||
Reference in New Issue
Block a user