MCPcopy Create free account
hub / github.com/astercloud/aster / DeleteUser

Method DeleteUser

pkg/security/access_control.go:400–431  ·  view source on GitHub ↗

DeleteUser 删除用户

(userID string)

Source from the content-addressed store, hash-verified

398
399// DeleteUser 删除用户
400func (ac *AccessController) DeleteUser(userID string) error {
401 ac.mu.Lock()
402 defer ac.mu.Unlock()
403
404 user, exists := ac.users[userID]
405 if !exists {
406 return fmt.Errorf("user %s not found", userID)
407 }
408
409 delete(ac.users, userID)
410 delete(ac.userRoles, userID)
411 delete(ac.userPermissions, userID)
412
413 // 删除用户的所有会话
414 for sessionID, session := range ac.sessions {
415 if session.UserID == userID {
416 delete(ac.sessions, sessionID)
417 }
418 }
419
420 // 记录审计日志
421 if ac.config.EnableAudit && ac.auditLog != nil {
422 _ = ac.auditLog.LogEvent(AuditEvent{
423 Type: AuditTypeUserDeleted,
424 UserID: userID,
425 Timestamp: time.Now(),
426 Message: fmt.Sprintf("User %s (%s) deleted", user.ID, user.Username),
427 })
428 }
429
430 return nil
431}
432
433// AssignRole 为用户分配角色
434func (ac *AccessController) AssignRole(userID, roleID string) error {

Callers 1

Calls 2

deleteFunction · 0.85
LogEventMethod · 0.65

Tested by 1