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