Skip to content

Commit 3e9e0db

Browse files
authored
fix: Allow multiple account with same username (#1012) (#1013)
* fix: Allow multiple account with same username Allow multiple source control accounts to use same username if they are not using the same provider * fix: Use provider name for clone using description This prevent the description from always says `New repositories will be cloned from GitHub using` * refactor: Check git provider & username instead of `id` This is to prevent changes to the `id` format braking the old accounts added in earlier versions
1 parent 256ec5c commit 3e9e0db

5 files changed

Lines changed: 42 additions & 15 deletions

File tree

CodeEdit/Features/AppPreferences/Sections/AccountsPreferences/AccountPreferencesView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ struct AccountPreferencesView: View {
8888
.padding(.bottom, 5)
8989

9090
PreferencesSection("Clone Using", width: 100) {
91+
let account = getSourceControlAccount(selectedAccountId: accountSelection ?? "")
92+
9193
Picker("", selection: $cloneUsing) {
9294
Text("HTTPS")
9395
.tag(false) // temporary
@@ -96,7 +98,8 @@ struct AccountPreferencesView: View {
9698
}
9799
.pickerStyle(.radioGroup)
98100

99-
Text("New repositories will be cloned from GitHub using \(cloneUsing ? "SSH" : "HTTPS").")
101+
Text("New repositories will be cloned from \(account?.gitProviderDescription ?? "")"
102+
+ " using \(cloneUsing ? "SSH" : "HTTPS").")
100103
.lineLimit(2)
101104
.font(.system(size: 11))
102105
.foregroundColor(Color.secondary)

CodeEdit/Features/AppPreferences/Sections/AccountsPreferences/Accounts/Login/Github/GitHubEnterpriseLoginView.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,18 @@ struct GitHubEnterpriseLoginView: View {
8686
GitHubAccount(config).me { response in
8787
switch response {
8888
case .success(let user):
89-
if gitAccounts.contains(where: { $0.id == gitAccountName.lowercased() }) {
90-
print("Account with the username already exists!")
89+
if gitAccounts.contains(
90+
where: {
91+
$0.gitProviderLink == eneterpriseLink &&
92+
$0.gitAccountName.lowercased() == gitAccountName.lowercased()
93+
}
94+
) {
95+
print("Account with the username and provider already exists!")
9196
} else {
9297
print(user)
9398
prefs.preferences.accounts.sourceControlAccounts.gitAccount.append(
9499
SourceControlAccounts(
95-
id: gitAccountName.lowercased(),
100+
id: "\(eneterpriseLink)_\(gitAccountName.lowercased())",
96101
gitProvider: "GitHub",
97102
gitProviderLink: eneterpriseLink,
98103
gitProviderDescription: "GitHub",

CodeEdit/Features/AppPreferences/Sections/AccountsPreferences/Accounts/Login/Github/GitHubLoginView.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,25 @@ struct GitHubLoginView: View {
106106
let gitAccounts = prefs.preferences.accounts.sourceControlAccounts.gitAccount
107107

108108
let config = GitHubTokenConfiguration(accountToken)
109+
110+
let providerLink = "https://github.com"
109111
GitHubAccount(config).me { response in
110112
switch response {
111113
case .success(let user):
112-
if gitAccounts.contains(where: { $0.id == gitAccountName.lowercased() }) {
113-
print("Account with the username already exists!")
114+
if gitAccounts.contains(
115+
where: {
116+
$0.gitProviderLink == providerLink &&
117+
$0.gitAccountName.lowercased() == gitAccountName.lowercased()
118+
}
119+
) {
120+
print("Account with the username and provider already exists!")
114121
} else {
115122
print(user)
116123
prefs.preferences.accounts.sourceControlAccounts.gitAccount.append(
117124
SourceControlAccounts(
118-
id: gitAccountName.lowercased(),
125+
id: "\(providerLink)_\(gitAccountName.lowercased())",
119126
gitProvider: "GitHub",
120-
gitProviderLink: "https://github.com",
127+
gitProviderLink: providerLink,
121128
gitProviderDescription: "GitHub",
122129
gitAccountName: gitAccountName,
123130
gitCloningProtocol: true,

CodeEdit/Features/AppPreferences/Sections/AccountsPreferences/Accounts/Login/Gitlab/GitLabHostedLoginView.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,18 @@ struct GitLabHostedLoginView: View {
8282
GitLabAccount(config).me { response in
8383
switch response {
8484
case .success(let user):
85-
if gitAccounts.contains(where: { $0.id == gitAccountName.lowercased() }) {
86-
print("Account with the username already exists!")
85+
if gitAccounts.contains(
86+
where: {
87+
$0.gitProviderLink == eneterpriseLink &&
88+
$0.gitAccountName.lowercased() == gitAccountName.lowercased()
89+
}
90+
) {
91+
print("Account with the username and provider already exists!")
8792
} else {
8893
print(user)
8994
prefs.preferences.accounts.sourceControlAccounts.gitAccount.append(
9095
SourceControlAccounts(
91-
id: gitAccountName.lowercased(),
96+
id: "\(eneterpriseLink)_\(gitAccountName.lowercased())",
9297
gitProvider: "GitLab",
9398
gitProviderLink: eneterpriseLink,
9499
gitProviderDescription: "GitLab",

CodeEdit/Features/AppPreferences/Sections/AccountsPreferences/Accounts/Login/Gitlab/GitLabLoginView.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,25 @@ struct GitLabLoginView: View {
7474
let gitAccounts = prefs.preferences.accounts.sourceControlAccounts.gitAccount
7575

7676
let config = GitLabTokenConfiguration(accountToken)
77+
78+
let providerLink = "https://gitlab.com"
7779
GitLabAccount(config).me { response in
7880
switch response {
7981
case .success(let user):
80-
if gitAccounts.contains(where: { $0.id == gitAccountName.lowercased() }) {
81-
print("Account with the username already exists!")
82+
if gitAccounts.contains(
83+
where: {
84+
$0.gitProviderLink == providerLink &&
85+
$0.gitAccountName.lowercased() == gitAccountName.lowercased()
86+
}
87+
) {
88+
print("Account with the username and provider already exists!")
8289
} else {
8390
print(user)
8491
prefs.preferences.accounts.sourceControlAccounts.gitAccount.append(
8592
SourceControlAccounts(
86-
id: gitAccountName.lowercased(),
93+
id: "\(providerLink)_\(gitAccountName.lowercased())",
8794
gitProvider: "GitLab",
88-
gitProviderLink: "https://gitlab.com",
95+
gitProviderLink: providerLink,
8996
gitProviderDescription: "GitLab",
9097
gitAccountName: gitAccountName,
9198
gitCloningProtocol: true,

0 commit comments

Comments
 (0)