2024-06-22 05:04:21 +00:00
|
|
|
package api
|
2024-04-02 12:23:25 +00:00
|
|
|
|
|
|
|
import (
|
2024-07-24 10:09:18 +00:00
|
|
|
"fmt"
|
2024-07-30 12:28:38 +00:00
|
|
|
"strings"
|
2024-07-28 12:04:22 +00:00
|
|
|
|
2024-06-17 14:21:34 +00:00
|
|
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
|
|
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
2024-07-24 10:09:18 +00:00
|
|
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
2024-04-02 12:23:25 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getOtherUserinfo(c *fiber.Ctx) error {
|
|
|
|
alias := c.Params("alias")
|
|
|
|
|
|
|
|
var account models.Account
|
|
|
|
if err := database.C.
|
|
|
|
Where(&models.Account{Name: alias}).
|
2024-04-05 17:07:36 +00:00
|
|
|
Preload("Profile").
|
2024-06-02 12:15:04 +00:00
|
|
|
Preload("Badges").
|
2024-04-02 12:23:25 +00:00
|
|
|
First(&account).Error; err != nil {
|
|
|
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
|
2024-07-24 10:09:18 +00:00
|
|
|
groups, err := services.GetUserAccountGroup(account)
|
|
|
|
if err != nil {
|
|
|
|
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("unable to get account groups: %v", err))
|
|
|
|
}
|
|
|
|
for _, group := range groups {
|
|
|
|
for k, v := range group.PermNodes {
|
|
|
|
if _, ok := account.PermNodes[k]; !ok {
|
|
|
|
account.PermNodes[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-02 12:23:25 +00:00
|
|
|
return c.JSON(account)
|
|
|
|
}
|
2024-07-30 12:28:38 +00:00
|
|
|
|
|
|
|
func getOtherUserinfoBatch(c *fiber.Ctx) error {
|
|
|
|
idSet := strings.Split(c.Query("id"), ",")
|
|
|
|
if len(idSet) == 0 {
|
|
|
|
return fiber.NewError(fiber.StatusBadRequest, "id list is required")
|
|
|
|
}
|
|
|
|
|
|
|
|
var accounts []models.Account
|
|
|
|
if err := database.C.
|
|
|
|
Where("id IN ?", idSet).
|
|
|
|
Find(&accounts).Error; err != nil {
|
|
|
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.JSON(accounts)
|
|
|
|
}
|