fix: 修复用户可选分组不能选择用户分组 (close #528)

This commit is contained in:
1808837298@qq.com
2024-10-14 16:15:10 +08:00
parent 40baa636e4
commit f599c65944
6 changed files with 38 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ import (
"github.com/gin-gonic/gin"
"net/http"
"one-api/common"
"one-api/model"
)
func GetGroups(c *gin.Context) {
@@ -20,10 +21,14 @@ func GetGroups(c *gin.Context) {
func GetUserGroups(c *gin.Context) {
usableGroups := make(map[string]string)
userGroup := ""
userId := c.GetInt("id")
userGroup, _ = model.CacheGetUserGroup(userId)
for groupName, _ := range common.GroupRatio {
// UserUsableGroups contains the groups that the user can use
if _, ok := common.UserUsableGroups[groupName]; ok {
usableGroups[groupName] = common.UserUsableGroups[groupName]
userUsableGroups := common.GetUserUsableGroups(userGroup)
if _, ok := userUsableGroups[groupName]; ok {
usableGroups[groupName] = userUsableGroups[groupName]
}
}
c.JSON(http.StatusOK, gin.H{