fix: Dashboard统计数据修复 + 生产环境SECRET_KEY强制校验

1. Dashboard统计Bug修复
   - Task统计改用TASK_STATUS_PENDING/WIP/COMPLETED大写常量
   - 旧代码使用小写"pending"/"in_progress"永远匹配不到数据
   - 修复后tasks_pending/tasks_in_progress/tasks_completed返回真实值

2. 生产环境SECRET_KEY强制校验
   - 新增model_validator:DEBUG=False且SECRET_KEY为默认值时抛出ValueError
   - 阻止使用默认密钥部署到生产环境
This commit is contained in:
2026-08-12 12:03:07 +08:00
parent cc199081f9
commit 69f3e35d14
2 changed files with 16 additions and 4 deletions

View File

@ -17,7 +17,7 @@ class DashboardStats(BaseModel):
async def get_dashboard_stats(db: AsyncSession) -> DashboardStats:
from app.models.product import Product
from app.models.task import Task
from app.models.task import Task, TASK_STATUS_PENDING, TASK_STATUS_WIP, TASK_STATUS_COMPLETED
p_total = await db.scalar(select(func.count(Product.id)))
p_pending = await db.scalar(select(func.count(Product.id)).where(Product.status == "pending"))
@ -25,9 +25,9 @@ async def get_dashboard_stats(db: AsyncSession) -> DashboardStats:
p_done = await db.scalar(select(func.count(Product.id)).where(Product.status == "completed"))
t_total = await db.scalar(select(func.count(Task.id)))
t_pending = await db.scalar(select(func.count(Task.id)).where(Task.status == "pending"))
t_progress = await db.scalar(select(func.count(Task.id)).where(Task.status == "in_progress"))
t_done = await db.scalar(select(func.count(Task.id)).where(Task.status == "completed"))
t_pending = await db.scalar(select(func.count(Task.id)).where(Task.status == TASK_STATUS_PENDING))
t_progress = await db.scalar(select(func.count(Task.id)).where(Task.status == TASK_STATUS_WIP))
t_done = await db.scalar(select(func.count(Task.id)).where(Task.status == TASK_STATUS_COMPLETED))
return DashboardStats(
products_total=p_total or 0,