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
@@ -58,14 +58,20 @@ func ParseMailKind(value string) (MailKind, error) {
|
||||
}
|
||||
|
||||
// ServiceMailKinds lists the kinds of service identity mail, the kinds the
|
||||
// sending worker claims and sends. Notifications are not among them until
|
||||
// their sending is connected. The delivery metrics of due mail,
|
||||
// the sending worker, and the due index of the deliveries table follow this
|
||||
// list; changing it changes the predicate of deliveries_due_idx too.
|
||||
// service sending worker claims and sends. The delivery metrics of due mail
|
||||
// and the due index of the deliveries table follow this list; changing it
|
||||
// changes the predicate of deliveries_due_idx too.
|
||||
func ServiceMailKinds() []MailKind {
|
||||
return []MailKind{MailKindVerification, MailKindPasswordReset}
|
||||
}
|
||||
|
||||
// ProductMailKinds lists the kinds of product notifications, the kinds the
|
||||
// notification sending worker claims. Its claim has its own partial index,
|
||||
// deliveries_product_due_idx, which follows this list.
|
||||
func ProductMailKinds() []MailKind {
|
||||
return []MailKind{MailKindNotification}
|
||||
}
|
||||
|
||||
// IsServiceMail reports a kind of service identity mail.
|
||||
func (kind MailKind) IsServiceMail() bool { return kind.CarriesBearerToken() }
|
||||
|
||||
@@ -173,6 +179,17 @@ func RestoreRedactedMailContent(kind MailKind, templateVersion, subject string,
|
||||
if _, err := ParseMailKind(string(kind)); err != nil || !kind.CarriesBearerToken() {
|
||||
return MailContent{}, invalidMailContent("only a token mail has redacted content")
|
||||
}
|
||||
return restoreRedactedContent(location, kind, templateVersion, subject, hash)
|
||||
}
|
||||
|
||||
// RestoreRedactedNotificationContent rebuilds the content of a notification
|
||||
// whose bodies were cleared when it was cancelled. Like a redacted token mail,
|
||||
// it keeps the subject and the hash and can never be sent.
|
||||
func RestoreRedactedNotificationContent(templateVersion, subject string, hash []byte) (MailContent, error) {
|
||||
return restoreRedactedContent("domain.RestoreRedactedNotificationContent", MailKindNotification, templateVersion, subject, hash)
|
||||
}
|
||||
|
||||
func restoreRedactedContent(location string, kind MailKind, templateVersion, subject string, hash []byte) (MailContent, error) {
|
||||
if !mailTemplateVersionPattern.MatchString(templateVersion) || !strings.HasPrefix(templateVersion, string(kind)+".v") ||
|
||||
strings.TrimSpace(subject) == "" || utf8.RuneCountInString(subject) > maxMailSubjectRunes {
|
||||
return MailContent{}, fmt.Errorf("%s - stored version or subject is invalid: %w", location, ErrInvalidMailContent)
|
||||
|
||||
Reference in new issue
Block a user