2022-04-07 18:59:56 +00:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-04-07 18:59:56 +00:00
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2024-10-22 05:09:19 +00:00
|
|
|
"code.gitea.io/gitea/modules/optional"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2024-02-27 07:12:22 +00:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2022-12-29 02:57:15 +00:00
|
|
|
"code.gitea.io/gitea/services/convert"
|
2022-04-07 18:59:56 +00:00
|
|
|
)
|
|
|
|
|
2024-10-22 05:09:19 +00: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 18:59:56 +00:00
|
|
|
Actor: ctx.Doer,
|
|
|
|
Keyword: ctx.FormTrim("q"),
|
|
|
|
Type: user_model.UserTypeIndividual,
|
2024-10-22 05:09:19 +00:00
|
|
|
IsActive: optional.Some(true),
|
|
|
|
ListOptions: db.ListOptions{PageSize: setting.UI.MembersPagingNum},
|
2022-04-07 18:59:56 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2024-10-22 05:09:19 +00:00
|
|
|
ctx.ServerError("Unable to search users", err)
|
2022-04-07 18:59:56 +00:00
|
|
|
return
|
|
|
|
}
|
2024-10-22 05:09:19 +00:00
|
|
|
ctx.JSON(http.StatusOK, map[string]any{"data": convert.ToUsers(ctx, ctx.Doer, users)})
|
2022-04-07 18:59:56 +00:00
|
|
|
}
|