P0-1 认证安全: - JWT secret 改为环境变量配置, 未设置则随机生成(重启失效) - 新增 LoginRateLimitMiddleware: 5次/分钟登录频率限制(滑动窗口) - 429 响应 + 前端 toast 提示 P0-2 操作审计日志: - 新增 OperationLog 模型 (user/username/action/resource/detail/ip) - 新增 AuditLogMiddleware 自动记录 POST/PUT/DELETE/PATCH 操作 - 新增 GET /audit-logs API (分页/过滤/统计) - 前端 AuditLogsPage 对接真实 API (字段/路径修正) P0-3 实例密码加密: - 已确认 crypto.py AES-256-GCM 加密存储, 无需修改 P1 前端错误提示: - 新增 useToast hook + ToastContainer 组件 - request.ts 拦截器: 4xx/5xx 错误 toast 显示后端 detail 信息 - 422 验证错误提取第一条 msg - 网络失败显示通用提示 1182 tests passed
28 lines
1.3 KiB
Python
28 lines
1.3 KiB
Python
"""操作审计日志模型。"""
|
|
from sqlalchemy import Column, Integer, String, Text, DateTime, Index
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class OperationLog(Base):
|
|
__tablename__ = "operation_logs"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
user_id = Column(Integer, nullable=True, comment="操作者ID(系统操作为空)")
|
|
username = Column(String(50), nullable=True, comment="操作者用户名")
|
|
action = Column(String(50), nullable=False, comment="操作类型: login/create/update/delete/execute/approve/reject")
|
|
resource_type = Column(String(50), nullable=True, comment="资源类型: ticket/instance/user/audit_rule/notification/workflow")
|
|
resource_id = Column(Integer, nullable=True, comment="资源ID")
|
|
detail = Column(Text, nullable=True, comment="操作详情")
|
|
ip_address = Column(String(50), nullable=True, comment="操作者IP")
|
|
user_agent = Column(String(255), nullable=True, comment="浏览器UA")
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
__table_args__ = (
|
|
Index("ix_oplog_user_id", "user_id"),
|
|
Index("ix_oplog_action", "action"),
|
|
Index("ix_oplog_resource", "resource_type", "resource_id"),
|
|
Index("ix_oplog_created_at", "created_at"),
|
|
)
|