2022-04-07 12:59:56 -06:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 11:20:29 -07:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-04-07 12:59:56 -06:00
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2024-10-21 23:09:19 -06:00
|
|
|
"code.gitea.io/gitea/modules/optional"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2024-02-27 00:12:22 -07:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2022-12-28 19:57:15 -07:00
|
|
|
"code.gitea.io/gitea/services/convert"
|
2022-04-07 12:59:56 -06:00
|
|
|
)
|
|
|
|
|
2024-10-21 23:09:19 -06:00
|
|
|
// SearchCandidates searches candidate users for dropdown list
|
|
|
|
func SearchCandidates(ctx *context.Context) {
|
|
|
|
users, _, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
|
2022-04-07 12:59:56 -06:00
|
|
|
Actor: ctx.Doer,
|
|
|
|
Keyword: ctx.FormTrim("q"),
|
|
|
|
Type: user_model.UserTypeIndividual,
|
2024-10-21 23:09:19 -06:00
|
|
|
IsActive: optional.Some(true),
|
|
|
|
ListOptions: db.ListOptions{PageSize: setting.UI.MembersPagingNum},
|
2022-04-07 12:59:56 -06:00
|
|
|
})
|
|
|
|
if err != nil {
|
2024-10-21 23:09:19 -06:00
|
|
|
ctx.ServerError("Unable to search users", err)
|
2022-04-07 12:59:56 -06:00
|
|
|
return
|
|
|
|
}
|
2024-10-21 23:09:19 -06:00
|
|
|
ctx.JSON(http.StatusOK, map[string]any{"data": convert.ToUsers(ctx, ctx.Doer, users)})
|
2022-04-07 12:59:56 -06:00
|
|
|
}
|