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

@@ -36,6 +36,10 @@ var (
// ErrInvitationDeclineResultNotFound reports a missing outcome of a
// decline for a live idempotency record.
ErrInvitationDeclineResultNotFound = errors.New("invitation decline result not found")
// ErrInvitationAcceptResultNotFound reports a missing outcome of an
// acceptance for a live idempotency record.
ErrInvitationAcceptResultNotFound = errors.New("invitation accept result not found")
)
// MaxInvitationPageSize is the largest organization-scoped or candidate page
@@ -49,6 +53,8 @@ type InvitationRepositories interface {
InvitationCreationResults() InvitationCreationResultRepository
InvitationSendResults() InvitationSendResultRepository
InvitationDeclineResults() InvitationDeclineResultRepository
InvitationAcceptResults() InvitationAcceptResultRepository
ContactGrants() ContactGrantRepository
}
// InvitationRepository stores invitations, their immutable terms versions, and
@@ -130,6 +136,14 @@ type InvitationRepository interface {
// GetDecline returns the stored decline of the invitation or
// ErrInvitationDeclineNotFound.
GetDecline(ctx context.Context, organizationID, invitationID uuid.UUID) (domain.InvitationDecline, error)
// Accept moves a delivered or viewed invitation from expectedVersion to the
// accepted version of next before its deadline, keeps the deadline and the
// terms, and records the audit event. It returns
// ErrInvitationVersionConflict when the stored row is not answerable at
// expectedVersion, at its terms version, or before its deadline. The consent
// C4 and the contact grant are stored by the caller in the same transaction.
Accept(ctx context.Context, expectedVersion int64, next domain.Invitation, event domain.InvitationEvent) error
}
// InvitationCreationResultRepository stores the original response of a
@@ -246,3 +260,30 @@ type InvitationDeclineResultRepository interface {
SaveDeclineResult(ctx context.Context, scope [IdempotencyDigestSize]byte, result InvitationDeclineResult) error
GetDeclineResult(ctx context.Context, scope [IdempotencyDigestSize]byte) (InvitationDeclineResult, error)
}
// InvitationAcceptOutcome is the stored result of an acceptance under an
// Idempotency-Key. The contract stores a success, a missing invitation, and a
// state conflict; a stale version and a consent refusal are not stored.
type InvitationAcceptOutcome string
const (
InvitationAcceptAccepted InvitationAcceptOutcome = "accepted"
InvitationAcceptNotFound InvitationAcceptOutcome = "not_found"
InvitationAcceptStateConflict InvitationAcceptOutcome = "state_conflict"
)
// InvitationAcceptResult is the outcome of one acceptance. It keeps no copy of
// the response: an accepted invitation keeps its answer and its grant, so a
// replay rebuilds the response from them.
type InvitationAcceptResult struct {
InvitationID uuid.UUID
Outcome InvitationAcceptOutcome
}
// InvitationAcceptResultRepository stores the outcome of an idempotent
// acceptance. The scope references the generic idempotency record, so the
// outcome is removed when that record is purged.
type InvitationAcceptResultRepository interface {
SaveAcceptResult(ctx context.Context, scope [IdempotencyDigestSize]byte, result InvitationAcceptResult) error
GetAcceptResult(ctx context.Context, scope [IdempotencyDigestSize]byte) (InvitationAcceptResult, error)
}