fix: resilient member lookup in TeamComponent (#59)#61
Merged
Conversation
A team document with duplicate TeamMember rows for the same Key (e.g. from a migration glitch) bricked the team-management page — every .Single(predicate) call site in TeamComponent threw InvalidOperationException, and once tripped, every subsequent click in that team also threw. Replace the 5 .Single(predicate) sites in TeamComponent.razor (RemoveUserFromTeam, ChangeRole, ChangeTenantRoles, ChangeScopeOverrides, HasAccessLevel) with a small TeamMemberResolver helper that returns the first match, returns null when no match, and logs a warning when duplicates are found. Action handlers gracefully notify the user and bail when the member has gone missing; HasAccessLevel returns false. The repository layer is unchanged; duplicates remain operator-cleanup (separately tracked).
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #59.
<TeamComponent />no longer crashes the team-management page when a team document carries duplicateTeamMemberrows for the sameKey(e.g. from a migration glitch or missing unique constraint). Five member-lookup sites inTeamComponent.razorpreviously used.Single(predicate), which threwInvalidOperationExceptionon duplicates and bricked the page until reload — once tripped, every subsequent click on a different row also threw.RemoveUserFromTeam,ChangeRole,ChangeTenantRoles,ChangeScopeOverrides,HasAccessLevelall now go through a newTeamMemberResolver.Resolve(...)helper.nullwhen no match, and logs a warning (with team key, lookup key, count) when duplicates are found — so operators can find and clean up the bad rows."Member not found — please reload") and bail without throwing if the member has disappeared between renders.HasAccessLevelreturnsfalsedefensively.The repository layer is unchanged in this PR — duplicates remain operator-cleanup. Adding a unique index on
(TeamKey, UserKey)to prevent duplicates going forward is tracked separately.Consumer impact
Sequence contains more than one matching elementfromTeamComponentshould pick this up on next package upgrade — the page will stay usable, and a warning will appear in logs identifying the duplicate.Test plan
TeamMemberResolverTestscover no-match (returns null), single match (returns it), 2 / 3 matches (returns first + logs warning with count), and null logger (does not throw).dotnet build -c Release— clean, 0 warnings, 0 errors.dotnet test -c Release— 268 / 268 passing (was 263, +5 new).