完善掉线诊断并优化二维码加载
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"hfb_sys/backend/internal/auditlog"
|
||||
"hfb_sys/backend/internal/logging"
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/modules/adminrole"
|
||||
|
||||
@@ -105,7 +107,7 @@ func (r *Repository) Update(ctx context.Context, id uint64, req UpdateAdminReque
|
||||
return nil, err
|
||||
}
|
||||
if req.Status != "" {
|
||||
if err := r.bumpTokenVersion(db, id); err != nil {
|
||||
if err := r.bumpTokenVersion(db, ctx, id, "admin_status_changed"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.invalidatePermCache(ctx, id)
|
||||
@@ -158,7 +160,7 @@ func (r *Repository) AssignRoles(ctx context.Context, adminID uint64, roleIDs []
|
||||
return err
|
||||
}
|
||||
}
|
||||
return r.bumpTokenVersion(tx, adminID)
|
||||
return r.bumpTokenVersion(tx, ctx, adminID, "roles_changed")
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -186,7 +188,7 @@ func (r *Repository) ChangeOwnPassword(ctx context.Context, id uint64, oldPwd, n
|
||||
}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return r.bumpTokenVersion(tx, id)
|
||||
return r.bumpTokenVersion(tx, ctx, id, "password_changed")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -206,7 +208,7 @@ func (r *Repository) ResetPassword(ctx context.Context, id uint64, newPwd string
|
||||
}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return r.bumpTokenVersion(tx, id)
|
||||
return r.bumpTokenVersion(tx, ctx, id, "password_reset")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -259,10 +261,25 @@ func (r *Repository) invalidatePermCache(ctx context.Context, adminID uint64) {
|
||||
r.redis.Del(ctx, permCacheKey(adminID))
|
||||
}
|
||||
|
||||
func (r *Repository) bumpTokenVersion(db *gorm.DB, adminID uint64) error {
|
||||
return db.Model(&model.AdminUser{}).
|
||||
func (r *Repository) bumpTokenVersion(db *gorm.DB, ctx context.Context, adminID uint64, reason string) error {
|
||||
if err := db.Model(&model.AdminUser{}).
|
||||
Where("id = ?", adminID).
|
||||
UpdateColumn("token_version", gorm.Expr("token_version + 1")).Error
|
||||
UpdateColumn("token_version", gorm.Expr("token_version + 1")).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
bizID := adminID
|
||||
return auditlog.Append(db, auditlog.Entry{
|
||||
ActorType: "admin",
|
||||
ActorID: logging.AdminIDFromContext(ctx),
|
||||
Action: "auth.token_version.bump",
|
||||
BizType: "admin_user",
|
||||
BizID: &bizID,
|
||||
Meta: auditlog.Meta{RequestID: logging.RequestIDFromContext(ctx)},
|
||||
Detail: map[string]any{
|
||||
"target_admin_id": adminID,
|
||||
"reason": reason,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func permCacheKey(adminID uint64) string {
|
||||
|
||||
Reference in New Issue
Block a user