diff --git a/backend/internal/router/dependencies.go b/backend/internal/router/dependencies.go index 99df356f..af6aa035 100644 --- a/backend/internal/router/dependencies.go +++ b/backend/internal/router/dependencies.go @@ -222,15 +222,19 @@ func adminCanAccessFileBinding(ctx context.Context, db *gorm.DB, adminID, tenant } switch binding.ResourceType { case model.FileResourceGameAccount: + if isPlatformSuperAdmin(ctx, db, adminID) { + return true, nil + } var count int64 if err := db.WithContext(ctx).Table("game_accounts"). Where("id = ? AND source_tenant_id = ?", binding.ResourceID, tenantID). Count(&count).Error; err != nil || count > 0 { return count > 0, err } - err := db.WithContext(ctx).Table("rental_listings"). - Where("account_id = ? AND source_tenant_id = ?", binding.ResourceID, tenantID). - Where("distribution_site_id IS NULL OR distribution_site_id = 0"). + scopeSQL, scopeArgs := adminListingFileScopeSQL(tenantID, false) + err := db.WithContext(ctx).Table("rental_listings AS l"). + Where("l.account_id = ?", binding.ResourceID). + Where(scopeSQL, scopeArgs...). Count(&count).Error return count > 0, err case model.FileResourceChatConversation: diff --git a/backend/internal/router/file_access.go b/backend/internal/router/file_access.go index 2a9b8ca2..5507da65 100644 --- a/backend/internal/router/file_access.go +++ b/backend/internal/router/file_access.go @@ -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) { diff --git a/backend/internal/router/file_access_test.go b/backend/internal/router/file_access_test.go index 6041e859..03b89ce8 100644 --- a/backend/internal/router/file_access_test.go +++ b/backend/internal/router/file_access_test.go @@ -223,3 +223,122 @@ func TestAdminQrCodeFileAccessUsesConversationScope(t *testing.T) { t.Fatal("管理员不得访问其他租户未绑定会话的码池图片") } } + +func TestAdminListingFileAccessUsesTenantDistributionScope(t *testing.T) { + db := database.NewTestDB() + tenants := []model.Tenant{ + {ID: 101, Code: "file_scope_a", Name: "A站", Status: "active"}, + {ID: 202, Code: "file_scope_b", Name: "B站", Status: "active"}, + } + if err := db.Create(&tenants).Error; err != nil { + t.Fatal(err) + } + sites := []model.DistributionSite{ + {SiteCode: "file_scope_site_a", SiteName: "A分销站", Domain: "file-scope-a.example.com", Status: "active", DisplayAccountEnabled: true}, + {SiteCode: "file_scope_site_b", SiteName: "B分销站", Domain: "file-scope-b.example.com", Status: "active", DisplayAccountEnabled: true}, + } + if err := db.Create(&sites).Error; err != nil { + t.Fatal(err) + } + if err := db.Create(&[]model.ChatSiteTenantLink{ + {SiteID: sites[0].ID, TenantID: 101, Enabled: true}, + {SiteID: sites[1].ID, TenantID: 202, Enabled: true}, + }).Error; err != nil { + t.Fatal(err) + } + + owner := model.User{TenantID: 0, DistributionSiteID: sites[0].ID, Phone: "13900006101", Status: "active"} + if err := db.Create(&owner).Error; err != nil { + t.Fatal(err) + } + account := model.GameAccount{ + SourceTenantID: 0, + OwnerID: owner.ID, + GameName: "delta_force", + ServerRegion: "国服", + LoginPlatform: "steam", + Title: "分销站商品", + Status: "draft", + ScreenshotURLS: datatypes.JSON([]byte(`["/api/files/object?key=listing%2Fscope-tenant.jpg"]`)), + } + if err := db.Create(&account).Error; err != nil { + t.Fatal(err) + } + listing := model.RentalListing{ + SourceTenantID: 0, + ListingNo: "FILE-SCOPE-1", + AccountID: account.ID, + OwnerID: owner.ID, + PriceCent: 1000, + Status: "draft", + ReviewStatus: "pending", + DistributionSiteID: &sites[0].ID, + } + if err := db.Create(&listing).Error; err != nil { + t.Fatal(err) + } + + admin := model.AdminUser{Username: "file-scope-admin", PasswordHash: "x", Status: "active", TokenVersion: 1} + if err := db.Create(&admin).Error; err != nil { + t.Fatal(err) + } + superRole := model.Role{Code: "super_admin", Name: "超级管理员"} + if err := db.Create(&superRole).Error; err != nil { + t.Fatal(err) + } + superAdmin := model.AdminUser{Username: "file-scope-super", PasswordHash: "x", Status: "active", TokenVersion: 1} + if err := db.Create(&superAdmin).Error; err != nil { + t.Fatal(err) + } + if err := db.Create(&model.AdminUserRole{AdminID: superAdmin.ID, RoleID: superRole.ID, TenantID: 0}).Error; err != nil { + t.Fatal(err) + } + + values := fileReferenceValues("listing/scope-tenant.jpg", "listing/scope-tenant.jpg") + queries, known := knownAdminFileQueries(t.Context(), db, admin.ID, 101, values) + if !known { + t.Fatal("商品文件应进入管理员权限校验") + } + allowed, err := runFileAccessQueries(t.Context(), db, queries) + if err != nil { + t.Fatal(err) + } + if !allowed { + t.Fatal("大锤管理员应可读取大锤分销站商品图片") + } + + queries, _ = knownAdminFileQueries(t.Context(), db, admin.ID, 202, values) + allowed, err = runFileAccessQueries(t.Context(), db, queries) + if err != nil { + t.Fatal(err) + } + if allowed { + t.Fatal("解忧管理员不得读取大锤分销站商品图片") + } + + queries, _ = knownAdminFileQueries(t.Context(), db, superAdmin.ID, 101, values) + allowed, err = runFileAccessQueries(t.Context(), db, queries) + if err != nil { + t.Fatal(err) + } + if !allowed { + t.Fatal("平台超管应可读取任意租户商品图片") + } + + var binding model.FileObjectBinding + if err := db.Where("canonical_key = ? AND resource_type = ?", "listing/scope-tenant.jpg", model.FileResourceGameAccount).First(&binding).Error; err != nil { + t.Fatalf("load file binding: %v", err) + } + allowed, err = adminCanAccessFileBinding(t.Context(), db, admin.ID, 101, binding) + if err != nil || !allowed { + t.Fatalf("大锤管理员绑定鉴权 allowed=%v err=%v, want true", allowed, err) + } + allowed, err = adminCanAccessFileBinding(t.Context(), db, admin.ID, 202, binding) + if err != nil || allowed { + t.Fatalf("解忧管理员绑定鉴权 allowed=%v err=%v, want false", allowed, err) + } + allowed, err = adminCanAccessFileBinding(t.Context(), db, superAdmin.ID, 101, binding) + if err != nil || !allowed { + t.Fatalf("平台超管绑定鉴权 allowed=%v err=%v, want true", allowed, err) + } +} diff --git a/frontend/src/features/admin/views/AdminListingReviewView.vue b/frontend/src/features/admin/views/AdminListingReviewView.vue index 122d63f7..742b6444 100644 --- a/frontend/src/features/admin/views/AdminListingReviewView.vue +++ b/frontend/src/features/admin/views/AdminListingReviewView.vue @@ -62,10 +62,21 @@ import { readAssetString, } from '@/shared/utils/listingDisplay' import { formatDateTime } from '@/shared/utils/time' +import { useAdminSessionStore } from '@/stores/adminSession' import { useDistributionSiteStore } from '@/stores/distributionSite' const siteStore = useDistributionSiteStore() +const adminSession = useAdminSessionStore() const currentSiteName = computed(() => siteStore.siteName || '大锤商行') +const reviewScopeDescription = computed(() => + adminSession.isSuperAdmin + ? '平台超级管理员视图:可查看并审核全部租户及其分销站商品。' + : '仅审核本站号主提交的站内商品,核对账号资产、上号凭证、渠道溯源与定价风控。' +) +const reviewPoolLabel = computed(() => (adminSession.isSuperAdmin ? '全租户待审池' : '本站待审池')) +const reviewPageTitle = computed(() => + adminSession.isSuperAdmin ? '全平台商品审核' : currentSiteName.value + '商品审核' +) type RiskLevel = 'danger' | 'warning' | 'info' | 'success' @@ -953,8 +964,8 @@ async function handleScreenshotSaved(payload: { oldUrl: string; newUrl: string }
Audit Workbench · 审核工作台
-仅审核本站号主提交的站内商品,核对账号资产、上号凭证、渠道溯源与定价风控。
+{{ reviewScopeDescription }}