feat(invitations): accept invitations with C4 consent and contact grants; share the E0 quota across holdings

This commit is contained in:
shira committed 2026-10-09 18:03:35 +03:00
1 parent a5990d3fc6
commit 676b3c6e24
59 files changed
+4926 -194

No files matched your search

@@ -11,6 +11,11 @@ import (
)
type Querier interface {
// The compare-and-swap of an acceptance: it applies only to a delivered or
// viewed invitation at the version and the terms version that the candidate
// read, and before its deadline. The answer is the acceptance time, and the
// deadline is kept.
AcceptInvitation(ctx context.Context, arg AcceptInvitationParams) (pgtype.UUID, error)
// Adds recipients to the day and the month row. The caller holds their
// locks from LockMailQuotaRows and has checked both limits.
AddMailQuotaUsage(ctx context.Context, arg AddMailQuotaUsageParams) (int64, error)
@@ -131,7 +136,16 @@ type Querier interface {
CountAssessmentSignalEvents(ctx context.Context, attemptID pgtype.UUID) (int64, error)
// Counts the hiding records of one candidate for the settings read.
CountCandidateHiddenOrganizations(ctx context.Context, userID pgtype.UUID) (int64, error)
// Counts the distinct-card usage of the E0 pool of a holding, with the same
// rule as CountCompanyInvitationQuotaHoldingWindow. A view is still counted
// per organization: the same candidate seen by two organizations of one
// holding is two charges.
CountCompanyCardViewQuotaHoldingWindow(ctx context.Context, arg CountCompanyCardViewQuotaHoldingWindowParams) (CountCompanyCardViewQuotaHoldingWindowRow, error)
CountCompanyCardViewQuotaWindow(ctx context.Context, arg CountCompanyCardViewQuotaWindowParams) (CountCompanyCardViewQuotaWindowRow, error)
// Counts the invitation usage of the E0 pool of a holding: the usage of every
// organization of the holding whose trust level is E0 when the count runs. Each
// row stays attributed to the organization that consumed it.
CountCompanyInvitationQuotaHoldingWindow(ctx context.Context, arg CountCompanyInvitationQuotaHoldingWindowParams) (CountCompanyInvitationQuotaHoldingWindowRow, error)
CountCompanyInvitationQuotaWindow(ctx context.Context, arg CountCompanyInvitationQuotaWindowParams) (CountCompanyInvitationQuotaWindowRow, error)
// Counts the families of a category that have at least one published
// version, however many versions each has.
@@ -275,6 +289,9 @@ type Querier interface {
GetCandidateHiddenOrganization(ctx context.Context, arg GetCandidateHiddenOrganizationParams) (GetCandidateHiddenOrganizationRow, error)
GetConsentText(ctx context.Context, arg GetConsentTextParams) (ConsentText, error)
GetContactConsentRecordByInvitation(ctx context.Context, arg GetContactConsentRecordByInvitationParams) (GetContactConsentRecordByInvitationRow, error)
// Read the grant of one invitation of one organization. An invitation of
// another organization finds nothing.
GetContactGrantByInvitation(ctx context.Context, arg GetContactGrantByInvitationParams) (ContactGrant, error)
GetCurrentAssessmentCategoryOpening(ctx context.Context, category string) (AssessmentCategoryOpening, error)
// The newest unrevoked record of a purpose other than C4.
GetCurrentConsentRecord(ctx context.Context, arg GetCurrentConsentRecordParams) (GetCurrentConsentRecordRow, error)
@@ -304,6 +321,8 @@ type Querier interface {
GetEmailTokenByHash(ctx context.Context, arg GetEmailTokenByHashParams) (EmailToken, error)
// Explains why ConsumeEmailToken matched no row.
GetEmailTokenState(ctx context.Context, arg GetEmailTokenStateParams) (GetEmailTokenStateRow, error)
GetHoldingIDByFounder(ctx context.Context, founderAccountID pgtype.UUID) (pgtype.UUID, error)
GetInvitationAcceptResult(ctx context.Context, scopeHash []byte) (GetInvitationAcceptResultRow, error)
GetInvitationCreationResult(ctx context.Context, scopeHash []byte) (string, error)
GetInvitationDeclineResult(ctx context.Context, scopeHash []byte) (GetInvitationDeclineResultRow, error)
GetInvitationSendResult(ctx context.Context, scopeHash []byte) (GetInvitationSendResultRow, error)
@@ -470,6 +489,10 @@ type Querier interface {
// when no row returns; the insert then changes nothing and does not abort
// the transaction.
InsertContactConsentRecord(ctx context.Context, arg InsertContactConsentRecordParams) (InsertContactConsentRecordRow, error)
// Store the contact grant of an acceptance. The row is inserted in the same
// transaction as its C4 consent record and the accepted state; the database
// checks that the record, the invitation, and the candidate agree.
InsertContactGrant(ctx context.Context, arg InsertContactGrantParams) error
// Stores a new delivery. A delivery with the same ID already exists when the
// same request is handled again; the statement then inserts nothing and
// returns 0 rows, and the stored content stays as it was. While another
@@ -477,10 +500,16 @@ type Querier interface {
// for it.
InsertDelivery(ctx context.Context, arg InsertDeliveryParams) (int64, error)
InsertEmailToken(ctx context.Context, arg InsertEmailTokenParams) error
// Stores the holding of a founder account unless the account already has one.
// A concurrent creation of the same account waits on the founder key until the
// other transaction ends; then this insert does nothing, and the caller reads
// the stored holding with GetHoldingIDByFounder.
InsertHoldingIfAbsent(ctx context.Context, arg InsertHoldingIfAbsentParams) error
// The invitation row, its first terms version, and its first audit event are
// inserted in one caller-owned transaction. The deferred reference to the
// current terms version is checked when the transaction commits.
InsertInvitation(ctx context.Context, arg InsertInvitationParams) error
InsertInvitationAcceptResult(ctx context.Context, arg InsertInvitationAcceptResultParams) error
InsertInvitationDecline(ctx context.Context, arg InsertInvitationDeclineParams) error
InsertInvitationDeclineResult(ctx context.Context, arg InsertInvitationDeclineResultParams) error
InsertInvitationEvent(ctx context.Context, arg InsertInvitationEventParams) error
@@ -493,9 +522,9 @@ type Querier interface {
// unique key absorbs at-least-once redelivery without copying event content.
InsertNotificationInboxEvent(ctx context.Context, arg InsertNotificationInboxEventParams) (int64, error)
// Stores a new organization with the verification level that the domain
// gave it. The deferred constraint organizations_owner_required fails the
// transaction at commit unless an active owner membership was inserted in
// it too.
// gave it and the holding of its creator. The deferred constraint
// organizations_owner_required fails the transaction at commit unless an
// active owner membership was inserted in it too.
InsertOrganization(ctx context.Context, arg InsertOrganizationParams) error
// The parent and first immutable snapshot are inserted in one caller-owned
// transaction. Deferred version references are checked when it commits.
@@ -741,10 +770,19 @@ type Querier interface {
// canceled, or reclaimed after the lease expired. While the lock is held,
// other workers skip the row, so the handler never runs twice at once.
LockClaimedScheduledJob(ctx context.Context, arg LockClaimedScheduledJobParams) (int64, error)
// Takes the pool lock of an E0 holding. It follows the organization lock, so
// every writer locks an organization first and its holding second. Two
// reservations of one holding queue here, and the second one counts the
// usage that the first one committed. The lock does not conflict with the
// FOR KEY SHARE that organizations.holding_id takes when an organization joins
// the holding.
LockCompanyQuotaHolding(ctx context.Context, holdingID pgtype.UUID) (pgtype.UUID, error)
LockCompanyQuotaOrganization(ctx context.Context, organizationID pgtype.UUID) (LockCompanyQuotaOrganizationRow, error)
// Writers lock the organization first, then invitation/card-view state, and
// finally usage rows. The organization lock serializes quota decisions for
// the tenant and makes the subsequent count and insert atomic.
// Writers lock the organization first, then, for an E0 organization, the holding
// whose pool it shares, then invitation/card-view state, and finally usage rows.
// The organization lock serializes quota decisions for the tenant, the holding
// lock serializes the E0 pool across the organizations of one holding, and
// together they make the subsequent count and insert atomic.
// Takes the organization lock ahead of every share lock of a reader that will
// reserve usage later. FOR NO KEY UPDATE conflicts with itself and with FOR
// SHARE, so readers of one organization queue up instead of deadlocking on a
@@ -752,8 +790,9 @@ type Querier interface {
// FOR KEY SHARE that a foreign key takes, such as the hidden-organization
// insert of a candidate, which holds the candidate's row and then needs this
// one. The reservation itself still takes FOR UPDATE inside the same
// transaction.
LockCompanyQuotaOrganizationFirst(ctx context.Context, organizationID pgtype.UUID) (pgtype.UUID, error)
// transaction. The result carries the holding, whose pool an E0 organization
// shares; the caller locks that holding right after this lock.
LockCompanyQuotaOrganizationFirst(ctx context.Context, organizationID pgtype.UUID) (LockCompanyQuotaOrganizationFirstRow, error)
// Lock the current C2 before locking the publication. C2 revocation updates
// this row before it locks the publication, so preserving this order avoids
// a lock inversion and makes the current consent stable through the read.
@@ -1086,7 +1125,7 @@ type Querier interface {
// follow it). No row returns for a stale version, an account that is no
// active manager, or an unknown organization; the adapter reads the
// membership to tell them apart.
UpdateOrganizationProfile(ctx context.Context, arg UpdateOrganizationProfileParams) (Organization, error)
UpdateOrganizationProfile(ctx context.Context, arg UpdateOrganizationProfileParams) (UpdateOrganizationProfileRow, error)
// Replaces the registration of an unverified account and advances the
// registration version in the same statement, so no caller can choose it.
// The version check rejects a writer that read an older row; a verified