feat: allow saving frontend settings via api

This commit is contained in:
kolaente 2023-06-11 17:49:14 +02:00
parent 4a4ba041e0
commit 04e2c51fac
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 57 additions and 0 deletions

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 users20230611170341 struct {
FrontendSettings interface{} `xorm:"json null" json:"-"`
}
func (users20230611170341) TableName() string {
return "users"
}
func init() {
migrations = append(migrations, &xormigrate.Migration{
ID: "20230611170341",
Description: "",
Migrate: func(tx *xorm.Engine) error {
return tx.Sync2(users20230611170341{})
},
Rollback: func(tx *xorm.Engine) error {
return nil
},
})
}

View File

@ -59,6 +59,8 @@ type UserSettings struct {
Language string `json:"language"`
// The user's time zone. Used to send task reminders in the time zone of the user.
Timezone string `json:"timezone"`
// Additional settings only used by the frontend
FrontendSettings interface{} `json:"frontend_settings"`
}
// GetUserAvatarProvider returns the currently set user avatar
@ -198,6 +200,7 @@ func UpdateGeneralUserSettings(c echo.Context) error {
user.Language = us.Language
user.Timezone = us.Timezone
user.OverdueTasksRemindersTime = us.OverdueTasksRemindersTime
user.FrontendSettings = us.FrontendSettings
_, err = user2.UpdateUser(s, user, true)
if err != nil {

View File

@ -76,6 +76,7 @@ func UserShow(c echo.Context) error {
Language: u.Language,
Timezone: u.Timezone,
OverdueTasksRemindersTime: u.OverdueTasksRemindersTime,
FrontendSettings: u.FrontendSettings,
},
DeletionScheduledAt: u.DeletionScheduledAt,
IsLocalUser: u.Issuer == user.IssuerLocal,

View File

@ -17,6 +17,7 @@
package user
import (
"encoding/json"
"errors"
"fmt"
"reflect"
@ -103,6 +104,8 @@ type User struct {
DeletionScheduledAt time.Time `xorm:"datetime null" json:"-"`
DeletionLastReminderSent time.Time `xorm:"datetime null" json:"-"`
FrontendSettings interface{} `xorm:"json null" json:"-"`
ExportFileID int64 `xorm:"bigint null" json:"-"`
// A timestamp when this task was created. You cannot change this value.
@ -484,6 +487,12 @@ func UpdateUser(s *xorm.Session, user *User, forceOverride bool) (updatedUser *U
return
}
frontendSettingsJSON, err := json.Marshal(user.FrontendSettings)
if err != nil {
return nil, err
}
user.FrontendSettings = frontendSettingsJSON
// Update it
_, err = s.
ID(user.ID).
@ -503,6 +512,7 @@ func UpdateUser(s *xorm.Session, user *User, forceOverride bool) (updatedUser *U
"language",
"timezone",
"overdue_tasks_reminders_time",
"frontend_settings",
).
Update(user)
if err != nil {