feat(invitations): accept invitations with C4 consent and contact grants; share the E0 quota across holdings
This commit is contained in:
1 parent
a5990d3fc6
commit
676b3c6e24
59 files changed
+4926
-194
No files matched your search
@@ -3,9 +3,9 @@
|
||||
// candidate card of the organization, the idempotent creation, and the
|
||||
// idempotent send that delivers a draft to the candidate's inbox. On the
|
||||
// candidate's side it lists that inbox, reads one invitation, records the
|
||||
// view, and records a structured decline. The acceptance, the cancellation,
|
||||
// and the contact grant belong to later operations that build on the same
|
||||
// records.
|
||||
// view, records a structured decline, and accepts the current terms with the
|
||||
// consent C4 and its contact grant in one transaction. The cancellation and
|
||||
// the revocation of a grant belong to later operations.
|
||||
package invitation
|
||||
|
||||
import (
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
"lincodex/backend/internal/usecase/consent"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -70,6 +71,14 @@ type CandidateResolver func(ctx context.Context, unit outbound.UnitOfWork, actor
|
||||
// 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)
|
||||
|
||||
// ContactConsents is the consent ledger of the acceptance. It reads the
|
||||
// published C4 text, checks the version that the candidate saw, and records
|
||||
// the C4 grant inside the caller's transaction. consent.Service implements it.
|
||||
type ContactConsents interface {
|
||||
CheckTextVersion(ctx context.Context, repositories outbound.ConsentRepositories, purpose domain.ConsentPurpose, version domain.ConsentTextVersion) (domain.ConsentText, error)
|
||||
GrantContact(ctx context.Context, repositories outbound.ConsentRepositories, input consent.ContactGrantInput) (consent.GrantResult, 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
|
||||
@@ -90,11 +99,13 @@ type Dependencies struct {
|
||||
Candidates CandidateResolver
|
||||
Quota InvitationQuota
|
||||
Notifier DeliveryNotifier
|
||||
Clock func() time.Time
|
||||
// Consents records the consent C4 of an acceptance in its transaction.
|
||||
Consents ContactConsents
|
||||
Clock func() time.Time
|
||||
}
|
||||
|
||||
// Service applies organization-scoped invitation commands and reads, and the
|
||||
// candidate's reads, view, and decline of the own invitations.
|
||||
// candidate's reads, view, decline, and acceptance of the own invitations.
|
||||
type Service struct {
|
||||
transactor outbound.Transactor
|
||||
keyring Keyring
|
||||
@@ -102,13 +113,14 @@ type Service struct {
|
||||
candidates CandidateResolver
|
||||
quota InvitationQuota
|
||||
notifier DeliveryNotifier
|
||||
consents ContactConsents
|
||||
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.Quota == nil ||
|
||||
deps.Notifier == nil || deps.Clock == nil {
|
||||
deps.Notifier == nil || deps.Consents == 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 {
|
||||
@@ -116,7 +128,8 @@ func NewService(deps Dependencies) (*Service, error) {
|
||||
}
|
||||
return &Service{
|
||||
transactor: deps.Transactor, keyring: deps.Keyring, pseudonymKey: deps.PseudonymKey,
|
||||
candidates: deps.Candidates, quota: deps.Quota, notifier: deps.Notifier, clock: deps.Clock,
|
||||
candidates: deps.Candidates, quota: deps.Quota, notifier: deps.Notifier, consents: deps.Consents,
|
||||
clock: deps.Clock,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user