fix(distribution): 统一分销订单租户管理口径
This commit is contained in:
@@ -38,7 +38,7 @@ func (r *Repository) Arbitrate(ctx context.Context, adminID uint64, id uint64, r
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&order, row.OrderID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if !currentTenantCanAdminDisputeOrder(ctx, order.BuyerTenantID, order.DistributionSiteID) {
|
||||
if !currentTenantCanAdminDisputeOrder(ctx, order.BuyerTenantID) {
|
||||
return gorm.ErrRecordNotFound
|
||||
}
|
||||
var listing model.RentalListing
|
||||
|
||||
@@ -171,7 +171,7 @@ func (r *Repository) AdminCreateByOrder(ctx context.Context, adminID uint64, ord
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&order, orderID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if !currentTenantCanAdminDisputeOrder(ctx, order.BuyerTenantID, order.DistributionSiteID) {
|
||||
if !currentTenantCanAdminDisputeOrder(ctx, order.BuyerTenantID) {
|
||||
return gorm.ErrRecordNotFound
|
||||
}
|
||||
if order.Status == "completed" || order.Status == "cancelled" || order.Status == "closed" {
|
||||
|
||||
@@ -116,19 +116,15 @@ func applyAdminDisputeTenantScope(ctx context.Context, db *gorm.DB) *gorm.DB {
|
||||
if tenantID == 0 {
|
||||
return db
|
||||
}
|
||||
return db.Where("o.buyer_tenant_id = ?", tenantID).
|
||||
Where("(o.distribution_site_id IS NULL OR o.distribution_site_id = 0)")
|
||||
return db.Where("o.buyer_tenant_id = ?", tenantID)
|
||||
}
|
||||
|
||||
func currentTenantCanAdminDisputeOrder(ctx context.Context, orderBuyerTenantID uint64, distributionSiteID *uint64) bool {
|
||||
func currentTenantCanAdminDisputeOrder(ctx context.Context, orderBuyerTenantID uint64) bool {
|
||||
tenantID := tenancy.IDFromContext(ctx)
|
||||
if tenantID == 0 {
|
||||
return true
|
||||
}
|
||||
if orderBuyerTenantID != tenantID {
|
||||
return false
|
||||
}
|
||||
return distributionSiteID == nil || *distributionSiteID == 0
|
||||
return orderBuyerTenantID == tenantID
|
||||
}
|
||||
|
||||
func (r *Repository) adminFilterQuery(ctx context.Context) *gorm.DB {
|
||||
|
||||
@@ -831,8 +831,16 @@ func TestAdminDisputeQueriesAndActionsAreScopedByBuyerTenant(t *testing.T) {
|
||||
if err := db.Create(&tenantB).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
site := model.DistributionSite{
|
||||
SiteCode: "dispute_tenant_scope", SiteName: "纠纷归属测试站",
|
||||
Domain: "dispute-tenant-scope.example.com", Status: "active",
|
||||
}
|
||||
if err := db.Create(&site).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _, orderA := createDisputeOrderFixture(t, db, model.RentalOrder{
|
||||
OrderNo: "RO-DISPUTE-TENANT-A", BuyerTenantID: 101, SourceTenantID: 202, Status: "renting",
|
||||
DistributionSiteID: &site.ID, DistributionMode: "two_party_distributor_receive",
|
||||
})
|
||||
_, _, orderB := createDisputeOrderFixture(t, db, model.RentalOrder{
|
||||
OrderNo: "RO-DISPUTE-TENANT-B", BuyerTenantID: 202, SourceTenantID: 101, Status: "renting",
|
||||
@@ -866,6 +874,20 @@ func TestAdminDisputeQueriesAndActionsAreScopedByBuyerTenant(t *testing.T) {
|
||||
}, AuditMeta{}); !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
t.Fatalf("cross-tenant arbitrate error = %v", err)
|
||||
}
|
||||
|
||||
_, _, orderC := createDisputeOrderFixture(t, db, model.RentalOrder{
|
||||
OrderNo: "RO-DISPUTE-TENANT-C", BuyerTenantID: 101, SourceTenantID: 202, Status: "renting",
|
||||
DistributionSiteID: &site.ID, DistributionMode: "two_party_distributor_receive",
|
||||
})
|
||||
created, err := repo.AdminCreateByOrder(ctx, 9, orderC.ID, AdminCreateRequest{
|
||||
Type: "cannot_login", Description: "分销订单允许租户客服创建纠纷", TargetRole: "owner",
|
||||
}, AuditMeta{})
|
||||
if err != nil {
|
||||
t.Fatalf("buyer tenant should create dispute for distribution order: %v", err)
|
||||
}
|
||||
if created.OrderID != orderC.ID {
|
||||
t.Fatalf("created dispute order = %d, want %d", created.OrderID, orderC.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStampOwnerIncomeSiteUsesListingSite(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user