| 636 | } |
| 637 | |
| 638 | func GetUserModels(c *gin.Context) { |
| 639 | id, err := strconv.Atoi(c.Param("id")) |
| 640 | if err != nil { |
| 641 | id = c.GetInt("id") |
| 642 | } |
| 643 | user, err := model.GetUserCache(id) |
| 644 | if err != nil { |
| 645 | common.ApiError(c, err) |
| 646 | return |
| 647 | } |
| 648 | groups := service.GetUserUsableGroups(user.Group) |
| 649 | group := c.Query("group") |
| 650 | var groupsToQuery []string |
| 651 | switch { |
| 652 | case group == "": |
| 653 | for g := range groups { |
| 654 | groupsToQuery = append(groupsToQuery, g) |
| 655 | } |
| 656 | case group == "auto": |
| 657 | if _, ok := groups[group]; ok { |
| 658 | groupsToQuery = service.GetUserAutoGroup(user.Group) |
| 659 | } |
| 660 | default: |
| 661 | if _, ok := groups[group]; ok { |
| 662 | groupsToQuery = []string{group} |
| 663 | } |
| 664 | } |
| 665 | c.JSON(http.StatusOK, gin.H{ |
| 666 | "success": true, |
| 667 | "message": "", |
| 668 | "data": service.GetGroupsEnabledModels(groupsToQuery), |
| 669 | }) |
| 670 | } |
| 671 | |
| 672 | func UpdateUser(c *gin.Context) { |
| 673 | var updatedUser model.User |