Files
opsxsql/backend/app/schemas/ldap_config.py
T
logan be2d6f3894 feat: LDAP 账号管理 — OU管理/添加用户/删除用户/批量导入
后端新增 4 个 LDAP 管理端点:
- POST /ldap-config/create-ou: 创建组织单元
- POST /ldap-config/create-user: 创建单个用户 (SSHA加密)
- POST /ldap-config/delete-user: 删除用户
- POST /ldap-config/batch-import-ldap: 批量导入用户
- POST /ldap-config/user-list: 查询用户列表(恢复)

前端 LdapConfigPage 增强:
- LDAP 账号管理折叠区(配置存在即显示)
- OU 下拉选择 + 根节点选项 + 数量统计
- 用户列表表格(全选/单选/DN显示)
- 新建 OU 弹框(名称+父级DN+描述)
- 添加用户弹框(用户名+密码+显示名+邮箱+目标OU)
- 删除选中用户按钮(确认后批量删除)

前端 UsersPage BatchImportModal 三 Tab:
- 本地导入 / 导入到 LDAP / 从 LDAP 导入

测试修复:
- test_user_endpoint.py: 分页格式兼容
- test_users.py: 分页格式兼容
- test_system_settings.py: 精简后配置项匹配
2026-05-25 17:34:53 +08:00

47 lines
1.7 KiB
Python

from datetime import datetime
from typing import Optional, Dict, Any
from pydantic import BaseModel, ConfigDict, Field
class LdapConfigCreate(BaseModel):
ldap_host: str = Field(..., min_length=1, max_length=200)
ldap_port: int = Field(default=389, ge=1, le=65535)
use_ldaps: bool = False
admin_dn: str = Field(..., min_length=1, max_length=500)
admin_password: Optional[str] = Field(default=None, max_length=500)
search_filter: Optional[str] = Field(default=None, max_length=500)
base_dn: str = Field(..., min_length=1, max_length=500)
user_mapping: Optional[Dict[str, Any]] = None
class LdapConfigUpdate(BaseModel):
ldap_host: Optional[str] = Field(default=None, min_length=1, max_length=200)
ldap_port: Optional[int] = Field(default=None, ge=1, le=65535)
use_ldaps: Optional[bool] = None
admin_dn: Optional[str] = Field(default=None, min_length=1, max_length=500)
admin_password: Optional[str] = Field(default=None, min_length=1, max_length=500)
search_filter: Optional[str] = Field(default=None, max_length=500)
base_dn: Optional[str] = Field(default=None, min_length=1, max_length=500)
user_mapping: Optional[Dict[str, Any]] = None
class LdapConfigResponse(BaseModel):
id: int
ldap_host: str
ldap_port: int
use_ldaps: bool
admin_dn: str
admin_password: str # masked in endpoint
search_filter: Optional[str] = None
base_dn: str
user_mapping: Optional[Dict[str, Any]] = None
created_at: datetime
updated_at: datetime
model_config = ConfigDict(from_attributes=True)
class LdapTestRequest(BaseModel):
test_user: str = Field(..., min_length=1)
test_password: str = Field(..., min_length=1)