fix(withdrawal): 修复分站审核凭证与历史订单可见性

This commit is contained in:
yml
2026-11-27 21:37:34 +08:00
parent 17ca2f6672
commit 06dbf52f08
6 changed files with 283 additions and 22 deletions
+37 -5
View File
@@ -244,11 +244,30 @@ func TestAdminPrivateFileAuthorizerScopesOperatingTenant(t *testing.T) {
}
}
func TestAdminBindingAuthorizerExcludesDistributionFinanceFiles(t *testing.T) {
func TestAdminBindingAuthorizerAllowsOwnDistributionFinanceFiles(t *testing.T) {
db := openAuthorizerTestDB(t)
tenant := model.Tenant{ID: 101, Code: "dachui", Name: "大锤商行", Status: "active"}
if err := db.Create(&tenant).Error; err != nil {
t.Fatal(err)
}
site := model.DistributionSite{
ID: 77,
SiteCode: "gz_dist",
SiteName: "天域商行",
Domain: "tysh.example.com",
Status: "active",
}
if err := db.Create(&site).Error; err != nil {
t.Fatal(err)
}
if err := db.Create(&model.ChatSiteTenantLink{
SiteID: site.ID, TenantID: tenant.ID, Enabled: true,
}).Error; err != nil {
t.Fatal(err)
}
user := model.User{
TenantID: 101,
DistributionSiteID: 77,
DistributionSiteID: site.ID,
Phone: "file-distribution-user",
Status: "active",
}
@@ -270,7 +289,7 @@ func TestAdminBindingAuthorizerExcludesDistributionFinanceFiles(t *testing.T) {
WithdrawNo: "W-FILE-DIST",
TenantID: 101,
UserID: user.ID,
DistributionSiteID: 77,
DistributionSiteID: site.ID,
AccountType: "alipay",
AccountName: "测试",
AccountNo: "test@example.com",
@@ -282,12 +301,25 @@ func TestAdminBindingAuthorizerExcludesDistributionFinanceFiles(t *testing.T) {
}
authorize := adminPrivateFileAuthorizer(db, "strict")
ctx := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 101})
ctx := tenancy.WithScope(context.Background(), tenancy.Scope{
TenantID: tenant.ID, TenantCode: tenant.Code,
})
for _, key := range []string{"payment-cert/distribution.webp", "payment-proof/distribution.webp"} {
if allowed, err := authorize(ctx, 9, key); err != nil {
t.Fatalf("%s authorize error: %v", key, err)
} else if !allowed {
t.Fatalf("tenant admin should read own distribution finance file %s", key)
}
}
otherCtx := tenancy.WithScope(context.Background(), tenancy.Scope{
TenantID: 202, TenantCode: "jieyou",
})
for _, key := range []string{"payment-cert/distribution.webp", "payment-proof/distribution.webp"} {
if allowed, err := authorize(otherCtx, 9, key); err != nil {
t.Fatalf("%s cross-tenant authorize error: %v", key, err)
} else if allowed {
t.Fatalf("tenant admin must not read distribution finance file %s", key)
t.Fatalf("other tenant must not read finance file %s", key)
}
}
}