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