MCPcopy
hub / github.com/1Panel-dev/KubePi / SearchUsers

Method SearchUsers

internal/api/v1/user/user.go:57–97  ·  view source on GitHub ↗

Search User @Tags users @Summary Search users @Description Search users by Condition @Accept json @Produce json @Success 200 {object} api.Page @Security ApiKeyAuth @Router /users/search [post]

()

Source from the content-addressed store, hash-verified

55// @Security ApiKeyAuth
56// @Router /users/search [post]
57func (h *Handler) SearchUsers() iris.Handler {
58 return func(ctx *context.Context) {
59 pageNum, _ := ctx.Values().GetInt(pkgV1.PageNum)
60 pageSize, _ := ctx.Values().GetInt(pkgV1.PageSize)
61
62 //pattern := ctx.URLParam("pattern")
63 var conditions commons.SearchConditions
64 if err := ctx.ReadJSON(&conditions); err != nil {
65 ctx.StatusCode(iris.StatusBadRequest)
66 ctx.Values().Set("message", err.Error())
67 return
68 }
69 users, total, err := h.userService.Search(pageNum, pageSize, conditions.Conditions, common.DBOptions{})
70 if err != nil {
71 if !errors.Is(err, storm.ErrNotFound) {
72 ctx.StatusCode(iris.StatusInternalServerError)
73 ctx.Values().Set("message", err.Error())
74 return
75 }
76 }
77 us := make([]User, 0)
78 for i := range users {
79 users[i] = sanitizeUser(users[i])
80 bindings, err := h.roleBindingService.GetRoleBindingBySubject(v1Role.Subject{Kind: "User", Name: users[i].Name}, common.DBOptions{})
81 if err != nil && !errors.Is(err, storm.ErrNotFound) {
82 ctx.StatusCode(iris.StatusInternalServerError)
83 ctx.Values().Set("message", err.Error())
84 return
85 }
86 roles := collections.NewStringSet()
87 for i := range bindings {
88 roles.Add(bindings[i].RoleRef)
89 }
90 us = append(us, User{
91 User: users[i],
92 Roles: roles.ToSlice(),
93 })
94 }
95 ctx.Values().Set("data", pkgV1.Page{Items: us, Total: total})
96 }
97}
98
99// Create User
100// @Tags users

Callers 1

InstallFunction · 0.95

Calls 8

AddMethod · 0.95
ToSliceMethod · 0.95
NewStringSetFunction · 0.92
sanitizeUserFunction · 0.85
ErrorMethod · 0.80
SearchMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected