feat(auth): allow passing custom settings links to user account via openid claims
This commit is contained in:
parent
3ae8169204
commit
da0f6fb366
|
|
@ -0,0 +1,43 @@
|
||||||
|
// Vikunja is a to-do list application to facilitate your life.
|
||||||
|
// Copyright 2018-present 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 License 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 License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package migration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"src.techknowlogick.com/xormigrate"
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type users20250402173109 struct {
|
||||||
|
ExtraSettingsLinks map[string]any `xorm:"json null" json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (users20250402173109) TableName() string {
|
||||||
|
return "users"
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
migrations = append(migrations, &xormigrate.Migration{
|
||||||
|
ID: "20250402173109",
|
||||||
|
Description: "add extra settings links",
|
||||||
|
Migrate: func(tx *xorm.Engine) error {
|
||||||
|
return tx.Sync(users20250402173109{})
|
||||||
|
},
|
||||||
|
Rollback: func(tx *xorm.Engine) error {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -68,12 +68,13 @@ type Provider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type claims struct {
|
type claims struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
PreferredUsername string `json:"preferred_username"`
|
PreferredUsername string `json:"preferred_username"`
|
||||||
Nickname string `json:"nickname"`
|
Nickname string `json:"nickname"`
|
||||||
VikunjaGroups []map[string]interface{} `json:"vikunja_groups"`
|
VikunjaGroups []map[string]interface{} `json:"vikunja_groups"`
|
||||||
Picture string `json:"picture"`
|
Picture string `json:"picture"`
|
||||||
|
ExtraSettingsLinks map[string]any `json:"extra_settings_links"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -304,13 +305,15 @@ func getOrCreateUser(s *xorm.Session, cl *claims, provider *Provider, idToken *o
|
||||||
|
|
||||||
// If no user exists, create one with the preferred username if it is not already taken
|
// If no user exists, create one with the preferred username if it is not already taken
|
||||||
uu := &user.User{
|
uu := &user.User{
|
||||||
Username: strings.ReplaceAll(cl.PreferredUsername, " ", "-"),
|
Username: strings.ReplaceAll(cl.PreferredUsername, " ", "-"),
|
||||||
Email: cl.Email,
|
Email: cl.Email,
|
||||||
Name: cl.Name,
|
Name: cl.Name,
|
||||||
Status: user.StatusActive,
|
Status: user.StatusActive,
|
||||||
Issuer: idToken.Issuer,
|
Issuer: idToken.Issuer,
|
||||||
Subject: idToken.Subject,
|
Subject: idToken.Subject,
|
||||||
|
ExtraSettingsLinks: cl.ExtraSettingsLinks,
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err = auth.CreateUserWithRandomUsername(s, uu)
|
u, err = auth.CreateUserWithRandomUsername(s, uu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -324,6 +327,9 @@ func getOrCreateUser(s *xorm.Session, cl *claims, provider *Provider, idToken *o
|
||||||
if cl.Name != u.Name {
|
if cl.Name != u.Name {
|
||||||
u.Name = cl.Name
|
u.Name = cl.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u.ExtraSettingsLinks = cl.ExtraSettingsLinks
|
||||||
|
|
||||||
u, err = user.UpdateUser(s, u, false)
|
u, err = user.UpdateUser(s, u, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,8 @@ type User struct {
|
||||||
DeletionScheduledAt time.Time `xorm:"datetime null" json:"-"`
|
DeletionScheduledAt time.Time `xorm:"datetime null" json:"-"`
|
||||||
DeletionLastReminderSent time.Time `xorm:"datetime null" json:"-"`
|
DeletionLastReminderSent time.Time `xorm:"datetime null" json:"-"`
|
||||||
|
|
||||||
FrontendSettings interface{} `xorm:"json null" json:"-"`
|
FrontendSettings interface{} `xorm:"json null" json:"-"`
|
||||||
|
ExtraSettingsLinks map[string]any `xorm:"json null" json:"-"`
|
||||||
|
|
||||||
ExportFileID int64 `xorm:"bigint null" json:"-"`
|
ExportFileID int64 `xorm:"bigint null" json:"-"`
|
||||||
|
|
||||||
|
|
@ -607,6 +608,7 @@ func UpdateUser(s *xorm.Session, user *User, forceOverride bool) (updatedUser *U
|
||||||
"timezone",
|
"timezone",
|
||||||
"overdue_tasks_reminders_time",
|
"overdue_tasks_reminders_time",
|
||||||
"frontend_settings",
|
"frontend_settings",
|
||||||
|
"extra_settings_links",
|
||||||
).
|
).
|
||||||
Update(user)
|
Update(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue