1
0

feat(notify): don't notify disabled users

This commit is contained in:
kolaente
2023-09-04 14:23:56 +02:00
parent c28d1af877
commit 80b40bb2c0
3 changed files with 84 additions and 28 deletions

View File

@ -17,6 +17,7 @@
package notifications
import (
"code.vikunja.io/api/pkg/log"
"encoding/json"
"code.vikunja.io/api/pkg/db"
@ -40,10 +41,13 @@ type NotificationWithSubject interface {
// Notifiable is an entity which can be notified. Usually a user.
type Notifiable interface {
// Should return the email address this notifiable has.
// RouteForMail should return the email address this notifiable has.
RouteForMail() (string, error)
// Should return the id of the notifiable entity
// RouteForDB should return the id of the notifiable entity to save it in the database.
RouteForDB() int64
// ShouldNotify provides a last-minute way to cancel a notification. It will be called immediately before
// sending a notification.
ShouldNotify() (should bool, err error)
}
// Notify notifies a notifiable of a notification
@ -53,6 +57,12 @@ func Notify(notifiable Notifiable, notification Notification) (err error) {
return nil
}
should, err := notifiable.ShouldNotify()
if err != nil || !should {
log.Debugf("Not notifying user %d because they are disabled", notifiable.RouteForDB())
return err
}
err = notifyMail(notifiable, notification)
if err != nil {
return