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