fix anwser token and database issus
This commit is contained in:
+24
-2
@@ -86,7 +86,7 @@ type User struct {
|
||||
UID string `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Password string `json:"-"`
|
||||
Email string `json:"email" gorm:"uniqueIndex:idx_users_email_unique"`
|
||||
Email string `json:"-" gorm:"uniqueIndex:idx_users_email_unique"`
|
||||
Avatar string `json:"avatar"`
|
||||
Domain string `json:"domain" gorm:"uniqueIndex:idx_users_domain_unique"`
|
||||
Background string `json:"background"`
|
||||
@@ -105,8 +105,12 @@ type User struct {
|
||||
Qrcodepdpcolor string `json:"qrcodepdpcolor"`
|
||||
Backgroundimagealpha string `json:"Backgroundimagealpha"`
|
||||
Notify NotifyType `json:"notify"`
|
||||
HarassmentSetting HarassmentSettingType `json:"harassment_setting"`
|
||||
HarassmentSetting HarassmentSettingType `json:"harassment_setting" gorm:"default:'none'"`
|
||||
BlockWords string `json:"-"`
|
||||
// 防骚扰设置取值 none / register_only(见下方常量)。历史账号此列为空串(建表时无默认值),
|
||||
// 与 none 语义等价但取值不同,会导致「按 == none 判断」的隐性漏判 → 已补 schema 默认值、
|
||||
// Create 显式写入、启动期归一历史空值(见 db.Init 的 normalizeHarassmentSetting)。
|
||||
//
|
||||
// ModerationStrictness 内容审核严格度:lax / standard / strict。
|
||||
// 空值表示「跟随站点默认」([security] default_moderation_strictness),
|
||||
// 存量账号迁移后即为空值形态 —— 缺省回退 strict(最严档),
|
||||
@@ -244,6 +248,7 @@ func (db *users) Create(ctx context.Context, opts CreateUserOptions) error {
|
||||
Backgroundimagealpha: opts.Backgroundimagealpha,
|
||||
Qrcodepdpcolor: opts.Qrcodepdpcolor,
|
||||
Notify: NotifyTypeEmail,
|
||||
HarassmentSetting: HarassmentSettingNone,
|
||||
Usernamecolor: opts.Usernamecolor,
|
||||
Introcolor: opts.Introcolor,
|
||||
Acfunlink: opts.Acfunlink,
|
||||
@@ -388,6 +393,23 @@ func (db *users) UpdateHarassmentType(ctx context.Context, id uint, typ Harassme
|
||||
return nil
|
||||
}
|
||||
|
||||
// normalizeHarassmentSetting 把 users.harassment_setting 的历史空值(空字符串)归一为 none。
|
||||
// 空串与 none 语义等价(均表示不做限制),归一后取值唯一,避免将来按 == none 判断时漏判。
|
||||
// 幂等:无空值时不做写入;失败由调用方告警(不阻断启动)。
|
||||
func normalizeHarassmentSetting(db *gorm.DB) error {
|
||||
res := db.Model(&User{}).
|
||||
Where("harassment_setting IS NULL OR harassment_setting = ''").
|
||||
Update("harassment_setting", HarassmentSettingNone)
|
||||
if res.Error != nil {
|
||||
return errors.Wrap(res.Error, "normalize harassment setting")
|
||||
}
|
||||
if res.RowsAffected > 0 {
|
||||
logrus.WithField("count", res.RowsAffected).
|
||||
Info("防骚扰设置已归一:历史空值已置为 none")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateBlockWords 仅更新全局屏蔽词表(逗号分隔,保存前已去重/去空白/限额)。
|
||||
// 只写 block_words 列,不动 harassment_setting。
|
||||
func (db *users) UpdateBlockWords(ctx context.Context, id uint, words string) error {
|
||||
|
||||
Reference in New Issue
Block a user