UpdateUser 更新用户
(user *User)
| 370 | |
| 371 | // UpdateUser 更新用户 |
| 372 | func (ac *AccessController) UpdateUser(user *User) error { |
| 373 | ac.mu.Lock() |
| 374 | defer ac.mu.Unlock() |
| 375 | |
| 376 | existing, exists := ac.users[user.ID] |
| 377 | if !exists { |
| 378 | return fmt.Errorf("user %s not found", user.ID) |
| 379 | } |
| 380 | |
| 381 | user.CreatedAt = existing.CreatedAt |
| 382 | user.UpdatedAt = time.Now() |
| 383 | |
| 384 | ac.users[user.ID] = user |
| 385 | |
| 386 | // 记录审计日志 |
| 387 | if ac.config.EnableAudit && ac.auditLog != nil { |
| 388 | _ = ac.auditLog.LogEvent(AuditEvent{ |
| 389 | Type: AuditTypeUserUpdated, |
| 390 | UserID: user.ID, |
| 391 | Timestamp: time.Now(), |
| 392 | Message: fmt.Sprintf("User %s (%s) updated", user.ID, user.Username), |
| 393 | }) |
| 394 | } |
| 395 | |
| 396 | return nil |
| 397 | } |
| 398 | |
| 399 | // DeleteUser 删除用户 |
| 400 | func (ac *AccessController) DeleteUser(userID string) error { |