From 9a3e68930367949c15a77370f5c4f83582f05634 Mon Sep 17 00:00:00 2001 From: BovineOx <73857041+BovineOx@users.noreply.github.com> Date: Tue, 12 Mar 2024 20:49:01 +0100 Subject: [PATCH] Fixing account equality (#3220) Fixing account equality --- Core/Core/Credentials/AccountManager.cs | 9 +++++++-- .../Credentials/AccountServerMigrationTests.cs | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Core/Core/Credentials/AccountManager.cs b/Core/Core/Credentials/AccountManager.cs index c6fb027a6f..66888f0325 100644 --- a/Core/Core/Credentials/AccountManager.cs +++ b/Core/Core/Credentials/AccountManager.cs @@ -256,7 +256,10 @@ public static void UpgradeAccount(string id) account.serverInfo.url = upgradeUri.ToString().TrimEnd('/'); account.serverInfo.frontend2 = true; - s_accountStorage.UpdateObject(account.id, JsonConvert.SerializeObject(account)); + // setting the id to null will force it to be recreated + account.id = null; + + s_accountStorage.UpdateObject(account.id!, JsonConvert.SerializeObject(account)); } /// @@ -281,7 +284,9 @@ public static IEnumerable GetAccounts(string serverUrl) foreach (var acc in accounts) { - if (acc.serverInfo.url == serverUrl && !filtered.Any(x => x.id != acc.id)) + // 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)) { filtered.Add(acc); } diff --git a/Core/Tests/Speckle.Core.Tests.Unit/Credentials/AccountServerMigrationTests.cs b/Core/Tests/Speckle.Core.Tests.Unit/Credentials/AccountServerMigrationTests.cs index b7b807d49e..35c21adf7c 100644 --- a/Core/Tests/Speckle.Core.Tests.Unit/Credentials/AccountServerMigrationTests.cs +++ b/Core/Tests/Speckle.Core.Tests.Unit/Credentials/AccountServerMigrationTests.cs @@ -17,6 +17,9 @@ public static IEnumerable MigrationTestCase() Account newAccount = CreateTestAccount(NEW_URL, new(OLD_URL), null); Account otherAccount = CreateTestAccount(OTHER_URL, null, null); + // new account user must match old account user id + newAccount.userInfo.id = oldAccount.userInfo.id; + List givenAccounts = new() { oldAccount, newAccount, otherAccount }; yield return new TestCaseData(givenAccounts, NEW_URL, new[] { newAccount }) @@ -69,7 +72,7 @@ private static Account CreateTestAccount(string url, Uri movedFrom, Uri movedTo) }, userInfo = new UserInfo { - id = new Guid().ToString(), + id = Guid.NewGuid().ToString(), email = "user@example.com", name = "user" }