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

+28 -18
View File
@@ -28,12 +28,18 @@ type CompanyQuotaDecision struct {
// creates the invitation or applies the visibility change in the same
// transaction, so a failed business operation cannot leave quota charged.
//
// Writers lock rows in this order: organization, active membership,
// invitation or visibility record, then quota usage. A repository may take an
// organization lock again inside the same transaction, but must not invert
// this order. Each method rechecks the organization's stored verification
// level, basis, and changed_at against the snapshot in CompanyQuota before it
// writes; a caller cannot grant itself a tier by supplying a different level.
// Writers lock rows in this order: organization, then for an E0 organization
// its holding, then active membership, invitation or visibility record, and
// last quota usage. A repository may take an organization lock again inside
// the same transaction, but must not invert this order. Each method rechecks
// the organization's stored verification level, basis, and changed_at against
// the snapshot in CompanyQuota before it writes; a caller cannot grant itself
// a tier by supplying a different level.
//
// The E0 limits are pooled per holding: the usage of every E0 organization of
// one holding counts toward the same window. Usage rows stay attributed to the
// organization that consumed them, and idempotency stays per organization.
// Organizations at E1 and above count only their own usage.
//
// Invitation usage is keyed by organization and invitation ID and remains
// until the organization is deleted. The unique key makes retries idempotent
@@ -49,24 +55,28 @@ type CompanyQuotaRepository interface {
// LockOrganization takes the organization lock that serializes the
// reservations of one organization (FOR NO KEY UPDATE, which does not block
// the foreign-key lock of a candidate's own hide), ahead of the share locks
// of a membership check. A
// caller that checks the membership first and reserves later would hold a
// share lock and then ask for the exclusive one, and two such callers of one
// organization deadlock. A caller that reserves after a share lock takes
// this lock first, in the documented order. It returns
// of a membership check. A caller that checks the membership first and
// reserves later would hold a share lock and then ask for the exclusive
// one, and two such callers of one organization deadlock. A caller that
// reserves after a share lock takes this lock first, in the documented
// order. For an E0 organization it also takes the lock of its holding,
// which serializes the shared E0 pool; the holding is locked right after
// the organization, before any other lock of the caller, so the callers of
// one holding cannot deadlock on it. It returns
// ErrCompanyQuotaSnapshotChanged for a removed organization.
LockOrganization(ctx context.Context, organizationID uuid.UUID) error
// ReserveInvitation counts a new invitation against the current policy
// limit. An existing invitation ID is returned as allowed and reused
// without a second charge, regardless of its age or the request key. A
// denied new invitation writes no usage and reports RetryAt after the
// earliest currently counted invitation expires.
// limit of the organization's usage scope. An existing invitation ID is
// returned as allowed and reused without a second charge, regardless of
// its age or the request key. A denied new invitation writes no usage and
// reports RetryAt after the earliest currently counted invitation expires.
ReserveInvitation(ctx context.Context, quota domain.CompanyQuota, invitationID uuid.UUID) (CompanyQuotaDecision, error)
// ReserveCardView counts a distinct candidate within the rolling card-view
// window. A repeat while the prior view is active is allowed and reused,
// and refreshes last_seen with a monotonic update. A denied new view writes
// no usage and reports RetryAt after the earliest active view expires.
// window of the organization's usage scope. A repeat while the prior view
// of the same organization is active is allowed and reused, and refreshes
// last_seen with a monotonic update. A denied new view writes no usage and
// reports RetryAt after the earliest active view expires.
ReserveCardView(ctx context.Context, quota domain.CompanyQuota, candidateID uuid.UUID) (CompanyQuotaDecision, error)
}