refactor platform domain states and permissions

This commit is contained in:
david
2026-07-29 14:25:38 +08:00
parent d4799cd320
commit 35a52c4b06
42 changed files with 507 additions and 364 deletions

View File

@@ -28,3 +28,12 @@ func TestHiddenGasorderResourcesFollowOwningSecondLevelMenu(t *testing.T) {
t.Fatal("order menu granted contract management")
}
}
func TestLocationScopeValuesAreExplicit(t *testing.T) {
if !validLocationScope("standard") || !validLocationScope("precise") {
t.Fatal("supported location scopes were rejected")
}
if validLocationScope("global") || validLocationScope("anything") {
t.Fatal("ambiguous location scope was accepted")
}
}

View File

@@ -27,8 +27,12 @@ func CreatePlatformRole(ctx *gin.Context) {
}
request.Entity = common.NewEntity(common.StatusEnable)
request.IsSystem = false
if request.DataScope == "" {
request.DataScope = "global"
if request.LocationScope == "" {
request.LocationScope = "standard"
}
if !validLocationScope(request.LocationScope) {
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
return
}
if err := impl.DBService.Create(&request).Error; err != nil {
infra.Response.Error(ctx, err)
@@ -43,10 +47,10 @@ func UpdatePlatformRole(ctx *gin.Context) {
return
}
var request struct {
Name string `json:"name" binding:"required,max=64"`
DataScope string `json:"data_scope" binding:"required,max=32"`
Name string `json:"name" binding:"required,max=64"`
LocationScope string `json:"location_scope" binding:"required,max=32"`
}
if err := ctx.ShouldBindJSON(&request); err != nil {
if err := ctx.ShouldBindJSON(&request); err != nil || !validLocationScope(request.LocationScope) {
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
return
}
@@ -59,9 +63,11 @@ func UpdatePlatformRole(ctx *gin.Context) {
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
return
}
common.UpdateAllowedByIdentity(ctx, &models.PlatformRole{}, gin.H{"name": request.Name, "data_scope": request.DataScope}, []string{"name", "data_scope"})
common.UpdateAllowedByIdentity(ctx, &models.PlatformRole{}, gin.H{"name": request.Name, "location_scope": request.LocationScope}, []string{"name", "location_scope"})
}
func validLocationScope(scope string) bool { return scope == "standard" || scope == "precise" }
// UpdatePlatformRoleStatus 更新非内置平台角色状态,系统角色始终受保护。
func UpdatePlatformRoleStatus(ctx *gin.Context) {
if !common.RequirePlatformRoot(ctx) {
@@ -70,7 +76,7 @@ func UpdatePlatformRoleStatus(ctx *gin.Context) {
var request struct {
Status int `json:"status" binding:"required"`
}
if err := ctx.ShouldBindJSON(&request); err != nil {
if err := ctx.ShouldBindJSON(&request); err != nil || !common.IsGenericRecordStatus(request.Status) {
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
return
}