修复冻结用户强制下线
This commit is contained in:
@@ -19,8 +19,9 @@ import (
|
||||
)
|
||||
|
||||
type Repository struct {
|
||||
db *gorm.DB
|
||||
encryptor crypto.Encryptor
|
||||
db *gorm.DB
|
||||
encryptor crypto.Encryptor
|
||||
statusChangeNotifier func(userID uint64)
|
||||
}
|
||||
|
||||
type AuditMeta = auditlog.Meta
|
||||
@@ -33,6 +34,11 @@ func NewRepository(db *gorm.DB, encryptors ...crypto.Encryptor) *Repository {
|
||||
return &Repository{db: db, encryptor: encryptor}
|
||||
}
|
||||
|
||||
// SetStatusChangeNotifier 设置状态变更后的会话撤销通知。
|
||||
func (r *Repository) SetStatusChangeNotifier(notifier func(userID uint64)) {
|
||||
r.statusChangeNotifier = notifier
|
||||
}
|
||||
|
||||
func (r *Repository) List(ctx context.Context, page, pageSize int, query ListQuery) (*PaginatedResult, error) {
|
||||
growthConfig, err := rentergrowth.ConfigForTx(r.db.WithContext(ctx))
|
||||
if err != nil {
|
||||
@@ -207,6 +213,7 @@ func (r *Repository) AdjustGrowthPoints(ctx context.Context, adminID uint64, use
|
||||
}
|
||||
|
||||
func (r *Repository) updateStatus(ctx context.Context, adminID uint64, userID uint64, status string, riskStatus string, action string, reason string, meta AuditMeta) (*UserDTO, error) {
|
||||
statusChanged := false
|
||||
err := r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
var user model.User
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&user, userID).Error; err != nil {
|
||||
@@ -214,23 +221,33 @@ func (r *Repository) updateStatus(ctx context.Context, adminID uint64, userID ui
|
||||
}
|
||||
beforeStatus := user.Status
|
||||
beforeRisk := user.RiskStatus
|
||||
beforeTokenVersion := user.TokenVersion
|
||||
user.Status = status
|
||||
user.RiskStatus = riskStatus
|
||||
if beforeStatus != status {
|
||||
user.TokenVersion++
|
||||
statusChanged = true
|
||||
}
|
||||
if err := tx.Save(&user).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return appendAuditLog(tx, adminID, action, user.ID, meta, map[string]any{
|
||||
"user_id": user.ID,
|
||||
"reason": reason,
|
||||
"before_status": beforeStatus,
|
||||
"after_status": status,
|
||||
"before_risk_status": beforeRisk,
|
||||
"after_risk_status": riskStatus,
|
||||
"user_id": user.ID,
|
||||
"reason": reason,
|
||||
"before_status": beforeStatus,
|
||||
"after_status": status,
|
||||
"before_risk_status": beforeRisk,
|
||||
"after_risk_status": riskStatus,
|
||||
"before_token_version": beforeTokenVersion,
|
||||
"after_token_version": user.TokenVersion,
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if statusChanged && r.statusChangeNotifier != nil {
|
||||
r.statusChangeNotifier(userID)
|
||||
}
|
||||
return r.Find(ctx, userID)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user