You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(api): look up, accept and decline invitations by link - #3025
Follows ADR 086 §3, §4, §7 and §10, with an amendment for the adapter's grant call, accept's ordering, self-decline and the named inviter (below)
Summary
POST /invitations/lookup returns the project, its name, the role, the expiry and the inviter:
inviter is a user-ref (user_id, identifier, display) the server resolves, because the invited user cannot read platform users and the console could not name the inviter from created_by alone;
it degrades to user_id when the inviter no longer resolves, and is null when a project secret created the invitation. created_by is unchanged.
POST /invitations/accept runs in one transaction:
the invitation must be pending and unexpired, its project claimed, and the accepting user not the inviter (403 inv.self_accept);
unless created_by is null, the inviter must still hold admin on the project, checked through the resolver on the transaction's statements; otherwise 403 inv.inviter_not_admin (new code);
the guarded status change runs first, so of two racing accepts the loser misses and gets the same 404 as a finished invitation;
the project_member adapter then calls GrantService.EnsureUserGrant: no grant is created, a different relation gets a second grant, an identical active grant counts as done, an identical expired grant is revoked and created again. It runs in the invitation's transaction, because Create opens its own and transactions don't nest, and it refuses a relation outside viewer, editor and admin, which accept answers as a server fault;
metadata is cleared and invitation.accepted emitted, sharing its request_id with the grant's authz.granted / authz.revoked.
POST /invitations/reject sets rejected, clears metadata and emits invitation.rejected. The inviter can't decline their own invitation (403 inv.self_reject, new code); they cancel it instead.
All three need a session of a user homed in the platform project; any other session gets 401. Accept and reject need the CSRF token, lookup doesn't. Every unknown or finished token answers the same 404 inv.not_found.
invitation.accepted and invitation.rejected move from the events catalog's Contracted table to Path B, and the stubs are gone.
Follow-up from the review of feat(api): invitations CRUD #2983: HTTP integration tests for the pending cap and replace at it, pagination, a concurrent replace, and another project's invitation ids.
Notes
The contract changes (inviter, self-decline) land with the implementation rather than in a spec PR first; happy to split them out.
Whoever holds a link sees the inviter's display name and identifier (usually their email), as ADR 086's accept page intends.
No rate limit yet. The server has no per-operation limiter anywhere (ADR 078, Rate limit grant creation by identifier #1266); the 128-bit token makes guessing infeasible meanwhile.
One race remains: the same user accepting two different invitations for the same relation at the same moment can still hit the grant's unique index and get a 500. Fixing that needs an insert that ignores conflicts in storage.
A signed-in platform user redeems an invitation link (ADR 086 §3, §4, §7,
§10). Lookup returns the project, role, inviter and expiry. Accept marks
the invitation accepted under the pending guard, then the project_member
adapter grants the role through the grant service in the same
transaction. Decline marks it rejected. Every unknown or finished token
answers the same 404.
Accept is refused when the inviter accepts their own invitation, the
project is unclaimed, or the creator no longer holds admin
(inv.inviter_not_admin). invitation.accepted and invitation.rejected move
from the catalog's Contracted table to live producers.
Refs #2853
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd foreign ids over HTTP
Follow-up from the review of #2983: the cap and replace at it, pagination,
a concurrent replace and another project's invitation ids had been checked
by hand, but none had an HTTP-level integration test.
Refs #2852
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…invitation
Lookup returns the inviter as a user reference, resolved by the server:
the invited user cannot read platform users, so the console had no way
to show who invited them from created_by alone. Decline now refuses the
inviter with inv.self_reject, as accept already did; an administrator
cancels their own invitation instead. EnsureUserGrant starts a span like
every other service method.
Refs #2853
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EnsureUserGrant refuses a relation outside viewer, editor and admin; the
invitation adapter answers that refusal as a server fault, since create
already validated the stored relation. ADR 086 gets a dated amendment for
the adapter's grant call, accept's ordering, self-decline and the named
inviter on lookup.
Refs #2853
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Invitation redemption lacks active-user validation, allowing deactivated users to accept or reject invitations, and delegated grants can incorrectly satisfy acceptance without creating a direct grant.
…ip delegated grants
From review on #3025. EnsureUserGrant runs the same active, platform-homed
principal check as Create, and accept answers a user that is gone or no
longer active as auth.unauthorized. Delegated assignments sit outside the
unique binding the write targets, so they no longer count as an identical
grant or get revoked as an expired one.
Refs #2853
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Capturing now before the transaction allows connection waits or retries to bypass invitation expiry checks, permitting expired invitations to be accepted or rejected with metadata cleared instead of returning 404.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Invitations created by project-local administrators return an ID-only inviter despite available user details because creator resolution incorrectly uses the platform project instead of the creator’s home project.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
An invitation created by a project-local administrator returns an ID-only inviter, even when that…
apps/api/internal/service/invitation.go:304
An invitation created by a project-local administrator returns an ID-only inviter, even when that user still has a name or identifier. Creation permits these administrators, but ResolveUserRefs filters users to the supplied project, so the platform-project lookup excludes them. Resolve CreatedBy through GetResourceScope and use its home project, preserving the ID-only fallback for a missing creator while propagating storage errors.
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
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.
Context
Summary
POST /invitations/lookupreturns the project, its name, the role, the expiry and the inviter:inviteris a user-ref (user_id,identifier,display) the server resolves, because the invited user cannot read platform users and the console could not name the inviter fromcreated_byalone;user_idwhen the inviter no longer resolves, and isnullwhen a project secret created the invitation.created_byis unchanged.POST /invitations/acceptruns in one transaction:403 inv.self_accept);created_byisnull, the inviter must still holdadminon the project, checked through the resolver on the transaction's statements; otherwise403 inv.inviter_not_admin(new code);404as a finished invitation;project_memberadapter then callsGrantService.EnsureUserGrant: no grant is created, a different relation gets a second grant, an identical active grant counts as done, an identical expired grant is revoked and created again. It runs in the invitation's transaction, becauseCreateopens its own and transactions don't nest, and it refuses a relation outsideviewer,editorandadmin, which accept answers as a server fault;metadatais cleared andinvitation.acceptedemitted, sharing itsrequest_idwith the grant'sauthz.granted/authz.revoked.POST /invitations/rejectsetsrejected, clearsmetadataand emitsinvitation.rejected. The inviter can't decline their own invitation (403 inv.self_reject, new code); they cancel it instead.401. Accept and reject need the CSRF token, lookup doesn't. Every unknown or finished token answers the same404 inv.not_found.invitation.acceptedandinvitation.rejectedmove from the events catalog's Contracted table to Path B, and the stubs are gone.Notes
inviter, self-decline) land with the implementation rather than in a spec PR first; happy to split them out.500. Fixing that needs an insert that ignores conflicts in storage.created_bytoinviter.TestSessionCSRF's lookup subtest expected the stub's501; it now signs in a platform user and expects404.🤖 Generated with Claude Code