Commit Graph

6 Commits

Author SHA1 Message Date
Simon 8bfd0cfdc3 fix: v0.5.6 require_role 装饰器 signature + 3 个 schema 同步 migration
🛠️ Bug 修复:
- backend/app/dependencies.py: 修 require_role 装饰器
  问题:@wraps 让 FastAPI 看到 __wrapped__ 签名,Depends 默认值未被解析,
        current_user 实际是 Depends 对象 → 'Depends' object has no attribute 'roles'
  修法:用 inspect 合并签名 + 手动设 wrapper.__signature__,
        把 current_user 加进 FastAPI 看到的参数列表
  影响:所有用 @require_role 的 endpoint 在生产都受影响,修后正常

📦 Dependencies:
- backend/requirements.txt: pydantic 2.7.4
  原因:2.7.5 被 PyPI yank,清华源不缓存,build 失败
  (本次不进生产,但合并时一起跟)

🗃️ Alembic migrations(3 个,生产必跑):
- 010_add_agent_otp: agents.otp_secret + agents.otp_enabled
  背景:Agent 模型加了 OTP 字段但没建 migration,坐席登录报
        'column agents.otp_secret does not exist'
  字段:otp_secret VARCHAR(64) NULL, otp_enabled BOOLEAN DEFAULT false
  安全:nullable + default,现有坐席不受影响

- 011_add_conversation_impact: conversations 3 个评估字段
  背景:坐席发消息 500 报 'column conversations.impact_scope does not exist'
  字段:impact_scope INT DEFAULT 0, is_blocking BOOL DEFAULT false,
        emotion_state VARCHAR(20) DEFAULT 'normal'
  安全:都有 default,现有会话自动填默认值

- 012_sync_remaining_fields: 模型 vs DB 剩余漂移
  背景:dev-check-schema-drift 找到 4 个 dev 模式下没暴露的字段
  字段:conversations.dify_conversation_id VARCHAR(128) NULL,
        employees.it_level VARCHAR(20) DEFAULT 'silver',
        employees.it_level_source VARCHAR(20) DEFAULT 'system',
        employees.notes JSON DEFAULT '{}'
  安全:都有 default,现有数据自动填默认值

部署:
  cd /app && python -m alembic upgrade head
  docker compose restart backend
  验证:curl http://10.90.5.110:8000/health → 200
2026-06-16 19:24:27 +08:00
Simon 60e67b0681 v0.5.5: 应急页 v0.5.4 + 移除IT设备升级 + admin登录修复 + 内容审核架构 + 知识库 2026-06-16 10:07:42 +08:00
Simon 10b37a6acc fix(alembic): 修 007 revision id 跟文件名/008 引用一致
- revision '007_role_sys' → '007_role_system'
  - 008 的 down_revision 写的是 '007_role_system',但 007 实际是 '007_role_sys'
  - alembic upgrade head 报 KeyError: '007_role_system'
  - DB alembic_version 已记 007_role_system,改 007 对齐最干净

  Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-15 18:17:17 +08:00
Simon 2cd162eb17 fix(alembic): P1-2 生成消息状态字段迁移 2026-06-14 21:56:04 +08:00
Claude 3735dc0367 feat(security): P0 安全止血 - WS token 改 header + 坐席本地密码
【workbuddy 推送 2026-06-14,任务 #10】

修复:
- P0-#4 WS token 泄露:服务端 ws.py 优先从 Authorization: Bearer header 取,
  query param 仅作向后兼容降级路径(h5_websocket_endpoint 同)
- P0-#5 坐席本地密码:Agent 模型加 password_hash 字段(bcrypt),
  坐席登录增加 password 字段(企微验证失败时备用),
  新增 POST /agents/password 端点修改密码,
  alembic 008 迁移脚本

新增/变更:
M  backend/app/api/agents.py              (+67 行,登录 password 验证 + 改密端点)
M  backend/app/api/ws.py                  (~+30 行,header 优先 + query 降级)
M  backend/app/models/agent.py            (+10 行,password_hash 字段)
M  backend/app/schemas/agent.py           (+7 行,password 字段)
M  frontend-agent/.../useWebSocket.ts     (+5 行,Authorization header)
A  backend/alembic/versions/008_add_agent_password.py
A  docs/安全/secret-管理.md               (P0-#1 长期方案规划)

【评审遗留 5 项,详见 docs/评审报告/workbuddy-2026-06-14-P0安全.md】
- [P0-#4-ws.ts] 浏览器 WebSocket API 不支持自定义 header,需改 Sec-WebSocket-Protocol
- [P0-#4-nginx] nginx access_log 没关闭,token 仍可能经 access_log 泄露
- [P0-#5-type] model Mapped[str] 严格模式下为 None 会报错,应改 Optional
- [P0-#5-fall] 企微降级放行路径不强制 password 验证,反削弱 P0-#5
- [P0-#5-dep]  requirements.txt 缺 passlib 依赖,部署会 ImportError

【推 Gitea】
卡 #8: MariaDB 套件未装,Gitea 未启动。本次 commit 暂存本地,
Gitea 起来后一次 git push -u origin main 推送供 workbuddy 二次评审。
2026-06-14 19:32:36 +08:00
Simon 63262292d7 chore: initial baseline with P0-safety .gitignore 2026-06-14 16:51:56 +08:00