fix: check user's role when manage user
This commit is contained in:
@@ -600,6 +600,13 @@ func ManageUser(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if user.Role == common.RoleRootUser {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "无法禁用超级管理员用户",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
channel.TokenStoreRemoveUser(&user)
|
channel.TokenStoreRemoveUser(&user)
|
||||||
user.Status = common.UserStatusDisabled
|
user.Status = common.UserStatusDisabled
|
||||||
case "enable":
|
case "enable":
|
||||||
@@ -613,6 +620,13 @@ func ManageUser(c *gin.Context) {
|
|||||||
channel.TokenStoreAddUser(&user)
|
channel.TokenStoreAddUser(&user)
|
||||||
user.Status = common.UserStatusEnabled
|
user.Status = common.UserStatusEnabled
|
||||||
case "delete":
|
case "delete":
|
||||||
|
if user.Role == common.RoleRootUser {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "无法删除超级管理员用户",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
if err := user.Delete(); err != nil {
|
if err := user.Delete(); err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": false,
|
"success": false,
|
||||||
@@ -628,8 +642,29 @@ func ManageUser(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if user.Role >= common.RoleAdminUser {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "该用户已经是管理员",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
user.Role = common.RoleAdminUser
|
user.Role = common.RoleAdminUser
|
||||||
case "demote":
|
case "demote":
|
||||||
|
if user.Role == common.RoleRootUser {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "无法降级超级管理员用户",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if user.Role == common.RoleCommonUser {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": "该用户已经是普通用户",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
user.Role = common.RoleCommonUser
|
user.Role = common.RoleCommonUser
|
||||||
case "allow_send_email_to_others":
|
case "allow_send_email_to_others":
|
||||||
user.SendEmailToOthers = common.SendEmailToOthersAllowed
|
user.SendEmailToOthers = common.SendEmailToOthersAllowed
|
||||||
|
|||||||
Reference in New Issue
Block a user