ForcePilot/server/utils/common_utils.py
Wenjie Zhang fa56bca143 refactor: 移除未使用的代码和注释,优化代码结构
- 删除 SettingView.vue 中的 TODO 注释
- 移除 AgentView.vue 和 AgentChatComponent.vue 中侧边栏互斥逻辑
- 删除 kb_manager.py 中未实现的 migrate_database 方法
- 将操作日志功能提取到 common_utils.py
- 修复文件末尾缺少换行符的问题
2025-08-23 17:39:47 +08:00

27 lines
719 B
Python

"""通用工具函数"""
from sqlalchemy.orm import Session
from fastapi import Request
from server.models.user_model import User, OperationLog
def log_operation(db: Session, user_id: int, operation: str, details: str = None, request: Request = None):
"""记录用户操作日志"""
ip_address = None
if request:
ip_address = request.client.host if request.client else None
log = OperationLog(
user_id=user_id,
operation=operation,
details=details,
ip_address=ip_address
)
db.add(log)
db.commit()
def get_user_dict(user: User, include_password: bool = False) -> dict:
"""获取用户字典表示"""
return user.to_dict(include_password)