Add overdue notification setting
This commit is contained in:
parent
2c123d146d
commit
180384ec7d
43
pkg/migration/20210411161337.go
Normal file
43
pkg/migration/20210411161337.go
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
// Vikunja is a to-do list application to facilitate your life.
|
||||||
|
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public Licensee as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public Licensee for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public Licensee
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package migration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"src.techknowlogick.com/xormigrate"
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type users20210411161337 struct {
|
||||||
|
OverdueTasksRemindersEnabled bool `xorm:"bool default true index" json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (users20210411161337) TableName() string {
|
||||||
|
return "users"
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
migrations = append(migrations, &xormigrate.Migration{
|
||||||
|
ID: "20210411161337",
|
||||||
|
Description: "Add overdue notifications enabled setting to users",
|
||||||
|
Migrate: func(tx *xorm.Engine) error {
|
||||||
|
return tx.Sync2(users20210411161337{})
|
||||||
|
},
|
||||||
|
Rollback: func(tx *xorm.Engine) error {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -17,13 +17,15 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/cron"
|
"code.vikunja.io/api/pkg/cron"
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/notifications"
|
"code.vikunja.io/api/pkg/notifications"
|
||||||
"code.vikunja.io/api/pkg/utils"
|
"code.vikunja.io/api/pkg/utils"
|
||||||
"time"
|
"xorm.io/builder"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -68,7 +70,7 @@ func RegisterOverdueReminderCron() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
users, err := getTaskUsersForTasks(s, taskIDs)
|
users, err := getTaskUsersForTasks(s, taskIDs, builder.Eq{"users.overdue_tasks_reminders_enabled": true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("[Undone Overdue Tasks Reminder] Could not get task users to send them reminders: %s", err)
|
log.Errorf("[Undone Overdue Tasks Reminder] Could not get task users to send them reminders: %s", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -17,9 +17,11 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/utils"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/utils"
|
||||||
|
"xorm.io/builder"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/notifications"
|
"code.vikunja.io/api/pkg/notifications"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
@ -51,7 +53,7 @@ type taskUser struct {
|
||||||
|
|
||||||
const dbTimeFormat = `2006-01-02 15:04:05`
|
const dbTimeFormat = `2006-01-02 15:04:05`
|
||||||
|
|
||||||
func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64) (taskUsers []*taskUser, err error) {
|
func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64, cond builder.Cond) (taskUsers []*taskUser, err error) {
|
||||||
if len(taskIDs) == 0 {
|
if len(taskIDs) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -62,7 +64,7 @@ func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64) (taskUsers []*taskUs
|
||||||
Select("users.id, users.username, users.email, users.name").
|
Select("users.id, users.username, users.email, users.name").
|
||||||
Join("LEFT", "tasks", "tasks.created_by_id = users.id").
|
Join("LEFT", "tasks", "tasks.created_by_id = users.id").
|
||||||
In("tasks.id", taskIDs).
|
In("tasks.id", taskIDs).
|
||||||
Where("users.email_reminders_enabled = true").
|
Where(cond).
|
||||||
GroupBy("tasks.id, users.id, users.username, users.email, users.name").
|
GroupBy("tasks.id, users.id, users.username, users.email, users.name").
|
||||||
Find(&creators)
|
Find(&creators)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -87,15 +89,18 @@ func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64) (taskUsers []*taskUs
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
assignees, err := getRawTaskAssigneesForTasks(s, taskIDs)
|
var assignees []*TaskAssigneeWithUser
|
||||||
|
err = s.Table("task_assignees").
|
||||||
|
Select("task_id, users.*").
|
||||||
|
In("task_id", taskIDs).
|
||||||
|
Join("INNER", "users", "task_assignees.user_id = users.id").
|
||||||
|
Where(cond).
|
||||||
|
Find(&assignees)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, assignee := range assignees {
|
for _, assignee := range assignees {
|
||||||
if !assignee.EmailRemindersEnabled { // Can't filter that through a query directly since we're using another function
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
taskUsers = append(taskUsers, &taskUser{
|
taskUsers = append(taskUsers, &taskUser{
|
||||||
Task: taskMap[assignee.TaskID],
|
Task: taskMap[assignee.TaskID],
|
||||||
User: &assignee.User,
|
User: &assignee.User,
|
||||||
|
@ -167,7 +172,7 @@ func RegisterReminderCron() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
users, err := getTaskUsersForTasks(s, taskIDs)
|
users, err := getTaskUsersForTasks(s, taskIDs, builder.Eq{"users.email_reminders_enabled": true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("[Task Reminder Cron] Could not get task users to send them reminders: %s", err)
|
log.Errorf("[Task Reminder Cron] Could not get task users to send them reminders: %s", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -43,6 +43,8 @@ type UserSettings struct {
|
||||||
DiscoverableByName bool `json:"discoverable_by_name"`
|
DiscoverableByName bool `json:"discoverable_by_name"`
|
||||||
// If true, the user can be found when searching for their exact email.
|
// If true, the user can be found when searching for their exact email.
|
||||||
DiscoverableByEmail bool `json:"discoverable_by_email"`
|
DiscoverableByEmail bool `json:"discoverable_by_email"`
|
||||||
|
// If enabled, the user will get an email for their overdue tasks each morning.
|
||||||
|
OverdueTasksRemindersEnabled bool `json:"overdue_tasks_reminders_enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserAvatarProvider returns the currently set user avatar
|
// GetUserAvatarProvider returns the currently set user avatar
|
||||||
|
@ -167,6 +169,7 @@ func UpdateGeneralUserSettings(c echo.Context) error {
|
||||||
user.EmailRemindersEnabled = us.EmailRemindersEnabled
|
user.EmailRemindersEnabled = us.EmailRemindersEnabled
|
||||||
user.DiscoverableByEmail = us.DiscoverableByEmail
|
user.DiscoverableByEmail = us.DiscoverableByEmail
|
||||||
user.DiscoverableByName = us.DiscoverableByName
|
user.DiscoverableByName = us.DiscoverableByName
|
||||||
|
user.OverdueTasksRemindersEnabled = us.OverdueTasksRemindersEnabled
|
||||||
|
|
||||||
_, err = user2.UpdateUser(s, user)
|
_, err = user2.UpdateUser(s, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -67,11 +67,10 @@ type User struct {
|
||||||
Issuer string `xorm:"text null" json:"-"`
|
Issuer string `xorm:"text null" json:"-"`
|
||||||
Subject string `xorm:"text null" json:"-"`
|
Subject string `xorm:"text null" json:"-"`
|
||||||
|
|
||||||
// If enabled, sends email reminders of tasks to the user.
|
|
||||||
EmailRemindersEnabled bool `xorm:"bool default true" json:"-"`
|
EmailRemindersEnabled bool `xorm:"bool default true" json:"-"`
|
||||||
|
|
||||||
DiscoverableByName bool `xorm:"bool default false index" json:"-"`
|
DiscoverableByName bool `xorm:"bool default false index" json:"-"`
|
||||||
DiscoverableByEmail bool `xorm:"bool default false index" json:"-"`
|
DiscoverableByEmail bool `xorm:"bool default false index" json:"-"`
|
||||||
|
OverdueTasksRemindersEnabled bool `xorm:"bool default true index" json:"-"`
|
||||||
|
|
||||||
// A timestamp when this task was created. You cannot change this value.
|
// A timestamp when this task was created. You cannot change this value.
|
||||||
Created time.Time `xorm:"created not null" json:"created"`
|
Created time.Time `xorm:"created not null" json:"created"`
|
||||||
|
@ -371,6 +370,7 @@ func UpdateUser(s *xorm.Session, user *User) (updatedUser *User, err error) {
|
||||||
"email_reminders_enabled",
|
"email_reminders_enabled",
|
||||||
"discoverable_by_name",
|
"discoverable_by_name",
|
||||||
"discoverable_by_email",
|
"discoverable_by_email",
|
||||||
|
"overdue_tasks_reminders_enabled",
|
||||||
).
|
).
|
||||||
Update(user)
|
Update(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user