fix(admin): 恢复超级管理员分销管理入口
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"hfb_sys/backend/internal/database"
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/sitecode"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
|
||||
@@ -14,7 +16,7 @@ import (
|
||||
func TestBlockTenantLegacyDistributionAdmin(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
engine := gin.New()
|
||||
engine.Use(BlockTenantLegacyDistributionAdmin())
|
||||
engine.Use(BlockTenantLegacyDistributionAdmin(nil))
|
||||
engine.GET("/api/admin/distribution/sites", func(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
})
|
||||
@@ -32,7 +34,7 @@ func TestBlockTenantLegacyDistributionAdmin(t *testing.T) {
|
||||
c.Next()
|
||||
}
|
||||
tenantEngine := gin.New()
|
||||
tenantEngine.Use(tenantMiddleware, BlockTenantLegacyDistributionAdmin())
|
||||
tenantEngine.Use(tenantMiddleware, BlockTenantLegacyDistributionAdmin(nil))
|
||||
tenantEngine.GET("/api/admin/distribution/sites", func(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
})
|
||||
@@ -58,3 +60,40 @@ func TestBlockTenantLegacyDistributionAdmin(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockTenantLegacyDistributionAdminAllowsPlatformSuperAdmin(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
role := model.Role{Code: "super_admin", Name: "超级管理员"}
|
||||
if err := db.Create(&role).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
admin := model.AdminUser{Username: "legacy-dist-root", PasswordHash: "x", Status: "active"}
|
||||
if err := db.Create(&admin).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&model.AdminUserRole{
|
||||
AdminID: admin.ID,
|
||||
RoleID: role.ID,
|
||||
TenantID: 0,
|
||||
}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
gin.SetMode(gin.TestMode)
|
||||
engine := gin.New()
|
||||
engine.Use(func(c *gin.Context) {
|
||||
ctx := tenancy.WithScope(c.Request.Context(), tenancy.Scope{TenantID: 1, TenantCode: "dachui"})
|
||||
c.Request = c.Request.WithContext(sitecode.WithTenantScope(ctx))
|
||||
c.Set(ContextAdminID, admin.ID)
|
||||
c.Next()
|
||||
}, BlockTenantLegacyDistributionAdmin(db))
|
||||
engine.GET("/api/admin/distribution/sites", func(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
})
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
engine.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/api/admin/distribution/sites", nil))
|
||||
if rec.Code != http.StatusNoContent {
|
||||
t.Fatalf("platform super admin status = %d, want 204, body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user