MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / List

Method List

server-source-code/internal/handler/users.go:90–131  ·  view source on GitHub ↗

List returns paginated users.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

88
89// List returns paginated users.
90func (h *UsersHandler) List(w http.ResponseWriter, r *http.Request) {
91 returnAll := r.URL.Query().Get("all") == "true"
92 page := parseIntQuery(r, "page", 1)
93 pageSize := parseIntQuery(r, "pageSize", 50)
94 if pageSize > 200 {
95 pageSize = 200
96 }
97 if returnAll {
98 pageSize = 10000
99 }
100 offset := (page - 1) * pageSize
101
102 users, err := h.users.List(r.Context(), pageSize, offset)
103 if err != nil {
104 Error(w, http.StatusInternalServerError, "Failed to list users")
105 return
106 }
107 total, _ := h.users.Count(r.Context())
108 totalPages := 1
109 if !returnAll && pageSize > 0 {
110 totalPages = (total + pageSize - 1) / pageSize
111 if totalPages < 1 {
112 totalPages = 1
113 }
114 }
115 if returnAll {
116 pageSize = total
117 }
118
119 // Build response without password_hash
120 data := make([]map[string]interface{}, len(users))
121 for i, u := range users {
122 data[i] = userToAdminResponse(&u)
123 }
124
125 JSON(w, http.StatusOK, map[string]interface{}{
126 "data": data,
127 "pagination": map[string]interface{}{
128 "total": total, "page": page, "pageSize": pageSize, "totalPages": totalPages,
129 },
130 })
131}
132
133// ListForAssignment returns active users for assignment dropdowns.
134func (h *UsersHandler) ListForAssignment(w http.ResponseWriter, r *http.Request) {

Callers 3

resolveHostGroupParamMethod · 0.45
ListRunsMethod · 0.45
ListPoliciesMethod · 0.45

Calls 7

parseIntQueryFunction · 0.85
ErrorFunction · 0.85
userToAdminResponseFunction · 0.85
QueryMethod · 0.80
JSONFunction · 0.70
GetMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected