feat(identity): add server sessions and audited mail recovery

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 11:03:46 +03:00
1 parent 20c03288d6
commit 4ee53d9a74
58 files changed
+5359 -567

No files matched your search

+41
View File
@@ -640,6 +640,47 @@ func (delivery Delivery) Rebind(at time.Time, providerAccount MailProviderAccoun
return next, nil
}
// StopAutomaticRetry ends the automatic retry schedule without claiming that
// an uncertain delivery was not sent. The delivery remains unknown, with no
// due time, so only an audited operator decision can start another send cycle.
// It also accepts pending or waiting_quota when a later confirmed refusal
// leaves an earlier unknown outcome unresolved after the automatic cutoff.
func (delivery Delivery) StopAutomaticRetry(at time.Time) (Delivery, error) {
const location = "Delivery.StopAutomaticRetry"
if err := delivery.checkChangeTime(location, at); err != nil {
return Delivery{}, err
}
if (delivery.status != DeliveryStatusUnknown && delivery.status != DeliveryStatusPending && delivery.status != DeliveryStatusWaitingQuota) || delivery.nextAttemptAt.IsZero() {
return Delivery{}, fmt.Errorf("%s - delivery is %s without a scheduled retry: %w", location, delivery.status, ErrDeliveryTransition)
}
next := delivery
next.status = DeliveryStatusUnknown
next.nextAttemptAt = time.Time{}
next.version = delivery.version + 1
next.updatedAt = at
return next, nil
}
// ScheduleUnknownRetry keeps an unknown delivery in the due queue until a
// provider quota reset. It does not change the outcome or append an attempt.
func (delivery Delivery) ScheduleUnknownRetry(at, nextAttemptAt time.Time) (Delivery, error) {
const location = "Delivery.ScheduleUnknownRetry"
if err := delivery.checkChangeTime(location, at); err != nil {
return Delivery{}, err
}
if delivery.status != DeliveryStatusUnknown || delivery.nextAttemptAt.IsZero() {
return Delivery{}, fmt.Errorf("%s - delivery is %s without an automatic retry: %w", location, delivery.status, ErrDeliveryTransition)
}
if nextAttemptAt.IsZero() || nextAttemptAt.Before(at) {
return Delivery{}, invalidDelivery(location, "next retry time must be set and not precede the decision")
}
next := delivery
next.nextAttemptAt = nextAttemptAt
next.version = delivery.version + 1
next.updatedAt = at
return next, nil
}
// checkChangeTime rejects a zero delivery and a change time before the last
// recorded change.
func (delivery Delivery) checkChangeTime(location string, at time.Time) error {