feat: complete remaining Go backend modules

This commit is contained in:
zn-admin committed 2026-08-14 00:02:43 +08:00
1 parent cea2751dc5
commit aef5a97165
145 files changed
+18376 -199

No files matched your search

@@ -109,6 +109,7 @@ func (s *Service) UpdateAccount(ctx context.Context, actor Actor, id string, pat
return Account{}, problem(ErrorForbidden, "组织管理员不能修改账号角色或归属。")
}
next := current
update := AccountUpdate{Actor: actor}
mutates := false
if patch.DisplayName != nil {
name := strings.TrimSpace(*patch.DisplayName)
@@ -116,16 +117,20 @@ func (s *Service) UpdateAccount(ctx context.Context, actor Actor, id string, pat
return Account{}, problem(ErrorValidation, "显示名称不能为空。")
}
next.DisplayName = name
update.DisplayName = &name
}
if patch.Role != nil {
if !validRole(*patch.Role) {
return Account{}, problem(ErrorValidation, "账号角色不正确。")
}
next.Role = *patch.Role
update.Role = patch.Role
mutates = true
}
if patch.OrganizationID != nil {
next.OrganizationID = strings.TrimSpace(*patch.OrganizationID)
organizationID := next.OrganizationID
update.OrganizationID = &organizationID
mutates = true
}
if patch.Status != nil {
@@ -133,6 +138,7 @@ func (s *Service) UpdateAccount(ctx context.Context, actor Actor, id string, pat
return Account{}, problem(ErrorValidation, "账号状态不正确。")
}
next.Status = *patch.Status
update.Status = patch.Status
mutates = true
}
if err := s.validateMembership(ctx, next.Role, next.OrganizationID); err != nil {
@@ -147,15 +153,23 @@ func (s *Service) UpdateAccount(ctx context.Context, actor Actor, id string, pat
return Account{}, infrastructure("hash password", err)
}
next.PasswordHash, next.PasswordSalt = hashed.Hash, hashed.Salt
update.PasswordHash = &hashed
mutates = true
}
if patch.ClearLoginLock {
next.FailedLoginCount, next.LockedUntil = 0, nil
update.ClearLoginLock = true
}
if mutates {
next.SessionVersion++
update.IncrementSessionVersion = true
}
next.UpdatedAt = s.now()
update.UpdatedAt = next.UpdatedAt
if atomic, ok := s.store.(AtomicAccountUpdater); ok {
updated, err := atomic.ApplyAccountUpdate(ctx, id, update)
return updated, infrastructure("update account", err)
}
updated, err := s.store.UpdateAccount(ctx, next)
return updated, infrastructure("update account", err)
}