feat(notifications): send product notifications with a rights check right before each send
This commit is contained in:
1 parent
a856066316
commit
623d41b969
59 files changed
+4125
-1126
No files matched your search
@@ -44,6 +44,22 @@ func NewMailQuotaLimits(daily, monthly int64) (MailQuotaLimits, error) {
|
||||
|
||||
func (limits MailQuotaLimits) IsZero() bool { return limits.daily == 0 }
|
||||
|
||||
// WithReserve returns the limits that a sender may use when daily and monthly
|
||||
// recipients stay free for other mail. Each window keeps its own reserve, so
|
||||
// the result is checked window by window; it may not keep the rule that the
|
||||
// daily limit does not exceed the monthly one, which the configuration keeps.
|
||||
// A reserve must be zero or more and leave at least one recipient per window.
|
||||
func (limits MailQuotaLimits) WithReserve(daily, monthly int64) (MailQuotaLimits, error) {
|
||||
const location = "domain.MailQuotaLimits.WithReserve"
|
||||
switch {
|
||||
case daily < 0 || monthly < 0:
|
||||
return MailQuotaLimits{}, fmt.Errorf("%s - reserves must not be negative: %w", location, ErrInvalidMailQuota)
|
||||
case daily >= limits.daily || monthly >= limits.monthly:
|
||||
return MailQuotaLimits{}, fmt.Errorf("%s - a reserve must leave room in its window: %w", location, ErrInvalidMailQuota)
|
||||
}
|
||||
return MailQuotaLimits{daily: limits.daily - daily, monthly: limits.monthly - monthly}, nil
|
||||
}
|
||||
|
||||
func (limits MailQuotaLimits) Daily() int64 { return limits.daily }
|
||||
|
||||
func (limits MailQuotaLimits) Monthly() int64 { return limits.monthly }
|
||||
|
||||
Reference in new issue
Block a user