merge(main): 同步主站最新 UI 与审核优化代码并保持分销多租户隔离
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -347,75 +346,9 @@ func TestApplyPublicListingURLsHidesSourceChannel(t *testing.T) {
|
||||
if _, ok := item.AssetSummary["price_breakdown"]; ok {
|
||||
t.Fatal("expected price_breakdown hidden from public listing")
|
||||
}
|
||||
if _, ok := item.AssetSummary["screenshot_groups"]; ok {
|
||||
t.Fatal("expected screenshot_groups hidden from public listing")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicListingDTOsDoNotSerializeSensitiveFields(t *testing.T) {
|
||||
item := ListingDTO{
|
||||
ID: 1,
|
||||
ListingNo: "SP000001",
|
||||
AccountID: 2,
|
||||
OwnerID: 3,
|
||||
OwnerPhone: "13800001234",
|
||||
OwnerNickname: "号主",
|
||||
SourceChannel: "外部渠道",
|
||||
IsExternalUpload: true,
|
||||
Title: "测试账号",
|
||||
Description: "公开描述",
|
||||
ScreenshotURLS: []string{"/api/listings/1/screenshots/0"},
|
||||
Status: "published",
|
||||
ReviewStatus: "approved",
|
||||
HandoffMode: "platform",
|
||||
SettlementMode: "platform_managed",
|
||||
ManagedAdminID: uint64Pointer(4),
|
||||
ReviewReason: "内部审核备注",
|
||||
ListingGroupConversationID: 5,
|
||||
AssetSummary: map[string]any{
|
||||
"season_insurance": "3*3",
|
||||
"contact_phone": "13900005678",
|
||||
"remark": "首页不应携带",
|
||||
},
|
||||
}
|
||||
|
||||
listRaw, err := json.Marshal(PublicListResult{Items: publicListingListItems([]ListingDTO{item})})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal public list error = %v", err)
|
||||
}
|
||||
detailRaw, err := json.Marshal(item.toPublicDetail())
|
||||
if err != nil {
|
||||
t.Fatalf("marshal public detail error = %v", err)
|
||||
}
|
||||
for _, field := range []string{
|
||||
"account_id",
|
||||
"owner_id",
|
||||
"owner_phone",
|
||||
"owner_nickname",
|
||||
"source_channel",
|
||||
"is_external_upload",
|
||||
"status",
|
||||
"review_status",
|
||||
"handoff_mode",
|
||||
"settlement_mode",
|
||||
"managed_admin_id",
|
||||
"review_reason",
|
||||
"listing_group_conversation_id",
|
||||
} {
|
||||
if strings.Contains(string(listRaw), field) || strings.Contains(string(detailRaw), field) {
|
||||
t.Fatalf("public response contains sensitive field %q", field)
|
||||
}
|
||||
}
|
||||
if strings.Contains(string(listRaw), "description") || strings.Contains(string(listRaw), "screenshot_urls") {
|
||||
t.Fatalf("public list contains detail-only fields: %s", listRaw)
|
||||
}
|
||||
if strings.Contains(string(listRaw), "contact_phone") || strings.Contains(string(listRaw), "首页不应携带") {
|
||||
t.Fatalf("public list contains non-display asset fields: %s", listRaw)
|
||||
}
|
||||
if strings.Contains(string(detailRaw), "contact_phone") {
|
||||
t.Fatalf("public detail contains non-public asset field: %s", detailRaw)
|
||||
}
|
||||
}
|
||||
|
||||
func uint64Pointer(value uint64) *uint64 {
|
||||
return &value
|
||||
@@ -746,7 +679,6 @@ func containsString(values []string, target string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TestListPublicWithDistributionSiteCode(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
if err := database.MigrateListingLifecycleTestSchema(db); err != nil {
|
||||
@@ -792,3 +724,99 @@ func TestListPublicWithDistributionSiteCode(t *testing.T) {
|
||||
t.Fatalf("expected 2 listings for main site, got %d", len(allRes.Items))
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyPublicScreenshotGroups(t *testing.T) {
|
||||
rawURLs := []string{
|
||||
"/api/files/object?key=listing/coin.png",
|
||||
"/api/files/object?key=listing/skin1.png",
|
||||
}
|
||||
publicURLs := []string{
|
||||
"/api/listings/88/screenshots/0",
|
||||
"/api/listings/88/screenshots/1",
|
||||
}
|
||||
summary := map[string]any{
|
||||
"screenshot_groups": map[string]any{
|
||||
"coin": []any{"/api/files/object?key=listing/coin.png"},
|
||||
"skin": []string{"/api/files/object?key=listing/skin1.png"},
|
||||
},
|
||||
}
|
||||
applyPublicScreenshotGroups(88, summary, rawURLs, publicURLs)
|
||||
groups := summary["screenshot_groups"].(map[string]any)
|
||||
coinList := groups["coin"].([]string)
|
||||
if len(coinList) != 1 || coinList[0] != "/api/listings/88/screenshots/0" {
|
||||
t.Fatalf("expected /api/listings/88/screenshots/0, got %#v", coinList)
|
||||
}
|
||||
skinList := groups["skin"].([]string)
|
||||
if len(skinList) != 1 || skinList[0] != "/api/listings/88/screenshots/1" {
|
||||
t.Fatalf("expected /api/listings/88/screenshots/1, got %#v", skinList)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateScreenshots(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
if err := database.MigrateListingLifecycleTestSchema(db); err != nil {
|
||||
t.Fatalf("failed to migrate test db: %v", err)
|
||||
}
|
||||
if err := db.AutoMigrate(&model.AuditLog{}); err != nil {
|
||||
t.Fatalf("failed to migrate audit log: %v", err)
|
||||
}
|
||||
repo := NewRepository(db, nil)
|
||||
account := model.GameAccount{
|
||||
OwnerID: 1,
|
||||
GameName: "delta_force",
|
||||
ServerRegion: "QQ",
|
||||
LoginPlatform: "QQ账号密码",
|
||||
Title: "待审核商品",
|
||||
Status: "draft",
|
||||
}
|
||||
if err := db.Create(&account).Error; err != nil {
|
||||
t.Fatalf("failed to create account: %v", err)
|
||||
}
|
||||
listing := model.RentalListing{
|
||||
ListingNo: "202609070001",
|
||||
AccountID: account.ID,
|
||||
OwnerID: 1,
|
||||
Status: "draft",
|
||||
ReviewStatus: "pending",
|
||||
}
|
||||
if err := db.Create(&listing).Error; err != nil {
|
||||
t.Fatalf("failed to create listing: %v", err)
|
||||
}
|
||||
|
||||
meta := AuditMeta{IP: "127.0.0.1", UserAgent: "TestAgent", RequestID: "req-1"}
|
||||
req := AdminUpdateScreenshotsRequest{
|
||||
ScreenshotURLs: []string{
|
||||
"/api/files/object?key=edited1.png",
|
||||
"/api/files/object?key=edited2.png",
|
||||
},
|
||||
ScreenshotGroups: map[string]any{
|
||||
"coin": []string{"/api/files/object?key=edited1.png"},
|
||||
"gameId": []string{"/api/files/object?key=edited2.png"},
|
||||
},
|
||||
}
|
||||
|
||||
updated, err := repo.UpdateScreenshots(t.Context(), 999, listing.ID, req, meta)
|
||||
if err != nil {
|
||||
t.Fatalf("UpdateScreenshots failed: %v", err)
|
||||
}
|
||||
|
||||
if len(updated.ScreenshotURLS) != 2 || updated.ScreenshotURLS[0] != "/api/files/object?key=edited1.png" {
|
||||
t.Fatalf("unexpected screenshot_urls: %#v", updated.ScreenshotURLS)
|
||||
}
|
||||
|
||||
groups, ok := updated.AssetSummary["screenshot_groups"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("screenshot_groups not found in AssetSummary: %#v", updated.AssetSummary)
|
||||
}
|
||||
coinList, ok := groups["coin"].([]string)
|
||||
if !ok {
|
||||
if anyList, isAny := groups["coin"].([]any); isAny {
|
||||
for _, v := range anyList {
|
||||
coinList = append(coinList, v.(string))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(coinList) != 1 || coinList[0] != "/api/files/object?key=edited1.png" {
|
||||
t.Fatalf("unexpected coin screenshots: %#v", coinList)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user