fix: await promises in VisitAuthorization hasReadRights - #1754
Open
jekabs-karklins wants to merge 1 commit into
Open
fix: await promises in VisitAuthorization hasReadRights#1754jekabs-karklins wants to merge 1 commit into
jekabs-karklins wants to merge 1 commit into
Conversation
The two async checks in hasReadRights were not awaited. Because an unawaited promise is truthy, `||` short-circuited on isMemberOfProposal and returned that promise object, so isVisitorOfVisit was never evaluated. The async wrapper then adopted the returned promise, making the method silently equivalent to: visit.creatorId === agent.id || (await isMemberOfProposal(...)) The visitor-list check was therefore dead code. Proposal members passed on the second check, so the bug only surfaced for a user who is on the visitor list without being a proposal member -- they got "Failed to load questionary details" when opening the visit registration. SWAP-5726 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
jekabs-karklins
requested review from
DChambersSTFC and
yoganandaness
and removed request for
a team
August 26, 2026 12:47
yoganandaness
requested changes
Aug 27, 2026
| visit.creatorId === agent.id || | ||
| this.proposalAuth.isMemberOfProposal(agent, visit.proposalPk) || | ||
| this.visitDataSource.isVisitorOfVisit(agent.id, visit.id) | ||
| (await this.proposalAuth.isMemberOfProposal(agent, visit.proposalPk)) || |
Contributor
There was a problem hiding this comment.
Can we add some parallelization?
const [isMember, isVisitor] = await Promise.all([
this.proposalAuth.isMemberOfProposal(agent, visit.proposalPk),
this.visitDataSource.isVisitorOfVisit(agent.id, visit.id),
]);
return visit.creatorId === agent.id || isMember || isVisitor;
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.
The two async checks in
VisitAuthorization.hasReadRightswere never awaited which caused issue that visitor could not load the questionaire.The first line is sync, and the last two is async.
one is false → || moves on
two is a pending Promise → truthy → || short-circuits and returns two itself
three is never evaluated
The method was silently equivalent to:
The visitor-list check was dead code for everyone. Proposal members passed on the second check, so this only surfaced for a user on the visitor list who is not a proposal member — they saw
Failed to load questionary detailswhen opening the visit registration.How Has This Been Tested
Manually, as the reporting visitor: the visit registration questionary now loads.
Fixes
SWAP-5726
Changes
apps/backend/src/auth/VisitAuthorization.ts— await both async checks.