feat(invitations): send invitations into the candidate inbox atomically
This commit is contained in:
1 parent
fc35e27af5
commit
1a067221f7
46 files changed
+3276
-113
No files matched your search
@@ -1,7 +1,9 @@
|
||||
// Package invitation applies the owner-only rules of invitation drafts: the
|
||||
// terms and their immutable versions, the link to a candidate card of the
|
||||
// organization, and the idempotent creation. Sending, the candidate's side, and
|
||||
// the contact grant belong to later operations that build on the same records.
|
||||
// Package invitation applies the owner-only rules of invitation drafts and of
|
||||
// their sending: the terms and their immutable versions, the link to a
|
||||
// candidate card of the organization, the idempotent creation, and the
|
||||
// idempotent send that delivers a draft to the candidate's inbox. It also
|
||||
// lists that inbox for the candidate. The candidate's answers and the contact
|
||||
// grant belong to later operations that build on the same records.
|
||||
package invitation
|
||||
|
||||
import (
|
||||
@@ -60,6 +62,21 @@ type Keyring interface {
|
||||
// not use. The identifier it returns never leaves the server.
|
||||
type CandidateResolver func(ctx context.Context, unit outbound.UnitOfWork, actorID, organizationID uuid.UUID, handle string) (uuid.UUID, error)
|
||||
|
||||
// InvitationQuota reserves one invitation of the organization quota inside
|
||||
// the caller's transaction. Bootstrap adapts the shared company-quota usecase,
|
||||
// so the verification tiers and their limits stay in one place. Repeating an
|
||||
// invitation that is already charged is allowed without a second charge.
|
||||
type InvitationQuota func(ctx context.Context, unit outbound.UnitOfWork, organization domain.Organization, invitationID uuid.UUID) (outbound.CompanyQuotaDecision, error)
|
||||
|
||||
// DeliveryNotifier records, inside the caller's transaction, the outbox
|
||||
// events that tell the candidate about a delivered invitation: the in-platform
|
||||
// notification and the email. Neither blocks the delivery: the invitation is
|
||||
// in the candidate's inbox when the transaction commits, and an email that
|
||||
// fails or is retried later never changes it.
|
||||
type DeliveryNotifier interface {
|
||||
InvitationDelivered(ctx context.Context, unit outbound.UnitOfWork, invitation domain.Invitation) error
|
||||
}
|
||||
|
||||
// Dependencies configure one stateless invitation service.
|
||||
type Dependencies struct {
|
||||
Transactor outbound.Transactor
|
||||
@@ -69,21 +86,27 @@ type Dependencies struct {
|
||||
// a handle in an invitation is the handle of the card.
|
||||
PseudonymKey domain.CandidateViewPseudonymKey
|
||||
Candidates CandidateResolver
|
||||
Quota InvitationQuota
|
||||
Notifier DeliveryNotifier
|
||||
Clock func() time.Time
|
||||
}
|
||||
|
||||
// Service applies organization-scoped invitation draft commands and reads.
|
||||
// Service applies organization-scoped invitation commands and reads, and the
|
||||
// candidate's read of the own inbox.
|
||||
type Service struct {
|
||||
transactor outbound.Transactor
|
||||
keyring Keyring
|
||||
pseudonymKey domain.CandidateViewPseudonymKey
|
||||
candidates CandidateResolver
|
||||
quota InvitationQuota
|
||||
notifier DeliveryNotifier
|
||||
clock func() time.Time
|
||||
}
|
||||
|
||||
// NewService fails at startup when a required dependency is missing.
|
||||
func NewService(deps Dependencies) (*Service, error) {
|
||||
if deps.Transactor == nil || deps.Keyring == nil || deps.Candidates == nil || deps.Clock == nil {
|
||||
if deps.Transactor == nil || deps.Keyring == nil || deps.Candidates == nil || deps.Quota == nil ||
|
||||
deps.Notifier == nil || deps.Clock == nil {
|
||||
return nil, errors.New("invitation.NewService - every dependency must be set")
|
||||
}
|
||||
if _, err := deps.PseudonymKey.ForOrganization(uuid.New(), uuid.New()); err != nil {
|
||||
@@ -91,7 +114,7 @@ func NewService(deps Dependencies) (*Service, error) {
|
||||
}
|
||||
return &Service{
|
||||
transactor: deps.Transactor, keyring: deps.Keyring, pseudonymKey: deps.PseudonymKey,
|
||||
candidates: deps.Candidates, clock: deps.Clock,
|
||||
candidates: deps.Candidates, quota: deps.Quota, notifier: deps.Notifier, clock: deps.Clock,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user