webui: Make some user preferences configurable
This extends 09f0237560.
- Extend user_pref with configurable profile fields and automatic migration defaults
- Move user info responses to read from user_pref instead of hardcoded values
- Add admin profile page for editing UI values after login
Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
@@ -31,6 +31,33 @@ func CreateTables() {
|
||||
db.UserEng.Sync2(new(usermodel.Users))
|
||||
db.UserEng.Sync2(new(usermodel.UserUnit))
|
||||
db.UserEng.Sync2(new(usermodel.UserUnitSkillEquip))
|
||||
|
||||
MigrateUserPref()
|
||||
}
|
||||
|
||||
func MigrateUserPref() {
|
||||
session := db.UserEng.NewSession()
|
||||
defer session.Close()
|
||||
|
||||
prefList := []usermodel.UserPref{}
|
||||
err := session.Table(new(usermodel.UserPref)).
|
||||
Where("profile_version < ?", usermodel.CurrentUserPrefProfileVersion).
|
||||
Or("profile_version IS NULL").
|
||||
Find(&prefList)
|
||||
if err != nil {
|
||||
log.Fatalln("迁移 user_pref 失败:", err.Error())
|
||||
}
|
||||
|
||||
for _, pref := range prefList {
|
||||
pref.ApplyProfileDefaults()
|
||||
_, err = session.Table(new(usermodel.UserPref)).
|
||||
ID(pref.ID).
|
||||
Cols(usermodel.UserPrefProfileColumns()...).
|
||||
Update(&pref)
|
||||
if err != nil {
|
||||
log.Fatalln("迁移 user_pref 失败:", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func LoadUnitData() {
|
||||
|
||||
Reference in New Issue
Block a user