feat(identity): confirm registration email atomically
This commit is contained in:
1 parent
8e7ce8d71c
commit
fade4e76e4
75 files changed
+4188
-403
No files matched your search
@@ -379,20 +379,25 @@ type ConsentGrantInput struct {
|
||||
TextVersion ConsentTextVersion
|
||||
TextHash ConsentTextHash
|
||||
Source ConsentSource
|
||||
GrantedAt time.Time
|
||||
// RegistrationVersion binds a registration C1 to the account registration
|
||||
// whose email token carries its pending credentials. It is zero for every
|
||||
// other consent source.
|
||||
RegistrationVersion int64
|
||||
GrantedAt time.Time
|
||||
}
|
||||
|
||||
// ConsentGrant is a validated grant of C1, C2, C3, or C5, ready for the
|
||||
// ledger. C4 is never a ConsentGrant: it needs its organization scope, see
|
||||
// ContactConsentGrant.
|
||||
type ConsentGrant struct {
|
||||
id uuid.UUID
|
||||
subjectID uuid.UUID
|
||||
purpose ConsentPurpose
|
||||
textVersion ConsentTextVersion
|
||||
textHash ConsentTextHash
|
||||
source ConsentSource
|
||||
grantedAt time.Time
|
||||
id uuid.UUID
|
||||
subjectID uuid.UUID
|
||||
purpose ConsentPurpose
|
||||
textVersion ConsentTextVersion
|
||||
textHash ConsentTextHash
|
||||
source ConsentSource
|
||||
registrationVersion int64
|
||||
grantedAt time.Time
|
||||
}
|
||||
|
||||
// NewConsentGrant validates input and assigns a UUIDv7 identifier.
|
||||
@@ -412,6 +417,10 @@ func NewConsentGrant(input ConsentGrantInput) (ConsentGrant, error) {
|
||||
return ConsentGrant{}, fmt.Errorf("%s - subject ID must not be nil: %w", location, ErrInvalidConsent)
|
||||
case !input.Source.allowedFor(input.Purpose):
|
||||
return ConsentGrant{}, fmt.Errorf("%s - source does not allow the purpose: %w", location, ErrInvalidConsent)
|
||||
case input.Source == ConsentSourceRegistration && input.RegistrationVersion <= 0:
|
||||
return ConsentGrant{}, fmt.Errorf("%s - registration C1 requires a positive registration version: %w", location, ErrInvalidConsent)
|
||||
case input.Source != ConsentSourceRegistration && input.RegistrationVersion != 0:
|
||||
return ConsentGrant{}, fmt.Errorf("%s - only registration C1 carries a registration version: %w", location, ErrInvalidConsent)
|
||||
case input.GrantedAt.IsZero():
|
||||
return ConsentGrant{}, fmt.Errorf("%s - grant time must be set: %w", location, ErrInvalidConsent)
|
||||
}
|
||||
@@ -420,13 +429,14 @@ func NewConsentGrant(input ConsentGrantInput) (ConsentGrant, error) {
|
||||
return ConsentGrant{}, fmt.Errorf("%s - generate record ID: %w", location, err)
|
||||
}
|
||||
return ConsentGrant{
|
||||
id: id,
|
||||
subjectID: input.SubjectID,
|
||||
purpose: input.Purpose,
|
||||
textVersion: input.TextVersion,
|
||||
textHash: input.TextHash,
|
||||
source: input.Source,
|
||||
grantedAt: input.GrantedAt,
|
||||
id: id,
|
||||
subjectID: input.SubjectID,
|
||||
purpose: input.Purpose,
|
||||
textVersion: input.TextVersion,
|
||||
textHash: input.TextHash,
|
||||
source: input.Source,
|
||||
registrationVersion: input.RegistrationVersion,
|
||||
grantedAt: input.GrantedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -436,6 +446,7 @@ func (grant ConsentGrant) Purpose() ConsentPurpose { return grant.purpos
|
||||
func (grant ConsentGrant) TextVersion() ConsentTextVersion { return grant.textVersion }
|
||||
func (grant ConsentGrant) TextHash() ConsentTextHash { return grant.textHash }
|
||||
func (grant ConsentGrant) Source() ConsentSource { return grant.source }
|
||||
func (grant ConsentGrant) RegistrationVersion() int64 { return grant.registrationVersion }
|
||||
func (grant ConsentGrant) GrantedAt() time.Time { return grant.grantedAt }
|
||||
|
||||
// IsZero reports a grant not built by NewConsentGrant.
|
||||
@@ -656,6 +667,7 @@ type ConsentRecord struct {
|
||||
textVersion ConsentTextVersion
|
||||
textHash ConsentTextHash
|
||||
source ConsentSource
|
||||
registrationVersion int64
|
||||
state ConsentState
|
||||
grantedAt time.Time
|
||||
revokedAt time.Time
|
||||
@@ -677,6 +689,7 @@ type StoredConsentRecord struct {
|
||||
TextVersion string
|
||||
TextHash []byte
|
||||
Source string
|
||||
RegistrationVersion int64
|
||||
State string
|
||||
GrantedAt time.Time
|
||||
RevokedAt *time.Time
|
||||
@@ -716,6 +729,7 @@ func RestoreConsentRecord(stored StoredConsentRecord) (ConsentRecord, error) {
|
||||
textVersion: version,
|
||||
textHash: hash,
|
||||
source: ConsentSource(stored.Source),
|
||||
registrationVersion: stored.RegistrationVersion,
|
||||
state: state,
|
||||
grantedAt: stored.GrantedAt,
|
||||
revocationSource: ConsentRevocationSource(stored.RevocationSource),
|
||||
@@ -760,6 +774,10 @@ func (record ConsentRecord) validate(hasFieldSet bool) error {
|
||||
return fmt.Errorf("record and subject IDs must not be nil: %w", ErrInvalidConsent)
|
||||
case !record.source.allowedFor(record.purpose):
|
||||
return fmt.Errorf("source does not allow the purpose: %w", ErrInvalidConsent)
|
||||
case record.source == ConsentSourceRegistration && record.registrationVersion <= 0:
|
||||
return fmt.Errorf("registration C1 requires a positive registration version: %w", ErrInvalidConsent)
|
||||
case record.source != ConsentSourceRegistration && record.registrationVersion != 0:
|
||||
return fmt.Errorf("only registration C1 carries a registration version: %w", ErrInvalidConsent)
|
||||
case record.grantedAt.IsZero():
|
||||
return fmt.Errorf("grant time must be set: %w", ErrInvalidConsent)
|
||||
}
|
||||
@@ -810,6 +828,7 @@ func (record ConsentRecord) Purpose() ConsentPurpose { return record.pur
|
||||
func (record ConsentRecord) TextVersion() ConsentTextVersion { return record.textVersion }
|
||||
func (record ConsentRecord) TextHash() ConsentTextHash { return record.textHash }
|
||||
func (record ConsentRecord) Source() ConsentSource { return record.source }
|
||||
func (record ConsentRecord) RegistrationVersion() int64 { return record.registrationVersion }
|
||||
func (record ConsentRecord) State() ConsentState { return record.state }
|
||||
func (record ConsentRecord) GrantedAt() time.Time { return record.grantedAt }
|
||||
|
||||
|
||||
Reference in new issue
Block a user