feat(invitations): check contact grants on every read, cap pending invitations, and expire them at the deadline

This commit is contained in:
shira committed 2026-10-09 19:06:50 +03:00
1 parent 676b3c6e24
commit 12a7213d4a
67 files changed
+4255 -149

No files matched your search

@@ -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)
}