feat(invitations): check contact grants on every read, cap pending invitations, and expire them at the deadline
This commit is contained in:
1 parent
676b3c6e24
commit
12a7213d4a
67 files changed
+4255
-149
No files matched your search
@@ -57,25 +57,23 @@ type AccountDeletionRequests interface {
|
||||
CreateOrGet(ctx context.Context, request domain.AccountDeletionRequest) (record domain.AccountDeletionRequest, created bool, err error)
|
||||
}
|
||||
|
||||
// ConsentRevocationEffects applies every currently available local privacy
|
||||
// change and records downstream revocation intents in the same transaction as
|
||||
// the ledger stamps. Future C2 and C4 grant adapters must bind each downstream
|
||||
// grant to its source consent record ID and synchronously close grants for
|
||||
// revoked record IDs before returning; a later consent record may create a
|
||||
// new grant, but must never reactivate an older record's grant. Future C5
|
||||
// readers and importers must check the current consent ledger before reading
|
||||
// ConsentRevocationEffects applies every local privacy change of a revocation
|
||||
// and records downstream revocation intents in the same transaction as the
|
||||
// ledger stamps. The local grants are closed synchronously there: a C4
|
||||
// revocation closes the grants that name the revoked records, and a C2
|
||||
// revocation closes every grant of the candidate. A later consent record may
|
||||
// create a new grant, but must never reactivate an older record's grant. Future
|
||||
// C5 readers and importers must check the current consent ledger before reading
|
||||
// or synchronizing data and fail closed on a missing grant or ledger error.
|
||||
// An outbox event communicates a committed change; it is never an
|
||||
// authorization check and cannot make a revoked grant current again. This
|
||||
// release has no external FSP or downstream contact-grant adapter, so those
|
||||
// external effects are not claimed as complete.
|
||||
type ConsentRevocationEffects interface {
|
||||
// Apply synchronously closes and records a C2 publication when present,
|
||||
// then appends one bounded durable outbox intent per affected consent record
|
||||
// with its stored scope. It must not truncate or omit affected records. A
|
||||
// future local C2/C4 grant adapter must implement record-bound closure in
|
||||
// this same UnitOfWork before the outbox intent is appended. An empty record
|
||||
// set is not a valid call.
|
||||
// Apply closes the local grants and the C2 publication when present, in the
|
||||
// caller's transaction, then appends one bounded durable outbox intent per
|
||||
// affected consent record with its stored scope. It must not truncate or
|
||||
// omit affected records. An empty record set is not a valid call.
|
||||
Apply(ctx context.Context, revocation domain.ConsentRevocation, records []domain.ConsentRecord) error
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,25 @@ var ErrContactGrantNotFound = errors.New("contact grant not found")
|
||||
|
||||
// ContactGrantRepository stores the contact grants of accepted invitations. A
|
||||
// grant is created in the acceptance transaction next to its consent C4
|
||||
// record; it is never updated here, and a read is always scoped by the
|
||||
// organization.
|
||||
// record. Its revocation stamp is set only by the consent revocation and the
|
||||
// visibility changes, through the closing statements of the postgres adapter.
|
||||
// A read is always scoped by the organization.
|
||||
type ContactGrantRepository interface {
|
||||
// Create inserts the grant in the surrounding transaction. The database
|
||||
// checks that the grant agrees with its consent record and invitation.
|
||||
Create(ctx context.Context, grant domain.ContactGrant) error
|
||||
|
||||
// GetByInvitation returns the grant of one invitation of one organization,
|
||||
// or ErrContactGrantNotFound.
|
||||
// or ErrContactGrantNotFound. It takes no lock, so its result is only a
|
||||
// starting point: a contact read locks the grant with LockForRead before it
|
||||
// decides.
|
||||
GetByInvitation(ctx context.Context, organizationID, invitationID uuid.UUID) (domain.ContactGrant, error)
|
||||
|
||||
// LockForRead share-locks the consent C4 record and then the grant that
|
||||
// grant names, in that order, and returns the grant as stored now. The
|
||||
// boolean reports whether the C4 record is still unrevoked. Both locks
|
||||
// last until the surrounding transaction ends, so a revocation that commits
|
||||
// first is seen here, and a revocation that waits closes the grant after the
|
||||
// read. It returns ErrContactGrantNotFound when the grant has no row.
|
||||
LockForRead(ctx context.Context, grant domain.ContactGrant) (domain.ContactGrant, bool, error)
|
||||
}
|
||||
@@ -144,6 +144,29 @@ type InvitationRepository interface {
|
||||
// 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
|
||||
|
||||
// CountPendingNeedInvitations counts the invitations of the organization
|
||||
// under the need that wait for an answer: delivered, viewed, or counter.
|
||||
// The caller holds the organization lock, which every send takes first.
|
||||
CountPendingNeedInvitations(ctx context.Context, organizationID, needID uuid.UUID) (int64, error)
|
||||
|
||||
// LatestDeclineTime returns the time of the latest decline of the candidate
|
||||
// by the organization, across its needs and members. It reports false when
|
||||
// the pair has no decline.
|
||||
LatestDeclineTime(ctx context.Context, organizationID, candidateID uuid.UUID) (time.Time, bool, error)
|
||||
|
||||
// GetForDeadline locks the row of an invitation by its identifier alone and
|
||||
// returns it, or ErrInvitationNotFound. Only the response deadline job reads
|
||||
// an invitation without the organization or the candidate of a request.
|
||||
GetForDeadline(ctx context.Context, invitationID uuid.UUID) (domain.Invitation, error)
|
||||
|
||||
// Expire moves a delivered or viewed invitation from expectedVersion to the
|
||||
// expired version of next, when its deadline has passed at the expiry time
|
||||
// of next, and records the audit event. It returns
|
||||
// ErrInvitationVersionConflict when the stored row is not waiting for an
|
||||
// answer at expectedVersion or its deadline has not passed. Nothing else
|
||||
// changes: no consent, grant, or quota is written or returned.
|
||||
Expire(ctx context.Context, expectedVersion int64, next domain.Invitation, event domain.InvitationEvent) error
|
||||
}
|
||||
|
||||
// InvitationCreationResultRepository stores the original response of a
|
||||
|
||||
Reference in new issue
Block a user