-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Teammate/finalize dashboard and api url #4574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4d45fac
7891a0d
830fddf
6d35ff6
584a1a8
d89f78e
63a1db7
f2dac94
3fd36a2
bc88dfa
2c468a6
27746b0
91bd75c
4bc32f3
9606f58
c19561f
f0f03a0
a70c455
213f58a
33c690d
18c98bc
5a7754b
d669e85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,3 +35,6 @@ data/ | |
| .test | ||
| token_estimator_test.go | ||
| skills-lock.json | ||
| .omx/ | ||
| .playwright-mcp/ | ||
| web/default/.omc/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -275,7 +275,7 @@ func GetUser(c *gin.Context) { | |
| return | ||
| } | ||
| myRole := c.GetInt("role") | ||
| if myRole <= user.Role && myRole != common.RoleRootUser { | ||
| if myRole <= user.Role && !common.HasRootPermission(myRole) { | ||
| common.ApiErrorI18n(c, i18n.MsgUserNoPermissionSameLevel) | ||
| return | ||
| } | ||
|
|
@@ -430,18 +430,10 @@ func calculateUserPermissions(userRole int) map[string]interface{} { | |
| permissions := map[string]interface{}{} | ||
|
|
||
| // 根据用户角色计算权限 | ||
| if userRole == common.RoleRootUser { | ||
| if common.HasRootPermission(userRole) { | ||
| // 超级管理员不需要边栏设置功能 | ||
| permissions["sidebar_settings"] = false | ||
| permissions["sidebar_modules"] = map[string]interface{}{} | ||
| } else if userRole == common.RoleAdminUser { | ||
| // 管理员可以设置边栏,但不包含系统设置功能 | ||
| permissions["sidebar_settings"] = true | ||
| permissions["sidebar_modules"] = map[string]interface{}{ | ||
| "admin": map[string]interface{}{ | ||
| "setting": false, // 管理员不能访问系统设置 | ||
| }, | ||
| } | ||
| } else { | ||
| // 普通用户只能设置个人功能,不包含管理员区域 | ||
| permissions["sidebar_settings"] = true | ||
|
|
@@ -482,18 +474,8 @@ func generateDefaultSidebarConfig(userRole int) string { | |
| } | ||
|
|
||
| // 管理员区域 - 根据角色决定 | ||
| if userRole == common.RoleAdminUser { | ||
| // 管理员可以访问管理员区域,但不能访问系统设置 | ||
| defaultConfig["admin"] = map[string]interface{}{ | ||
| "enabled": true, | ||
| "channel": true, | ||
| "models": true, | ||
| "redemption": true, | ||
| "user": true, | ||
| "setting": false, // 管理员不能访问系统设置 | ||
| } | ||
| } else if userRole == common.RoleRootUser { | ||
| // 超级管理员可以访问所有功能 | ||
| if common.HasRootPermission(userRole) { | ||
| // 管理员和超级管理员都可以访问所有管理功能 | ||
| defaultConfig["admin"] = map[string]interface{}{ | ||
| "enabled": true, | ||
| "channel": true, | ||
|
|
@@ -562,11 +544,11 @@ func UpdateUser(c *gin.Context) { | |
| return | ||
| } | ||
| myRole := c.GetInt("role") | ||
| if myRole <= originUser.Role && myRole != common.RoleRootUser { | ||
| if myRole <= originUser.Role && !common.HasRootPermission(myRole) { | ||
| common.ApiErrorI18n(c, i18n.MsgUserNoPermissionHigherLevel) | ||
| return | ||
| } | ||
| if myRole <= updatedUser.Role && myRole != common.RoleRootUser { | ||
| if myRole <= updatedUser.Role && !common.HasRootPermission(myRole) { | ||
| common.ApiErrorI18n(c, i18n.MsgUserCannotCreateHigherLevel) | ||
|
Comment on lines
+547
to
552
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep root-account mutations root-only. These guards now reuse Suggested tightening- if myRole <= originUser.Role && !common.HasRootPermission(myRole) {
+ if myRole <= originUser.Role && myRole != common.RoleRootUser {
common.ApiErrorI18n(c, i18n.MsgUserNoPermissionHigherLevel)
return
}
- if myRole <= updatedUser.Role && !common.HasRootPermission(myRole) {
+ if myRole <= updatedUser.Role && myRole != common.RoleRootUser {
common.ApiErrorI18n(c, i18n.MsgUserCannotCreateHigherLevel)
return
}
- if user.Role >= myRole && !common.HasRootPermission(myRole) {
+ if user.Role >= myRole && myRole != common.RoleRootUser {
common.ApiErrorI18n(c, i18n.MsgUserCannotCreateHigherLevel)
return
}Also applies to: 752-753, 803-805 🤖 Prompt for AI Agents |
||
| return | ||
| } | ||
|
|
@@ -605,7 +587,7 @@ func AdminClearUserBinding(c *gin.Context) { | |
| } | ||
|
|
||
| myRole := c.GetInt("role") | ||
| if myRole <= user.Role && myRole != common.RoleRootUser { | ||
| if myRole <= user.Role && !common.HasRootPermission(myRole) { | ||
| common.ApiErrorI18n(c, i18n.MsgUserNoPermissionSameLevel) | ||
| return | ||
| } | ||
|
|
@@ -767,7 +749,7 @@ func DeleteUser(c *gin.Context) { | |
| return | ||
| } | ||
| myRole := c.GetInt("role") | ||
| if myRole <= originUser.Role { | ||
| if myRole <= originUser.Role && !common.HasRootPermission(myRole) { | ||
| common.ApiErrorI18n(c, i18n.MsgUserNoPermissionHigherLevel) | ||
| return | ||
| } | ||
|
|
@@ -818,7 +800,7 @@ func CreateUser(c *gin.Context) { | |
| user.DisplayName = user.Username | ||
| } | ||
| myRole := c.GetInt("role") | ||
| if user.Role >= myRole { | ||
| if user.Role >= myRole && !common.HasRootPermission(myRole) { | ||
| common.ApiErrorI18n(c, i18n.MsgUserCannotCreateHigherLevel) | ||
| return | ||
| } | ||
|
|
@@ -867,7 +849,7 @@ func ManageUser(c *gin.Context) { | |
| return | ||
| } | ||
| myRole := c.GetInt("role") | ||
| if myRole <= user.Role && myRole != common.RoleRootUser { | ||
| if myRole <= user.Role && !common.HasRootPermission(myRole) { | ||
| common.ApiErrorI18n(c, i18n.MsgUserNoPermissionHigherLevel) | ||
| return | ||
| } | ||
|
|
@@ -898,7 +880,7 @@ func ManageUser(c *gin.Context) { | |
| common.SysLog(fmt.Sprintf("failed to invalidate tokens cache for user %d: %s", user.Id, err.Error())) | ||
| } | ||
| case "promote": | ||
| if myRole != common.RoleRootUser { | ||
| if !common.HasRootPermission(myRole) { | ||
| common.ApiErrorI18n(c, i18n.MsgUserAdminCannotPromote) | ||
| return | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Prefer explicit privileged-role checks over numeric threshold comparison.
Line 176 grants root-capable access to any future role value above admin. An explicit role allow-list avoids accidental privilege expansion.
💡 Suggested fix
func HasRootPermission(role int) bool { - return role >= RoleAdminUser + return role == RoleAdminUser || role == RoleRootUser }📝 Committable suggestion
🤖 Prompt for AI Agents