From 3277f6acf77ab7dbb6392a459a44e474878008e5 Mon Sep 17 00:00:00 2001 From: sytone Date: Wed, 2 Jun 2021 21:20:22 +0000 Subject: [PATCH 1/4] Add default list setting (#875) Co-authored-by: Sytone Reviewed-on: https://kolaente.dev/vikunja/api/pulls/875 Reviewed-by: konrad Co-authored-by: sytone Co-committed-by: sytone --- .editorconfig | 22 +++++++++++++++ pkg/migration/20210527105701.go | 43 ++++++++++++++++++++++++++++++ pkg/routes/api/v1/user_settings.go | 4 +++ pkg/routes/api/v1/user_show.go | 1 + pkg/swagger/docs.go | 4 +++ pkg/swagger/swagger.json | 4 +++ pkg/swagger/swagger.yaml | 5 ++++ pkg/user/user.go | 10 ++++--- 8 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 .editorconfig create mode 100644 pkg/migration/20210527105701.go diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..8e994f3ca1 --- /dev/null +++ b/.editorconfig @@ -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 \ No newline at end of file diff --git a/pkg/migration/20210527105701.go b/pkg/migration/20210527105701.go new file mode 100644 index 0000000000..3f6a96f6bc --- /dev/null +++ b/pkg/migration/20210527105701.go @@ -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 . + +package migration + +import ( + "src.techknowlogick.com/xormigrate" + "xorm.io/xorm" +) + +type users20210527105701 struct { + DefaultListID int64 `xorm:"bigint null index" json:"-"` +} + +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 + }, + }) +} diff --git a/pkg/routes/api/v1/user_settings.go b/pkg/routes/api/v1/user_settings.go index e5255efe89..3eacef8e8a 100644 --- a/pkg/routes/api/v1/user_settings.go +++ b/pkg/routes/api/v1/user_settings.go @@ -45,6 +45,9 @@ type UserSettings struct { 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"` + // 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"` } // GetUserAvatarProvider returns the currently set user avatar @@ -170,6 +173,7 @@ func UpdateGeneralUserSettings(c echo.Context) error { user.DiscoverableByEmail = us.DiscoverableByEmail user.DiscoverableByName = us.DiscoverableByName user.OverdueTasksRemindersEnabled = us.OverdueTasksRemindersEnabled + user.DefaultListID = us.DefaultListID _, err = user2.UpdateUser(s, user) if err != nil { diff --git a/pkg/routes/api/v1/user_show.go b/pkg/routes/api/v1/user_show.go index 601962d634..b9793997a5 100644 --- a/pkg/routes/api/v1/user_show.go +++ b/pkg/routes/api/v1/user_show.go @@ -68,6 +68,7 @@ func UserShow(c echo.Context) error { DiscoverableByName: u.DiscoverableByName, DiscoverableByEmail: u.DiscoverableByEmail, OverdueTasksRemindersEnabled: u.OverdueTasksRemindersEnabled, + DefaultListID: u.DefaultListID, }, } diff --git a/pkg/swagger/docs.go b/pkg/swagger/docs.go index f7e878ebbd..b4d89e9cc5 100644 --- a/pkg/swagger/docs.go +++ b/pkg/swagger/docs.go @@ -8556,6 +8556,10 @@ var doc = `{ "v1.UserSettings": { "type": "object", "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": { "description": "If true, the user can be found when searching for their exact email.", "type": "boolean" diff --git a/pkg/swagger/swagger.json b/pkg/swagger/swagger.json index 7428aeb831..70e7ef04d3 100644 --- a/pkg/swagger/swagger.json +++ b/pkg/swagger/swagger.json @@ -8539,6 +8539,10 @@ "v1.UserSettings": { "type": "object", "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": { "description": "If true, the user can be found when searching for their exact email.", "type": "boolean" diff --git a/pkg/swagger/swagger.yaml b/pkg/swagger/swagger.yaml index bfa224f284..3bb815c664 100644 --- a/pkg/swagger/swagger.yaml +++ b/pkg/swagger/swagger.yaml @@ -1178,6 +1178,11 @@ definitions: type: object v1.UserSettings: 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: description: If true, the user can be found when searching for their exact email. diff --git a/pkg/user/user.go b/pkg/user/user.go index 8b32510a28..2108c87354 100644 --- a/pkg/user/user.go +++ b/pkg/user/user.go @@ -67,10 +67,11 @@ type User struct { Issuer string `xorm:"text null" json:"-"` Subject string `xorm:"text null" json:"-"` - EmailRemindersEnabled bool `xorm:"bool default true" json:"-"` - DiscoverableByName bool `xorm:"bool default false index" json:"-"` - DiscoverableByEmail bool `xorm:"bool default false index" json:"-"` - OverdueTasksRemindersEnabled bool `xorm:"bool default true index" json:"-"` + EmailRemindersEnabled bool `xorm:"bool default true" json:"-"` + DiscoverableByName bool `xorm:"bool default false index" json:"-"` + DiscoverableByEmail bool `xorm:"bool default false index" json:"-"` + OverdueTasksRemindersEnabled bool `xorm:"bool default true index" json:"-"` + DefaultListID int64 `xorm:"bigint null index" json:"-"` // A timestamp when this task was created. You cannot change this value. 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_email", "overdue_tasks_reminders_enabled", + "default_list_id", ). Update(user) if err != nil { From fc5703ac8cbaa3cfbca8957977dd5f8134b3ab44 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 3 Jun 2021 15:30:31 +0200 Subject: [PATCH 2/4] Add truncate parameter to test fixtures setup --- pkg/db/dump.go | 3 +++ pkg/routes/api/v1/testing.go | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/db/dump.go b/pkg/db/dump.go index faf5402631..334b4d1ed7 100644 --- a/pkg/db/dump.go +++ b/pkg/db/dump.go @@ -47,6 +47,9 @@ func Dump() (data map[string][]byte, err error) { // Restore restores a table with all its entries func Restore(table string, contents []map[string]interface{}) (err error) { + if _, err := x.IsTableExist(table); err != nil { + return err + } for _, content := range contents { if _, err := x.Table(table).Insert(content); err != nil { diff --git a/pkg/routes/api/v1/testing.go b/pkg/routes/api/v1/testing.go index ac4b4ff0f3..ac81a44a38 100644 --- a/pkg/routes/api/v1/testing.go +++ b/pkg/routes/api/v1/testing.go @@ -58,7 +58,13 @@ func HandleTesting(c echo.Context) error { }) } - err = db.RestoreAndTruncate(table, content) + truncate := c.QueryParam("truncate") + if truncate == "true" || truncate == "" { + err = db.RestoreAndTruncate(table, content) + } else { + err = db.Restore(table, content) + } + if err != nil { return c.JSON(http.StatusInternalServerError, map[string]interface{}{ "error": true, From 78a206c81830b44aaeee3f921d903cc2136e989e Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 3 Jun 2021 18:11:44 +0200 Subject: [PATCH 3/4] Add setting for first day of the week --- pkg/migration/20210603174608.go | 43 ++++++++++++++++++++++++++++++ pkg/routes/api/v1/user_settings.go | 3 +++ pkg/routes/api/v1/user_show.go | 1 + pkg/swagger/docs.go | 4 +++ pkg/swagger/swagger.json | 4 +++ pkg/swagger/swagger.yaml | 4 +++ pkg/user/user.go | 2 ++ 7 files changed, 61 insertions(+) create mode 100644 pkg/migration/20210603174608.go diff --git a/pkg/migration/20210603174608.go b/pkg/migration/20210603174608.go new file mode 100644 index 0000000000..3eeb374f75 --- /dev/null +++ b/pkg/migration/20210603174608.go @@ -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 . + +package migration + +import ( + "src.techknowlogick.com/xormigrate" + "xorm.io/xorm" +) + +type users20210603174608 struct { + WeekStart int `xorm:"null" json:"-"` +} + +func (users20210603174608) TableName() string { + return "users" +} + +func init() { + migrations = append(migrations, &xormigrate.Migration{ + ID: "20210603174608", + Description: "Add week start user setting", + Migrate: func(tx *xorm.Engine) error { + return tx.Sync2(users20210603174608{}) + }, + Rollback: func(tx *xorm.Engine) error { + return nil + }, + }) +} diff --git a/pkg/routes/api/v1/user_settings.go b/pkg/routes/api/v1/user_settings.go index 3eacef8e8a..c112e031d9 100644 --- a/pkg/routes/api/v1/user_settings.go +++ b/pkg/routes/api/v1/user_settings.go @@ -48,6 +48,8 @@ type UserSettings struct { // 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"` + // The day when the week starts for this user. 0 = sunday, 1 = monday, etc. + WeekStart int `json:"week_start"` } // GetUserAvatarProvider returns the currently set user avatar @@ -174,6 +176,7 @@ func UpdateGeneralUserSettings(c echo.Context) error { user.DiscoverableByName = us.DiscoverableByName user.OverdueTasksRemindersEnabled = us.OverdueTasksRemindersEnabled user.DefaultListID = us.DefaultListID + user.WeekStart = us.WeekStart _, err = user2.UpdateUser(s, user) if err != nil { diff --git a/pkg/routes/api/v1/user_show.go b/pkg/routes/api/v1/user_show.go index b9793997a5..1277b1cb3b 100644 --- a/pkg/routes/api/v1/user_show.go +++ b/pkg/routes/api/v1/user_show.go @@ -69,6 +69,7 @@ func UserShow(c echo.Context) error { DiscoverableByEmail: u.DiscoverableByEmail, OverdueTasksRemindersEnabled: u.OverdueTasksRemindersEnabled, DefaultListID: u.DefaultListID, + WeekStart: u.WeekStart, }, } diff --git a/pkg/swagger/docs.go b/pkg/swagger/docs.go index b4d89e9cc5..b84260c24e 100644 --- a/pkg/swagger/docs.go +++ b/pkg/swagger/docs.go @@ -8579,6 +8579,10 @@ var doc = `{ "overdue_tasks_reminders_enabled": { "description": "If enabled, the user will get an email for their overdue tasks each morning.", "type": "boolean" + }, + "week_start": { + "description": "The day when the week starts for this user. 0 = sunday, 1 = monday, etc.", + "type": "integer" } } }, diff --git a/pkg/swagger/swagger.json b/pkg/swagger/swagger.json index 70e7ef04d3..f3f52a2ed3 100644 --- a/pkg/swagger/swagger.json +++ b/pkg/swagger/swagger.json @@ -8562,6 +8562,10 @@ "overdue_tasks_reminders_enabled": { "description": "If enabled, the user will get an email for their overdue tasks each morning.", "type": "boolean" + }, + "week_start": { + "description": "The day when the week starts for this user. 0 = sunday, 1 = monday, etc.", + "type": "integer" } } }, diff --git a/pkg/swagger/swagger.yaml b/pkg/swagger/swagger.yaml index 3bb815c664..2c17c828bb 100644 --- a/pkg/swagger/swagger.yaml +++ b/pkg/swagger/swagger.yaml @@ -1201,6 +1201,10 @@ definitions: description: If enabled, the user will get an email for their overdue tasks each morning. type: boolean + week_start: + description: The day when the week starts for this user. 0 = sunday, 1 = monday, + etc. + type: integer type: object v1.authInfo: properties: diff --git a/pkg/user/user.go b/pkg/user/user.go index 2108c87354..796de8c924 100644 --- a/pkg/user/user.go +++ b/pkg/user/user.go @@ -72,6 +72,7 @@ type User struct { DiscoverableByEmail bool `xorm:"bool default false index" json:"-"` OverdueTasksRemindersEnabled bool `xorm:"bool default true index" json:"-"` DefaultListID int64 `xorm:"bigint null index" json:"-"` + WeekStart int `xorm:"null" json:"-"` // A timestamp when this task was created. You cannot change this value. Created time.Time `xorm:"created not null" json:"created"` @@ -373,6 +374,7 @@ func UpdateUser(s *xorm.Session, user *User) (updatedUser *User, err error) { "discoverable_by_email", "overdue_tasks_reminders_enabled", "default_list_id", + "week_start", ). Update(user) if err != nil { From cc2c158b9db50cf1a97ae0256140e99c86e89053 Mon Sep 17 00:00:00 2001 From: renovate Date: Mon, 7 Jun 2021 16:15:28 +0000 Subject: [PATCH 4/4] Update golang.org/x/image commit hash to 775e3b0 (#880) Reviewed-on: https://kolaente.dev/vikunja/api/pulls/880 Co-authored-by: renovate Co-committed-by: renovate --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 6122a1dbe1..0dbd1f6ad7 100644 --- a/go.mod +++ b/go.mod @@ -70,7 +70,7 @@ require ( github.com/ulule/limiter/v3 v3.8.0 github.com/yuin/goldmark v1.3.7 golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a - golang.org/x/image v0.0.0-20210504121937-7319ad40d33e + golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9 golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirect golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c golang.org/x/sync v0.0.0-20210220032951-036812b2e83c diff --git a/go.sum b/go.sum index 07c28175e8..e2fcf092ec 100644 --- a/go.sum +++ b/go.sum @@ -825,6 +825,8 @@ golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+o golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20210504121937-7319ad40d33e h1:PzJMNfFQx+QO9hrC1GwZ4BoPGeNGhfeQEgcQFArEjPk= golang.org/x/image v0.0.0-20210504121937-7319ad40d33e/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9 h1:D0iM1dTCbD5Dg1CbuvLC/v/agLc79efSj/L35Q3Vqhs= +golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=