Skip to content
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

Use Uri for checks in GetAccounts function #8

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Speckle.Core/Credentials/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,25 @@ public static async Task UpgradeAccount(string id)
await s_accountStorage.WriteComplete().ConfigureAwait(false);
}

public static IEnumerable<Account> GetAccounts(string serverUrl)
{
return GetAccounts(new Uri(serverUrl));
}

/// <summary>
/// Returns all unique accounts matching the serverUrl provided. If an account exists on more than one server,
/// typically because it has been migrated, then only the upgraded account (and therefore server) are returned.
/// Accounts are deemed to be the same when the Account.Id matches.
/// </summary>
/// <param name="serverUrl"></param>
/// <returns></returns>
public static IEnumerable<Account> GetAccounts(string serverUrl)
/// <param name="serverUrl">Uri for server.</param>
public static IEnumerable<Account> GetAccounts(Uri serverUrl)
{
var accounts = GetAccounts().ToList();
List<Account> filtered = new();

foreach (var acc in accounts)
{
if (acc.serverInfo?.migration?.movedFrom == new Uri(serverUrl))
if (acc.serverInfo?.migration?.movedFrom == serverUrl)
{
filtered.Add(acc);
}
Expand All @@ -296,7 +300,7 @@ public static IEnumerable<Account> GetAccounts(string serverUrl)
{
// we use the userInfo to detect the same account rather than the account.id
// which should NOT match for essentially the same accounts but on different servers - i.e. FE1 & FE2
if (acc.serverInfo.url == serverUrl && !filtered.Any(x => x.userInfo.id == acc.userInfo.id))
if (new Uri(acc.serverInfo.url) == serverUrl && !filtered.Any(x => x.userInfo.id == acc.userInfo.id))
{
filtered.Add(acc);
}
Expand Down
Loading