-
-
Notifications
You must be signed in to change notification settings - Fork 6
Fix wrong current user in FW Lite comments for cross-server projects #2490
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
Open
myieye
wants to merge
9
commits into
develop
Choose a base branch
from
claude/fw-lite-user-identity-bug-iozg90
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c6cf659
Fix wrong current user in FW Lite comments for cross-server projects
claude 9bd3c46
Attribute synced comment read status to the freshly resolved user
claude 256c308
Fall back to the persisted origin user for read-status when auth is null
claude f16f85c
Revert the LastUser rename; keep origin-scoping in the gate
claude 61e767b
Resolve open-time identity from the MSAL cache without a token refresh
claude e3122ab
Keep the NewMetadata staleness todo verbatim from develop
claude 05fe964
Tidy review-pass comments
myieye a4a18a1
Trim review-pass comments; note GetCachedUser is authority-scoped
myieye 38fa4ec
Don't let a cached-user read failure block project open
myieye 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 hidden or 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
27 changes: 27 additions & 0 deletions
27
backend/FwLite/FwLiteShared.Tests/Projects/CombinedProjectsServiceTests.cs
This file contains hidden or 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,27 @@ | ||
| using FwLiteShared.Auth; | ||
| using FwLiteShared.Projects; | ||
| using LcmCrdt; | ||
|
|
||
| namespace FwLiteShared.Tests.Projects; | ||
|
|
||
| public class CombinedProjectsServiceTests | ||
| { | ||
| private static readonly LexboxServer Staging = new(new Uri("https://staging.languagedepot.org"), "Staging"); | ||
| private static readonly LexboxServer Dev = new(new Uri("https://lexbox.dev.languagetechnology.org"), "Dev"); | ||
|
|
||
| private static ProjectData ProjectFrom(LexboxServer origin) => | ||
| new("Sena 3", "sena-3", Guid.NewGuid(), ProjectData.GetOriginDomain(origin.Authority), Guid.NewGuid()); | ||
|
|
||
| [Fact] | ||
| public void ServerOwnsProject_TrueForOriginServer() | ||
| { | ||
| CombinedProjectsService.ServerOwnsProject(ProjectFrom(Staging), Staging).Should().BeTrue(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ServerOwnsProject_FalseForOtherServerSharingTheGuid() | ||
| { | ||
| // A project downloaded from staging must not be claimed by dev when both list the same GUID. | ||
| CombinedProjectsService.ServerOwnsProject(ProjectFrom(Staging), Dev).Should().BeFalse(); | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -191,6 +191,18 @@ public async ValueTask<bool> IsSignedIn() | |
| return accounts.Any(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Who's signed in, from the local MSAL cache (no network). Optimistic like <see cref="IsSignedIn"/>: | ||
| /// non-null means "was signed in", not "can get a token now". Null if none; for a token too use <see cref="GetCurrentUser"/>. | ||
| /// </summary> | ||
| public async ValueTask<LexboxUser?> GetCachedUser() | ||
| { | ||
| await ConfigureCache(); | ||
| // GetAccountsAsync is authority-scoped (WithOidcAuthority), so this is already the origin server's account. | ||
| var account = (await _application.GetAccountsAsync()).FirstOrDefault(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's already a number of places here where we call |
||
| return account?.Username is null ? null : new LexboxUser(account.Username, account.HomeAccountId.ObjectId); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets a usable authentication result, silently refreshing when the cached token is missing or near | ||
| /// expiry. Returns null when none can be produced — in one of two cases the caller may want to tell apart: | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
31 changes: 31 additions & 0 deletions
31
backend/FwLite/LcmCrdt.Tests/CurrentProjectServiceTests.cs
This file contains hidden or 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,31 @@ | ||
| namespace LcmCrdt.Tests; | ||
|
|
||
| public class CurrentProjectServiceTests(MiniLcmApiFixture fixture) : IClassFixture<MiniLcmApiFixture> | ||
| { | ||
| private CurrentProjectService ProjectService => fixture.GetService<CurrentProjectService>(); | ||
|
|
||
| [Fact] | ||
| public async Task UpdateLastUser_WithNullUser_KeepsPersistedValue() | ||
| { | ||
| // Open-time resolution falls back to this persisted value when auth is null, so a null update mustn't wipe it. | ||
| await ProjectService.UpdateLastUser("Tim Haasdyk", "tim-id"); | ||
|
|
||
| await ProjectService.UpdateLastUser(null, null); | ||
|
|
||
| var projectData = await ProjectService.GetProjectData(); | ||
| projectData.LastUserName.Should().Be("Tim Haasdyk"); | ||
| projectData.LastUserId.Should().Be("tim-id"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task UpdateLastUser_ReplacesPreviousUser() | ||
| { | ||
| await ProjectService.UpdateLastUser("first", "first-id"); | ||
|
|
||
| await ProjectService.UpdateLastUser("second", "second-id"); | ||
|
|
||
| var projectData = await ProjectService.GetProjectData(); | ||
| projectData.LastUserName.Should().Be("second"); | ||
| projectData.LastUserId.Should().Be("second-id"); | ||
| } | ||
| } |
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.
I know it's just a test, but the username in this context is actually the Name of the person, so
LexCore.Entities.User.Nameand notEmailorUsername