This commit is contained in:
@@ -32,6 +32,25 @@ func ApplyShopFilter(ctx context.Context, query *gorm.DB) *gorm.DB {
|
||||
return query.Where("shop_id IN ?", shopIDs)
|
||||
}
|
||||
|
||||
// ApplyStrictShopFilter 严格应用店铺数据权限过滤
|
||||
// 超管和平台用户不限制;代理用户仅能访问自己及下级店铺;其他用户返回空结果
|
||||
// 代理用户的权限范围缺失时降级为当前店铺,当前店铺也缺失时返回空结果
|
||||
func ApplyStrictShopFilter(ctx context.Context, query *gorm.DB) *gorm.DB {
|
||||
switch GetUserTypeFromContext(ctx) {
|
||||
case constants.UserTypeSuperAdmin, constants.UserTypePlatform:
|
||||
return query
|
||||
case constants.UserTypeAgent:
|
||||
shopIDs := GetSubordinateShopIDs(ctx)
|
||||
if len(shopIDs) > 0 {
|
||||
return query.Where("shop_id IN ?", shopIDs)
|
||||
}
|
||||
if shopID := GetShopIDFromContext(ctx); shopID > 0 {
|
||||
return query.Where("shop_id = ?", shopID)
|
||||
}
|
||||
}
|
||||
return query.Where("1 = 0")
|
||||
}
|
||||
|
||||
// ApplyEnterpriseFilter 应用企业数据权限过滤
|
||||
// 非企业用户:不添加条件
|
||||
// 企业用户:WHERE enterprise_id = ?
|
||||
|
||||
Reference in New Issue
Block a user