From d1823448d4e02c0c1ad5ed04dd10742c2c2a3f63 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 7 Feb 2021 17:42:50 +0100 Subject: [PATCH] Fix trying to send reminders to people who have disabled email reminders --- pkg/models/notifications.go | 2 +- pkg/models/task_reminder.go | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/models/notifications.go b/pkg/models/notifications.go index 25d781743..0a0ba41fe 100644 --- a/pkg/models/notifications.go +++ b/pkg/models/notifications.go @@ -36,7 +36,7 @@ func (n *ReminderDueNotification) ToMail() *notifications.Mail { Subject(`Reminder for "`+n.Task.Title+`"`). Greeting("Hi "+n.User.GetName()+","). Line(`This is a friendly reminder of the task "`+n.Task.Title+`".`). - Action("Open Task", config.ServiceFrontendurl.GetString()+"/tasks/"+strconv.FormatInt(n.Task.ID, 10)). + Action("Open Task", config.ServiceFrontendurl.GetString()+"tasks/"+strconv.FormatInt(n.Task.ID, 10)). Line("Have a nice day!") } diff --git a/pkg/models/task_reminder.go b/pkg/models/task_reminder.go index 40bc7d550..a6c63b746 100644 --- a/pkg/models/task_reminder.go +++ b/pkg/models/task_reminder.go @@ -61,11 +61,6 @@ func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64) (taskUsers []*taskUs return } - assignees, err := getRawTaskAssigneesForTasks(s, taskIDs) - if err != nil { - return - } - taskMap := make(map[int64]*Task, len(taskIDs)) err = s.In("id", taskIDs).Find(&taskMap) if err != nil { @@ -73,12 +68,22 @@ func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64) (taskUsers []*taskUs } for _, taskID := range taskIDs { + u, exists := creators[taskMap[taskID].CreatedByID] + if !exists { + continue + } + taskUsers = append(taskUsers, &taskUser{ Task: taskMap[taskID], - User: creators[taskMap[taskID].CreatedByID], + User: u, }) } + assignees, err := getRawTaskAssigneesForTasks(s, taskIDs) + if err != nil { + return + } + for _, assignee := range assignees { if !assignee.EmailRemindersEnabled { // Can't filter that through a query directly since we're using another function continue