e3efbd4552
Cron matching, audit/alert date filters, and schedule UI align on Asia/Shanghai while JWT/TOTP/heartbeat stay UTC; follow-ups add WS alert timestamps, fixed install timezone copy, and 422 on invalid date filters. Co-authored-by: Cursor <cursoragent@cursor.com>
1.7 KiB
1.7 KiB
2026-06-09 — 时区后续:WS 告警时间 / 安装时区 / 日期校验
摘要
修复北京时区改造后遗留的三项边缘问题:WebSocket 告警条使用服务端事件时间;安装向导不再提供误导性时区选项;审计/告警日期筛选非法输入返回 422 而非静默忽略。
动机
- WS 告警条用
new Date()与真实告警时刻不一致(重连/延迟时更明显)。 - 安装向导可选非北京时区但运行时不生效,易误导运维。
date_from/date_to非法时except ValueError: pass违反无静默吞错原则。
涉及文件
| 文件 | 变更 |
|---|---|
server/api/websocket.py |
broadcast_alert / broadcast_recovery 增加 at(UTC ISO) |
frontend/src/composables/useWebSocket.ts |
使用 msg.at 格式化北京时刻 |
web/app/install.html |
时区改为固定说明,移除多选下拉 |
server/api/install.py |
InitDbRequest.timezone 校验仅允许 Asia/Shanghai;config 固定写入 |
server/utils/display_time.py |
新增 parse_operator_calendar_date() |
server/infrastructure/database/audit_log_repo.py |
日期筛选用校验函数,不再静默 pass |
server/api/settings.py |
告警/审计列表非法日期 → HTTP 422 |
tests/test_operator_tz.py |
日期解析单测 |
tests/integration/test_alerts_audit.py |
422 集成测 |
tests/test_ws_alert_at.py |
WS at 字段单测 |
迁移 / 重启
- 无需 DB 迁移。
- 需重启 API;前端需重新
vite build后部署静态资源。
验证
pytest tests/test_operator_tz.py tests/test_ws_alert_at.py tests/integration/test_alerts_audit.py -q
cd frontend && npm run type-check