fix(platform): protect system role menus

This commit is contained in:
2026-07-27 02:11:42 +08:00
parent 8bd2be73f5
commit 05e6f22f1d
2 changed files with 29 additions and 0 deletions

View File

@@ -11,6 +11,8 @@ import (
"gorm.io/gorm"
)
var errSystemPlatformRole = errors.New("system platform roles cannot be modified")
// ListPlatformRole 查询平台角色分页列表。
func ListPlatformRole(ctx *gin.Context) { listPage[models.PlatformRole](ctx) }
@@ -108,6 +110,9 @@ func ReplacePlatformRoleMenus(ctx *gin.Context) {
if err := transaction.Where("identity = ?", ctx.Param("identity")).First(&role).Error; err != nil {
return err
}
if role.IsSystem {
return errSystemPlatformRole
}
var menus []models.PlatformMenu
if len(request.MenuIdentities) > 0 {
if err := transaction.Where("identity IN ?", request.MenuIdentities).Find(&menus).Error; err != nil {
@@ -132,6 +137,10 @@ func ReplacePlatformRoleMenus(ctx *gin.Context) {
infra.Response.Error(ctx, errcode.ErrRecordNotFound)
return
}
if errors.Is(err, errSystemPlatformRole) {
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
return
}
infra.Response.Error(ctx, err)
return
}