feat(invitations): send invitations into the candidate inbox atomically

This commit is contained in:
shira committed 2026-10-09 16:50:36 +03:00
1 parent fc35e27af5
commit 1a067221f7
46 files changed
+3276 -113

No files matched your search

@@ -201,6 +201,11 @@ type Querier interface {
// The restricting foreign key is checked at the end of the statement, after
// these rows are gone.
DeleteUnverifiedUsersRegisteredBefore(ctx context.Context, arg DeleteUnverifiedUsersRegisteredBeforeParams) (int64, error)
// The conditional update is the compare-and-swap of a send: it applies only to
// a draft whose version is still the one the caller read, records the first
// delivery with its deadline, and advances the version by one. No row is
// returned when it lost a race or the invitation is no longer a draft.
DeliverInvitation(ctx context.Context, arg DeliverInvitationParams) (pgtype.UUID, error)
// Lock order. Every transaction that writes mail_quota_usage first creates
// and locks all the usage rows it will touch with EnsureMailQuotaRows and
// LockMailQuotaRows, which both work in (period_kind, period_start) order,
@@ -297,6 +302,7 @@ type Querier interface {
// Explains why ConsumeEmailToken matched no row.
GetEmailTokenState(ctx context.Context, arg GetEmailTokenStateParams) (GetEmailTokenStateRow, error)
GetInvitationCreationResult(ctx context.Context, scopeHash []byte) (string, error)
GetInvitationSendResult(ctx context.Context, scopeHash []byte) (GetInvitationSendResultRow, error)
// The caller holds the attempt row lock, so the last mark is stable.
GetLastAssessmentOriginMark(ctx context.Context, attemptID pgtype.UUID) (AssessmentAttemptOriginMark, error)
GetLatestAssessmentFamily(ctx context.Context, familyKey string) (AssessmentFamily, error)
@@ -472,6 +478,7 @@ type Querier interface {
// current terms version is checked when the transaction commits.
InsertInvitation(ctx context.Context, arg InsertInvitationParams) error
InsertInvitationEvent(ctx context.Context, arg InsertInvitationEventParams) error
InsertInvitationSendResult(ctx context.Context, arg InsertInvitationSendResultParams) error
InsertInvitationTermsVersion(ctx context.Context, arg InsertInvitationTermsVersionParams) error
InsertMailQuotaReservation(ctx context.Context, arg InsertMailQuotaReservationParams) error
InsertMailRequest(ctx context.Context, arg InsertMailRequestParams) error
@@ -592,6 +599,11 @@ type Querier interface {
// (hidden_at, organization_id) position of the last record of the previous
// page.
ListCandidateHiddenOrganizations(ctx context.Context, arg ListCandidateHiddenOrganizationsParams) ([]ListCandidateHiddenOrganizationsRow, error)
// One bounded page of the candidate's inbox: every invitation delivered to
// the candidate, in any later state, newest first by delivery time. Drafts
// have no delivery and are never listed. The candidate scopes the rows, so
// no identifier of another candidate can appear.
ListCandidateInvitations(ctx context.Context, arg ListCandidateInvitationsParams) ([]ListCandidateInvitationsRow, error)
// The same selection for the candidate's own card preview, so the candidate
// sees what an organization would read. It is scoped by the owner and runs
// after the caller locked the effective C2 and publication; it does not apply
@@ -831,6 +843,9 @@ type Querier interface {
// Deletes at most batch_limit expired records. Locked rows are skipped, so
// the statement never waits for a concurrent reservation.
PurgeExpiredIdempotencyRecords(ctx context.Context, arg PurgeExpiredIdempotencyRecordsParams) (int64, error)
// Read one delivered invitation addressed to the candidate. A draft and an
// invitation of another candidate find nothing.
ReadCandidateInvitation(ctx context.Context, arg ReadCandidateInvitationParams) (ReadCandidateInvitationRow, error)
// Queries of the candidate visibility settings: the publication of
// the card, the search status, the hidden organizations, and the history of
// these settings. Every statement is scoped by the candidate's user_id, and