重构数据权限模型并清理旧RBAC代码

核心变更:
- 数据权限过滤从基于账号层级改为基于用户类型的多策略过滤
- 移除 AccountStore 中的 GetSubordinateIDs 等旧方法
- 重构认证中间件,支持 enterprise_id 和 customer_id
- 更新 GORM Callback,根据用户类型自动选择过滤策略(代理/企业/个人客户)
- 更新所有集成测试以适配新的 API 签名
- 添加功能总结文档和 OpenSpec 归档

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-10 15:08:11 +08:00
parent 9c6d4a3bd4
commit 743db126f7
26 changed files with 1292 additions and 322 deletions

View File

@@ -4,12 +4,14 @@ import "time"
// Fiber Locals 的上下文键
const (
ContextKeyRequestID = "requestid" // 请求记录ID
ContextKeyStartTime = "start_time" //请求开始时间
ContextKeyUserID = "user_id" // 用户ID
ContextKeyUserType = "user_type" //用户类型
ContextKeyShopID = "shop_id" //店铺ID
ContextKeyUserInfo = "user_info" //完整的用户信息
ContextKeyRequestID = "requestid" // 请求记录ID
ContextKeyStartTime = "start_time" // 请求开始时间
ContextKeyUserID = "user_id" // 用户ID
ContextKeyUserType = "user_type" // 用户类型
ContextKeyShopID = "shop_id" // 店铺ID
ContextKeyEnterpriseID = "enterprise_id" // 企业ID
ContextKeyCustomerID = "customer_id" // 个人客户ID
ContextKeyUserInfo = "user_info" // 完整的用户信息
)
// 配置环境变量
@@ -52,10 +54,11 @@ const (
// RBAC 用户类型常量
const (
UserTypeSuperAdmin = 1 // 超级管理员(跳过数据权限过滤)
UserTypePlatform = 2 // 平台用户
UserTypeAgent = 3 // 代理账号
UserTypeEnterprise = 4 // 企业账号
UserTypeSuperAdmin = 1 // 超级管理员(跳过数据权限过滤)
UserTypePlatform = 2 // 平台用户
UserTypeAgent = 3 // 代理账号
UserTypeEnterprise = 4 // 企业账号
UserTypePersonalCustomer = 5 // 个人客户C端用户
)
// RBAC 角色类型常量