mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-18 03:27:26 +00:00
fix(user): UpdateSelf 边栏权限检查和类型检查
This commit is contained in:
@@ -564,8 +564,6 @@ func generateDefaultSidebarConfig(userRole int) string {
|
|||||||
return string(configBytes)
|
return string(configBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func GetUserModels(c *gin.Context) {
|
func GetUserModels(c *gin.Context) {
|
||||||
id, err := strconv.Atoi(c.Param("id"))
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -665,6 +663,25 @@ func UpdateSelf(c *gin.Context) {
|
|||||||
// 检查是否是sidebar_modules更新请求
|
// 检查是否是sidebar_modules更新请求
|
||||||
if sidebarModules, exists := requestData["sidebar_modules"]; exists {
|
if sidebarModules, exists := requestData["sidebar_modules"]; exists {
|
||||||
userId := c.GetInt("id")
|
userId := c.GetInt("id")
|
||||||
|
userRole := c.GetInt("role")
|
||||||
|
// 注意超级管理员目前在 calculateUserPermissions 中被设置为无权更新设置
|
||||||
|
perms := calculateUserPermissions(userRole)
|
||||||
|
allow, ok := perms["sidebar_settings"]
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "无权更新设置",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
allowBool, ok := allow.(bool)
|
||||||
|
if !ok || !allowBool {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "无权更新设置",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
user, err := model.GetUserById(userId, false)
|
user, err := model.GetUserById(userId, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.ApiError(c, err)
|
common.ApiError(c, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user