Add default list setting #875

Merged
konrad merged 6 commits from sytone/api:main into main 2021-06-02 21:20:23 +00:00
8 changed files with 89 additions and 4 deletions

22
.editorconfig Normal file
View File

@ -0,0 +1,22 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
[*.go]
indent_style = tab
[*.{yaml,yml}]
indent_style = space
indent_size = 2
[*.json]
indent_style = space
indent_size = 4

View 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 users20210527105701 struct {
DefaultListID int64 `xorm:"bigint null index" json:"-"`

A few things:

  • This should be an int64 as all other ids are. Same for the xorm tag (I think that is bigint, take a look at the other ID fields).
  • Please make the field nullable and remove the default value. That will also remove the need to update all the tests.
  • I think the field would be better named something like DefaultListID - that way it's clear what this is.
A few things: * This should be an `int64` as all other ids are. Same for the xorm tag (I think that is bigint, take a look at the other ID fields). * Please make the field nullable and remove the default value. That will also remove the need to update all the tests. * I think the field would be better named something like `DefaultListID` - that way it's clear what this is.

Updated and renames, tests updated.

Updated and renames, tests updated.
}
func (users20210527105701) TableName() string {
return "users"
}
func init() {
migrations = append(migrations, &xormigrate.Migration{
ID: "20210527105701",
Description: "Add default list for new tasks setting to users",
Migrate: func(tx *xorm.Engine) error {
return tx.Sync2(users20210527105701{})
},
Rollback: func(tx *xorm.Engine) error {
return nil
},
})
}

View File

@ -45,6 +45,9 @@ type UserSettings struct {
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. // If enabled, the user will get an email for their overdue tasks each morning.
OverdueTasksRemindersEnabled bool `json:"overdue_tasks_reminders_enabled"` OverdueTasksRemindersEnabled bool `json:"overdue_tasks_reminders_enabled"`
// If a task is created without a specified list this value should be used. Applies
// to tasks made directly in API and from clients.
DefaultListID int64 `json:"default_list_id"`

Should be int64 as well.

Should be `int64` as well.

Updated to match.

Updated to match.
} }
// GetUserAvatarProvider returns the currently set user avatar // GetUserAvatarProvider returns the currently set user avatar
@ -170,6 +173,7 @@ func UpdateGeneralUserSettings(c echo.Context) error {
user.DiscoverableByEmail = us.DiscoverableByEmail user.DiscoverableByEmail = us.DiscoverableByEmail
user.DiscoverableByName = us.DiscoverableByName user.DiscoverableByName = us.DiscoverableByName
user.OverdueTasksRemindersEnabled = us.OverdueTasksRemindersEnabled user.OverdueTasksRemindersEnabled = us.OverdueTasksRemindersEnabled
user.DefaultListID = us.DefaultListID
_, err = user2.UpdateUser(s, user) _, err = user2.UpdateUser(s, user)
if err != nil { if err != nil {

View File

@ -68,6 +68,7 @@ func UserShow(c echo.Context) error {
DiscoverableByName: u.DiscoverableByName, DiscoverableByName: u.DiscoverableByName,
DiscoverableByEmail: u.DiscoverableByEmail, DiscoverableByEmail: u.DiscoverableByEmail,
OverdueTasksRemindersEnabled: u.OverdueTasksRemindersEnabled, OverdueTasksRemindersEnabled: u.OverdueTasksRemindersEnabled,
DefaultListID: u.DefaultListID,
}, },
} }

View File

@ -8556,6 +8556,10 @@ var doc = `{
"v1.UserSettings": { "v1.UserSettings": {
"type": "object", "type": "object",
"properties": { "properties": {
"default_list_id": {
"description": "If a task is created without a specified list this value should be used. Applies\nto tasks made directly in API and from clients.",
"type": "integer"
},
"discoverable_by_email": { "discoverable_by_email": {
"description": "If true, the user can be found when searching for their exact email.", "description": "If true, the user can be found when searching for their exact email.",
"type": "boolean" "type": "boolean"

View File

@ -8539,6 +8539,10 @@
"v1.UserSettings": { "v1.UserSettings": {
"type": "object", "type": "object",
"properties": { "properties": {
"default_list_id": {
"description": "If a task is created without a specified list this value should be used. Applies\nto tasks made directly in API and from clients.",
"type": "integer"
},
"discoverable_by_email": { "discoverable_by_email": {
"description": "If true, the user can be found when searching for their exact email.", "description": "If true, the user can be found when searching for their exact email.",
"type": "boolean" "type": "boolean"

View File

@ -1178,6 +1178,11 @@ definitions:
type: object type: object
v1.UserSettings: v1.UserSettings:
properties: properties:
default_list_id:
description: |-
If a task is created without a specified list this value should be used. Applies
to tasks made directly in API and from clients.
type: integer
discoverable_by_email: discoverable_by_email:
description: If true, the user can be found when searching for their exact description: If true, the user can be found when searching for their exact
email. email.

View File

@ -67,10 +67,11 @@ 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:"-"`
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:"-"` OverdueTasksRemindersEnabled bool `xorm:"bool default true index" json:"-"`
DefaultListID int64 `xorm:"bigint null index" json:"-"`

Please see the comments on the migration.

Please see the comments on the migration.

Updated to match migraiton, now null by default, bigint which maps to int64 as verified in the xorm documents.

Updated to match migraiton, now null by default, bigint which maps to int64 as verified in the xorm documents.
// 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 +372,7 @@ func UpdateUser(s *xorm.Session, user *User) (updatedUser *User, err error) {
"discoverable_by_name", "discoverable_by_name",
"discoverable_by_email", "discoverable_by_email",
"overdue_tasks_reminders_enabled", "overdue_tasks_reminders_enabled",
"default_list_id",
). ).
Update(user) Update(user)
if err != nil { if err != nil {