fix: 修复代码审查中发现的P0/P1/P2问题

修复内容:
1. P0-01/P0-02: IAM Handler硬编码userID=1问题
   - getUserIDFromContext现在从认证中间件的context获取真实userID
   - 添加middleware.GetOperatorID公开函数
   - CheckScope方法添加未认证检查

2. P1-01: 审计服务幂等竞态条件
   - 重构锁保护范围,整个检查和插入过程在锁保护下
   - 使用defer确保锁正确释放

3. P1-02: 幂等中间件响应码硬编码
   - 添加statusCapturingResponseWriter包装器
   - 捕获实际的状态码和响应体用于幂等记录

4. P2-01: 事件ID时间戳冲突
   - generateEventID改用UUID替代时间戳

5. P2-02: ListScopes硬编码
   - 使用model.PredefinedScopes替代硬编码列表

所有supply-api测试通过
This commit is contained in:
Your Name
2026-04-03 12:25:22 +08:00
parent cb3c503152
commit f34333dc09
5 changed files with 85 additions and 33 deletions

View File

@@ -65,7 +65,8 @@ func main() {
// 初始化审计存储
// R-08: DatabaseAuditService 已创建 (audit/service/audit_service_db.go)
// 需接口适配后可替换为: auditStore := audit.NewDatabaseAuditService(auditRepo)
// 注意由于domain层使用audit.AuditStore接口(旧)而DatabaseAuditService实现的是AuditStoreInterface(新)
// 需要接口适配。暂保持内存存储,后续统一架构时处理。
auditStore := audit.NewMemoryAuditStore()
// 初始化存储层