28 lines
806 B
Go
28 lines
806 B
Go
// package handler
|
|
// @Link https://github.com/xiujiecn/xiu-admin
|
|
// @Copyright Copyright (c) 2025 LiXiujie
|
|
// @Author Lxj <xxx@example.com>
|
|
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
|
|
package handler
|
|
|
|
import (
|
|
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/contexts"
|
|
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/utility/convert"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/text/gstr"
|
|
)
|
|
|
|
// FilterTenant 过滤多租户数据权限
|
|
func FilterTenant(m *gdb.Model) *gdb.Model {
|
|
var (
|
|
ctx = m.GetCtx()
|
|
fields = convert.EscapeFieldsToSlice(m.GetFieldsStr())
|
|
)
|
|
// 如果包含tenant_id字段,则过滤多租户数据权限
|
|
if gstr.InArray(fields, "tenant_id") {
|
|
m = m.Where("tenant_id", contexts.GetTenantId(ctx))
|
|
}
|
|
return m
|
|
}
|