aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/user/user.go
diff options
context:
space:
mode:
authorEarl Warren <109468362+earl-warren@users.noreply.github.com>2023-11-13 15:31:38 +0100
committerGitHub <noreply@github.com>2023-11-13 15:31:38 +0100
commit340055ab6c579fccc9a370527ee2768bfb1466ba (patch)
tree8cd182ec66fe57c6d1b69b7ed4cc00e626cc0c0f /routers/api/v1/user/user.go
parentf2ea31de36ec777a84f32dfdb242da2a3d9f1fc8 (diff)
downloadgitea-340055ab6c579fccc9a370527ee2768bfb1466ba.tar.gz
gitea-340055ab6c579fccc9a370527ee2768bfb1466ba.zip
Enable system users search via the API (#28013)
Refs: https://codeberg.org/forgejo/forgejo/issues/1403 (cherry picked from commit dd4d17c159eaf8b642aa9e6105b0532e25972bb7)
Diffstat (limited to 'routers/api/v1/user/user.go')
-rw-r--r--routers/api/v1/user/user.go38
1 files changed, 26 insertions, 12 deletions
diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go
index 6359138369..fb8f67d072 100644
--- a/routers/api/v1/user/user.go
+++ b/routers/api/v1/user/user.go
@@ -54,19 +54,33 @@ func Search(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
- users, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
- Actor: ctx.Doer,
- Keyword: ctx.FormTrim("q"),
- UID: ctx.FormInt64("uid"),
- Type: user_model.UserTypeIndividual,
- ListOptions: listOptions,
- })
- if err != nil {
- ctx.JSON(http.StatusInternalServerError, map[string]any{
- "ok": false,
- "error": err.Error(),
+ uid := ctx.FormInt64("uid")
+ var users []*user_model.User
+ var maxResults int64
+ var err error
+
+ switch uid {
+ case user_model.GhostUserID:
+ maxResults = 1
+ users = []*user_model.User{user_model.NewGhostUser()}
+ case user_model.ActionsUserID:
+ maxResults = 1
+ users = []*user_model.User{user_model.NewActionsUser()}
+ default:
+ users, maxResults, err = user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
+ Actor: ctx.Doer,
+ Keyword: ctx.FormTrim("q"),
+ UID: uid,
+ Type: user_model.UserTypeIndividual,
+ ListOptions: listOptions,
})
- return
+ if err != nil {
+ ctx.JSON(http.StatusInternalServerError, map[string]any{
+ "ok": false,
+ "error": err.Error(),
+ })
+ return
+ }
}
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)