refactor: improve user group handling and add GetUserUsableGroups function

- Introduced a new function `GetUserUsableGroupsCopy` to return a copy of user usable groups.
- Updated `GetUserUsableGroups` to utilize the new function for better encapsulation.
- Changed variable names from `UserUsableGroups` to `userUsableGroups` for consistency.
- Enhanced `GetUserUsableGroups` logic to ensure it returns a copy of the groups, preventing unintended modifications.
This commit is contained in:
CalciumIon
2024-12-27 21:19:22 +08:00
parent 5f082d72bb
commit 77861e6440
2 changed files with 24 additions and 15 deletions

View File

@@ -6,6 +6,7 @@ import (
"net/http"
"one-api/common"
"one-api/model"
"one-api/setting"
"strconv"
"strings"
"sync"
@@ -454,7 +455,11 @@ func GetUserModels(c *gin.Context) {
})
return
}
models := model.GetGroupModels(user.Group)
groups := setting.GetUserUsableGroups(user.Group)
var models []string
for group := range groups {
models = append(models, model.GetGroupModels(group)...)
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",