mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-04-24 22:25:15 +00:00
feat(auth): allow passing custom settings links to user account via openid claims
This commit is contained in:
43
pkg/migration/20250402173109.go
Normal file
43
pkg/migration/20250402173109.go
Normal file
@@ -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 {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
PreferredUsername string `json:"preferred_username"`
|
||||
Nickname string `json:"nickname"`
|
||||
VikunjaGroups []map[string]interface{} `json:"vikunja_groups"`
|
||||
Picture string `json:"picture"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
PreferredUsername string `json:"preferred_username"`
|
||||
Nickname string `json:"nickname"`
|
||||
VikunjaGroups []map[string]interface{} `json:"vikunja_groups"`
|
||||
Picture string `json:"picture"`
|
||||
ExtraSettingsLinks map[string]any `json:"extra_settings_links"`
|
||||
}
|
||||
|
||||
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
|
||||
uu := &user.User{
|
||||
Username: strings.ReplaceAll(cl.PreferredUsername, " ", "-"),
|
||||
Email: cl.Email,
|
||||
Name: cl.Name,
|
||||
Status: user.StatusActive,
|
||||
Issuer: idToken.Issuer,
|
||||
Subject: idToken.Subject,
|
||||
Username: strings.ReplaceAll(cl.PreferredUsername, " ", "-"),
|
||||
Email: cl.Email,
|
||||
Name: cl.Name,
|
||||
Status: user.StatusActive,
|
||||
Issuer: idToken.Issuer,
|
||||
Subject: idToken.Subject,
|
||||
ExtraSettingsLinks: cl.ExtraSettingsLinks,
|
||||
}
|
||||
|
||||
u, err = auth.CreateUserWithRandomUsername(s, uu)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -324,6 +327,9 @@ func getOrCreateUser(s *xorm.Session, cl *claims, provider *Provider, idToken *o
|
||||
if cl.Name != u.Name {
|
||||
u.Name = cl.Name
|
||||
}
|
||||
|
||||
u.ExtraSettingsLinks = cl.ExtraSettingsLinks
|
||||
|
||||
u, err = user.UpdateUser(s, u, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -105,7 +105,8 @@ type User struct {
|
||||
DeletionScheduledAt 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:"-"`
|
||||
|
||||
@@ -607,6 +608,7 @@ func UpdateUser(s *xorm.Session, user *User, forceOverride bool) (updatedUser *U
|
||||
"timezone",
|
||||
"overdue_tasks_reminders_time",
|
||||
"frontend_settings",
|
||||
"extra_settings_links",
|
||||
).
|
||||
Update(user)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user