MCPcopy Index your code
hub / github.com/coder/coder / GetUsers

Method GetUsers

coderd/users.go:372–423  ·  view source on GitHub ↗
(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

370}
371
372func (api *API) GetUsers(rw http.ResponseWriter, r *http.Request) ([]database.User, int64, bool) {
373 ctx := r.Context()
374 query := r.URL.Query().Get("q")
375 params, errs := searchquery.Users(query)
376 if len(errs) > 0 {
377 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
378 Message: "Invalid user search query.",
379 Validations: errs,
380 })
381 return nil, -1, false
382 }
383
384 paginationParams, ok := ParsePagination(rw, r)
385 if !ok {
386 return nil, -1, false
387 }
388
389 userRows, err := api.Database.GetUsers(ctx, database.GetUsersParams{
390 AfterID: paginationParams.AfterID,
391 Search: params.Search,
392 Name: params.Name,
393 Status: params.Status,
394 IsServiceAccount: params.IsServiceAccount,
395 RbacRole: params.RbacRole,
396 LastSeenBefore: params.LastSeenBefore,
397 LastSeenAfter: params.LastSeenAfter,
398 CreatedAfter: params.CreatedAfter,
399 CreatedBefore: params.CreatedBefore,
400 GithubComUserID: params.GithubComUserID,
401 LoginType: params.LoginType,
402 // #nosec G115 - Pagination offsets are small and fit in int32
403 OffsetOpt: int32(paginationParams.Offset),
404 // #nosec G115 - Pagination limits are small and fit in int32
405 LimitOpt: int32(paginationParams.Limit),
406 })
407 if err != nil {
408 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
409 Message: "Internal error fetching users.",
410 Detail: err.Error(),
411 })
412 return nil, -1, false
413 }
414
415 // GetUsers does not return ErrNoRows because it uses a window function to get the count.
416 // So we need to check if the userRows is empty and return an empty array if so.
417 if len(userRows) == 0 {
418 return []database.User{}, 0, true
419 }
420
421 users := database.ConvertUserRows(userRows)
422 return users, userRows[0].Count, true
423}
424
425// Creates a new user.
426//

Callers 2

usersMethod · 0.95

Calls 8

UsersFunction · 0.92
WriteFunction · 0.92
ConvertUserRowsFunction · 0.92
ParsePaginationFunction · 0.85
ContextMethod · 0.65
GetMethod · 0.65
GetUsersMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected