WIP-CHECKPOINT[auth-refactor]: 固化工程师崩溃前部分成果 + 同树其他未提交WIP(仅源码,不含密钥/二进制)-- 待重激活工程师续作

This commit is contained in:
Simon
2026-07-07 21:52:11 +08:00
parent 242c1967ff
commit fab75760e0
203 changed files with 21504 additions and 3345 deletions
+82
View File
@@ -21,6 +21,7 @@ from app.database import get_db
from app.models.agent import Agent
from app.models.quick_reply_template import QuickReplyTemplate
from app.schemas.quick_reply import (
QuickReplyApprove,
QuickReplyCreate,
QuickReplyResponse,
QuickReplyUpdate,
@@ -254,3 +255,84 @@ async def delete_quick_reply(
logger.info(f"删除快速回复模板: id={template_id}")
return success_response(data=None, message="删除成功")
# --------------------------------------------------------------------------
# PUT /api/quick-replies/{id}/approve — 审核通过
# --------------------------------------------------------------------------
@router.put("/quick-replies/{template_id}/approve")
async def approve_quick_reply(
template_id: UUID,
db: AsyncSession = Depends(get_db),
):
"""审核通过快速回复模板。
将模板状态从 pending_review 改为 approved,版本号 +1。
Args:
template_id: 模板ID
db: 数据库会话
Returns:
Dict: 统一响应格式,包含更新后的模板
"""
# 查找模板
stmt = select(QuickReplyTemplate).where(QuickReplyTemplate.id == template_id)
result = await db.execute(stmt)
template = result.scalars().first()
if not template:
raise ERR_NOT_FOUND
# 审核通过:状态改为 approved,版本号 +1
template.status = "approved"
template.version += 1
db.add(template)
await db.flush()
logger.info(f"审核通过快速回复模板: id={template_id}, version={template.version}")
template_data = QuickReplyResponse.model_validate(template).model_dump()
return success_response(data=template_data, message="审核通过")
# --------------------------------------------------------------------------
# PUT /api/quick-replies/{id}/reject — 驳回
# --------------------------------------------------------------------------
@router.put("/quick-replies/{template_id}/reject")
async def reject_quick_reply(
template_id: UUID,
body: QuickReplyApprove, # 使用 QuickReplyApprove 作为请求体(驳回不需要额外参数)
db: AsyncSession = Depends(get_db),
):
"""驳回快速回复模板。
将模板状态从 pending_review 改为 rejected。
Args:
template_id: 模板ID
body: 请求体(此接口不需要额外参数)
db: 数据库会话
Returns:
Dict: 统一响应格式,包含更新后的模板
"""
# 查找模板
stmt = select(QuickReplyTemplate).where(QuickReplyTemplate.id == template_id)
result = await db.execute(stmt)
template = result.scalars().first()
if not template:
raise ERR_NOT_FOUND
# 驳回:状态改为 rejected
template.status = "rejected"
db.add(template)
await db.flush()
logger.info(f"驳回快速回复模板: id={template_id}")
template_data = QuickReplyResponse.model_validate(template).model_dump()
return success_response(data=template_data, message="已驳回")