refactor: 数据权限过滤从 GORM Callback 改为 Store 层显式调用
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m2s

- 移除 RegisterDataPermissionCallback 和 SkipDataPermission 机制
- 在 Auth 中间件预计算 SubordinateShopIDs 并注入 Context
- 新增 ApplyShopFilter/ApplyEnterpriseFilter/ApplyOwnerShopFilter 等 Helper 函数
- 所有 Store 层查询方法显式调用数据权限过滤函数
- 权限检查函数 CanManageShop/CanManageEnterprise 改为从 Context 获取数据

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 16:38:52 +08:00
parent 4ba1f5b99d
commit 03a0960c4d
46 changed files with 1573 additions and 705 deletions

View File

@@ -45,8 +45,8 @@ func Bootstrap(deps *Dependencies) (*BootstrapResult, error) {
deps.Logger.Error("初始化默认超级管理员失败", zap.Error(err))
}
// 5. 初始化 Middleware 层
middlewares := initMiddlewares(deps)
// 5. 初始化 Middleware 层(传入 ShopStore 以支持预计算下级店铺 ID
middlewares := initMiddlewares(deps, stores)
// 6. 初始化 Handler 层
handlers := initHandlers(services, deps)
@@ -59,17 +59,12 @@ func Bootstrap(deps *Dependencies) (*BootstrapResult, error) {
// registerGORMCallbacks 注册 GORM Callbacks
func registerGORMCallbacks(deps *Dependencies, stores *stores) error {
// 注册数据权限过滤 Callback使用 ShopStore 来查询下级店铺 ID
if err := pkgGorm.RegisterDataPermissionCallback(deps.DB, stores.Shop); err != nil {
return err
}
// 注册自动添加创建&更新人 Callback
if err := pkgGorm.RegisterSetCreatorUpdaterCallback(deps.DB); err != nil {
return err
}
// TODO: 在此添加其他 GORM Callbacks
// 数据权限过滤已移至 Store 层显式调用 ApplyXxxFilter 函数
return nil
}