```
feat(auth): 添加用户权限获取接口并完善JWT令牌角色信息 - 在JWT令牌中添加用户角色信息 - 新增get_my_permissions接口用于获取当前用户权限码列表 - 重构认证回调逻辑,增加错误日志记录 - 更新用户信息获取接口使用Authorization头验证 ```
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""审计日志数据库模型"""
|
||||
from sqlalchemy import Column, Integer, String, Text, TIMESTAMP, Index
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy.sql import func
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class AuditLog(Base):
|
||||
__tablename__ = "audit_logs"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
|
||||
# 用户信息
|
||||
user_id = Column(String(100), nullable=False)
|
||||
username = Column(String(100), nullable=False)
|
||||
user_role = Column(String(50))
|
||||
|
||||
# 操作信息
|
||||
action_time = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||
action_type = Column(String(50), nullable=False) # auth/device/olt/user/system/inventory
|
||||
action_subtype = Column(String(50)) # create/update/delete/login/...
|
||||
|
||||
# 请求信息
|
||||
ip_address = Column(String(45))
|
||||
user_agent = Column(Text)
|
||||
request_method = Column(String(10))
|
||||
request_path = Column(String(500))
|
||||
|
||||
# 操作结果
|
||||
status = Column(String(20), nullable=False) # success/failed/error
|
||||
status_code = Column(Integer)
|
||||
|
||||
# 资源信息
|
||||
resource_type = Column(String(50))
|
||||
resource_id = Column(String(100))
|
||||
resource_name = Column(String(200))
|
||||
|
||||
# 日志内容
|
||||
description = Column(Text, nullable=False)
|
||||
request_params = Column(JSONB)
|
||||
response_data = Column(JSONB)
|
||||
error_message = Column(Text)
|
||||
|
||||
created_at = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_audit_logs_action_time", "action_time"),
|
||||
Index("idx_audit_logs_user_id", "user_id"),
|
||||
Index("idx_audit_logs_action_type", "action_type"),
|
||||
Index("idx_audit_logs_resource_type", "resource_type"),
|
||||
Index("idx_audit_logs_status", "status"),
|
||||
)
|
||||
Reference in New Issue
Block a user