fix(files): 分销站商品图片按租户范围鉴权

商品图片的绑定校验与历史回退查询统一使用站点归属租户;平台超管保留全量读取,并同步修正审核页超管文案。
This commit is contained in:
2026-11-21 15:55:10 +08:00
parent b4d058ef63
commit 194833ea9b
5 changed files with 164 additions and 9 deletions
+23 -2
View File
@@ -90,6 +90,25 @@ func jsonReferencePayload(values []string) string {
return string(payload)
}
// adminListingFileScopeSQL 统一管理员读取商品图片的租户范围。
// 主站商品按货源租户归属;分销站商品按站点归属租户判定;平台超管全量可见。
func adminListingFileScopeSQL(tenantID uint64, platformSuperAdmin bool) (string, []any) {
if tenantID == 0 || platformSuperAdmin {
return "(1 = 1)", nil
}
return `(
((l.distribution_site_id IS NULL OR l.distribution_site_id = 0) AND l.source_tenant_id = ?)
OR EXISTS (
SELECT 1
FROM chat_site_tenant_links AS st
JOIN tenants AS st_tenant ON st_tenant.id = st.tenant_id AND st_tenant.status = 'active'
WHERE st.site_id = l.distribution_site_id
AND st.enabled = 1
AND st.tenant_id = ?
)
)`, []any{tenantID, tenantID}
}
func jsonOverlapsAny(column string) string {
return fmt.Sprintf("JSON_OVERLAPS(%s, CAST(? AS JSON))", column)
}
@@ -252,12 +271,14 @@ func knownAdminFileQueries(ctx context.Context, db *gorm.DB, adminID, tenantID u
prefix := strings.SplitN(values[0], "/", 2)[0]
switch prefix {
case "listing", "misc":
platformSuperAdmin := tenantID > 0 && isPlatformSuperAdmin(ctx, db, adminID)
scopeSQL, scopeArgs := adminListingFileScopeSQL(tenantID, platformSuperAdmin)
return []fileAccessQuery{{
sql: `SELECT COUNT(1) FROM game_accounts a
JOIN rental_listings l ON l.account_id = a.id
WHERE (? = 0 OR (l.source_tenant_id = ? AND (l.distribution_site_id IS NULL OR l.distribution_site_id = 0)))
WHERE ` + scopeSQL + `
AND ` + listingMembers,
args: append([]any{tenantID, tenantID}, jsonArgs...),
args: append(append([]any{}, scopeArgs...), jsonArgs...),
}}, true
case "chat":
if isPlatformSuperAdmin(ctx, db, adminID) {