41 lines
1.9 KiB
Go
41 lines
1.9 KiB
Go
package outbound
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"lincodex/backend/internal/domain"
|
|
)
|
|
|
|
// ErrContactGrantNotFound reports that the invitation has no contact grant of
|
|
// the organization. An accepted invitation always has one, so a missing grant
|
|
// of an accepted invitation is a storage defect.
|
|
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. 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. 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)
|
|
}
|