127 lines
3.7 KiB
Python
127 lines
3.7 KiB
Python
# =============================================================================
|
||
# 企微IT智能服务台 — 管理员用户 Schema
|
||
# =============================================================================
|
||
# 说明:定义管理员用户相关的请求/响应数据结构
|
||
# 用于用户管理 CRUD 操作
|
||
# =============================================================================
|
||
|
||
from datetime import datetime
|
||
from typing import Optional
|
||
|
||
from pydantic import BaseModel, Field
|
||
|
||
|
||
class AdminUserCreateRequest(BaseModel):
|
||
"""创建管理员请求 Schema。
|
||
|
||
Attributes:
|
||
user_id: 企微用户ID(唯一)
|
||
name: 姓名
|
||
role: 角色(admin/super_admin)
|
||
password: 初始密码(可选,不传则生成随机密码)
|
||
"""
|
||
|
||
user_id: str = Field(..., min_length=1, max_length=64, description="企微用户ID(唯一)")
|
||
name: str = Field(..., min_length=1, max_length=128, description="姓名")
|
||
role: str = Field(default="admin", description="角色: admin=管理员, super_admin=超级管理员")
|
||
password: Optional[str] = Field(None, min_length=6, max_length=128, description="初始密码(可选)")
|
||
|
||
|
||
class AdminUserUpdateRequest(BaseModel):
|
||
"""更新管理员请求 Schema。
|
||
|
||
所有字段可选,只更新传入的字段。
|
||
|
||
Attributes:
|
||
name: 姓名
|
||
role: 角色
|
||
is_active: 是否激活
|
||
"""
|
||
|
||
name: Optional[str] = Field(None, min_length=1, max_length=128, description="姓名")
|
||
role: Optional[str] = Field(None, description="角色: admin=管理员, super_admin=超级管理员")
|
||
is_active: Optional[bool] = Field(None, description="是否激活")
|
||
|
||
|
||
class AdminUserResetPasswordRequest(BaseModel):
|
||
"""重置密码请求 Schema。
|
||
|
||
Attributes:
|
||
new_password: 新密码
|
||
"""
|
||
|
||
new_password: str = Field(..., min_length=6, max_length=128, description="新密码")
|
||
|
||
|
||
class AdminUserResponse(BaseModel):
|
||
"""管理员用户响应 Schema。
|
||
|
||
Attributes:
|
||
id: 用户ID
|
||
user_id: 企微用户ID
|
||
name: 姓名
|
||
role: 角色
|
||
is_active: 是否激活
|
||
password_hash: 密码哈希(不返回给前端)
|
||
mfa_enabled: 是否启用MFA
|
||
mfa_secret: MFA密钥(不返回给前端)
|
||
created_at: 创建时间
|
||
updated_at: 更新时间
|
||
"""
|
||
|
||
id: str
|
||
user_id: str
|
||
name: str
|
||
role: str
|
||
is_active: bool
|
||
mfa_enabled: bool
|
||
mfa_bound_at: Optional[datetime] = None
|
||
created_at: datetime
|
||
updated_at: datetime
|
||
|
||
model_config = {"from_attributes": True}
|
||
|
||
|
||
class AdminUserListResponse(BaseModel):
|
||
"""管理员列表响应 Schema。
|
||
|
||
Attributes:
|
||
items: 用户列表
|
||
total: 总数
|
||
"""
|
||
|
||
items: list[AdminUserResponse] = Field(default_factory=list, description="用户列表")
|
||
total: int = Field(default=0, description="总数")
|
||
|
||
|
||
class AuthLoginRequest(BaseModel):
|
||
"""账号密码登录请求 Schema。
|
||
|
||
Attributes:
|
||
username: 用户名/账号
|
||
password: 密码
|
||
otp_code: OTP 验证码(可选,MFA启用时必填)
|
||
"""
|
||
|
||
username: str = Field(..., min_length=1, description="用户名/账号")
|
||
password: str = Field(..., min_length=1, description="密码")
|
||
otp_code: Optional[str] = Field(None, min_length=6, max_length=6, description="OTP 验证码(可选)")
|
||
|
||
|
||
class AuthLoginResponse(BaseModel):
|
||
"""登录成功响应 Schema。
|
||
|
||
Attributes:
|
||
token: 认证 Token
|
||
user_id: 用户ID
|
||
name: 姓名
|
||
roles: 角色列表
|
||
require_otp: 是否需要 OTP 验证
|
||
"""
|
||
|
||
token: str
|
||
user_id: str
|
||
name: str
|
||
roles: list[str]
|
||
require_otp: bool = False
|