fix(listing): 保留平台超管全量商品查看
平台超管通过权限通配符获得全租户查询标记;普通租户管理员仍按所属租户及分销站隔离。
This commit is contained in:
@@ -10,6 +10,19 @@ import (
|
||||
|
||||
type contextKey struct{}
|
||||
|
||||
type adminAllTenantsKey struct{}
|
||||
|
||||
// WithAdminAllTenantScope 标记当前管理员拥有平台级全租户查看权限。
|
||||
// 该标记只用于管理后台查询范围,不改变请求 Host 对应的经营租户上下文。
|
||||
func WithAdminAllTenantScope(ctx context.Context) context.Context {
|
||||
return context.WithValue(ctx, adminAllTenantsKey{}, true)
|
||||
}
|
||||
|
||||
func HasAdminAllTenantScope(ctx context.Context) bool {
|
||||
enabled, _ := ctx.Value(adminAllTenantsKey{}).(bool)
|
||||
return enabled
|
||||
}
|
||||
|
||||
type Scope struct {
|
||||
TenantID uint64
|
||||
TenantCode string
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
//
|
||||
// 主站商品按 source_tenant_id 归属租户;历史分销站商品按站点归属租户判定,
|
||||
// 因为分销用户的 tenant_id 历史数据存在 0/经营租户混用,不能作为唯一依据。
|
||||
// 平台超管(tenant_id=0)保持全量可见。
|
||||
// 平台超管(tenant_id=0 或权限通配符标记)保持全量可见。
|
||||
func ApplyListingTenantScope(ctx context.Context, query *gorm.DB, listingAlias string) *gorm.DB {
|
||||
if query == nil {
|
||||
return query
|
||||
}
|
||||
tenantID := IDFromContext(ctx)
|
||||
if tenantID == 0 {
|
||||
if tenantID == 0 || HasAdminAllTenantScope(ctx) {
|
||||
return query
|
||||
}
|
||||
sourceTenantColumn := qualifyScopeColumn(listingAlias, "source_tenant_id")
|
||||
|
||||
Reference in New Issue
Block a user