fix(distribution): 统一分销订单租户管理口径
This commit is contained in:
@@ -329,8 +329,7 @@ WHERE ` + conversationTenantAccessClause("c") + ` AND ` + chatMembers,
|
||||
return []fileAccessQuery{{
|
||||
sql: `SELECT COUNT(1) FROM handoff_records h
|
||||
JOIN rental_orders o ON o.id = h.order_id
|
||||
WHERE (? = 0 OR ((o.buyer_tenant_id = ? OR o.source_tenant_id = ?)
|
||||
AND (o.distribution_site_id IS NULL OR o.distribution_site_id = 0)))
|
||||
WHERE (? = 0 OR (o.buyer_tenant_id = ? OR o.source_tenant_id = ?))
|
||||
AND ` + handoffMembers,
|
||||
args: append([]any{tenantID, tenantID, tenantID}, jsonArgs...),
|
||||
}}, true
|
||||
@@ -339,16 +338,16 @@ WHERE (? = 0 OR ((o.buyer_tenant_id = ? OR o.source_tenant_id = ?)
|
||||
{
|
||||
sql: `SELECT COUNT(1) FROM disputes d
|
||||
JOIN rental_orders o ON o.id = d.order_id
|
||||
WHERE (? = 0 OR (o.buyer_tenant_id = ? AND (o.distribution_site_id IS NULL OR o.distribution_site_id = 0)))
|
||||
WHERE (? = 0 OR o.buyer_tenant_id = ?)
|
||||
AND ` + disputeMembers,
|
||||
args: append([]any{tenantID, tenantID}, jsonArgs...),
|
||||
},
|
||||
{
|
||||
sql: `SELECT COUNT(1) FROM order_checkouts c
|
||||
JOIN rental_orders o ON o.id = c.order_id
|
||||
WHERE (? = 0 OR (o.buyer_tenant_id = ? AND (o.distribution_site_id IS NULL OR o.distribution_site_id = 0)))
|
||||
WHERE (? = 0 OR o.buyer_tenant_id = ? OR o.source_tenant_id = ?)
|
||||
AND ` + checkoutMembers,
|
||||
args: append([]any{tenantID, tenantID}, jsonArgs...),
|
||||
args: append([]any{tenantID, tenantID, tenantID}, jsonArgs...),
|
||||
},
|
||||
}, true
|
||||
case "payment-cert":
|
||||
|
||||
@@ -127,6 +127,116 @@ func TestPrivateFileAccessMatchesCrossTenantConversation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminOrderEvidenceFilesFollowOrderTenantOnDistributionListing(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
site := model.DistributionSite{
|
||||
SiteCode: "evidence_scope_dist", SiteName: "证据文件测试站",
|
||||
Domain: "evidence-scope.example.com", Status: "active",
|
||||
}
|
||||
if err := db.Create(&site).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seller := model.User{TenantID: 202, Phone: "13900004101", Status: "active"}
|
||||
buyer := model.User{TenantID: 101, Phone: "13900004102", Status: "active"}
|
||||
if err := db.Create(&seller).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&buyer).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
account := model.GameAccount{
|
||||
SourceTenantID: 202, OwnerID: seller.ID, ServerRegion: "国服",
|
||||
LoginPlatform: "steam", Title: "分销证据文件商品", Status: "published",
|
||||
}
|
||||
if err := db.Create(&account).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
listing := model.RentalListing{
|
||||
SourceTenantID: 202, DistributionSiteID: &site.ID,
|
||||
ListingNo: "L-EVIDENCE-SCOPE", AccountID: account.ID, OwnerID: seller.ID,
|
||||
PriceCent: 1000, Status: "rented", ReviewStatus: "approved",
|
||||
}
|
||||
if err := db.Create(&listing).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
order := model.RentalOrder{
|
||||
BuyerTenantID: 101, SourceTenantID: 202, PaymentTenantID: 101,
|
||||
DistributionSiteID: &site.ID, DistributionMode: "two_party_distributor_receive",
|
||||
OrderNo: "RO-EVIDENCE-SCOPE", ListingID: listing.ID, AccountID: account.ID,
|
||||
OwnerID: seller.ID, RenterID: buyer.ID, Status: "pending_handoff",
|
||||
}
|
||||
if err := db.Create(&order).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&model.HandoffRecord{
|
||||
OrderID: order.ID, FromUserID: seller.ID, ToUserID: buyer.ID, Type: "owner_handoff",
|
||||
AttachmentURLS: datatypes.JSON([]byte(`["/api/files/object?key=handoff%2Fdistribution.jpg"]`)),
|
||||
}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&model.Dispute{
|
||||
OrderID: order.ID, InitiatorID: buyer.ID, InitiatorType: "user",
|
||||
TargetUserID: seller.ID, Type: "cannot_login", Status: "open",
|
||||
EvidenceURLS: datatypes.JSON([]byte(`["/api/files/object?key=dispute%2Fdistribution.jpg"]`)),
|
||||
}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&model.OrderCheckout{
|
||||
OrderID: order.ID, Status: "open",
|
||||
EvidenceURLS: datatypes.JSON([]byte(`["/api/files/object?key=dispute%2Fcheckout.jpg"]`)),
|
||||
}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
key string
|
||||
allowSource bool
|
||||
}{
|
||||
{name: "交接附件", key: "handoff/distribution.jpg", allowSource: true},
|
||||
{name: "纠纷证据", key: "dispute/distribution.jpg"},
|
||||
{name: "结账证据", key: "dispute/checkout.jpg", allowSource: true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
queries, known := knownAdminFileQueries(
|
||||
context.Background(), db, 0, 101, fileReferenceValues(tc.key, tc.key),
|
||||
)
|
||||
if !known {
|
||||
t.Fatal("文件类型应进入管理员业务权限校验")
|
||||
}
|
||||
allowed, err := runFileAccessQueries(context.Background(), db, queries)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !allowed {
|
||||
t.Fatalf("买方租户管理员应可访问分销订单%s", tc.name)
|
||||
}
|
||||
|
||||
queries, _ = knownAdminFileQueries(
|
||||
context.Background(), db, 0, 202, fileReferenceValues(tc.key, tc.key),
|
||||
)
|
||||
allowed, err = runFileAccessQueries(context.Background(), db, queries)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if allowed != tc.allowSource {
|
||||
t.Fatalf("货源租户访问分销订单%s allowed=%v, want %v", tc.name, allowed, tc.allowSource)
|
||||
}
|
||||
|
||||
queries, _ = knownAdminFileQueries(
|
||||
context.Background(), db, 0, 303, fileReferenceValues(tc.key, tc.key),
|
||||
)
|
||||
allowed, err = runFileAccessQueries(context.Background(), db, queries)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if allowed {
|
||||
t.Fatalf("无关租户不得访问分销订单%s", tc.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminQrCodeFileAccessUsesConversationScope(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
admin := model.AdminUser{Username: "dachui-ops", PasswordHash: "x", Status: "active", TokenVersion: 1}
|
||||
|
||||
Reference in New Issue
Block a user