feat: add sort parameter for users/search api endpoint (#8594)

Introduces a new sort parameter to the `/users/search` API endpoint, similar to the one that already exists for the `/admin/users` endpoint.

Resolves #8499

Co-authored-by: DebuggerAndrzej <redpandaworkstation@gmail.com>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8594
Reviewed-by: Lucas <sclu1034@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: DebuggerAndrzej <debuggerandrzej@noreply.codeberg.org>
Co-committed-by: DebuggerAndrzej <debuggerandrzej@noreply.codeberg.org>
This commit is contained in:
DebuggerAndrzej 2025-07-24 22:40:27 +02:00 committed by Gusted
commit f4894b0edd
5 changed files with 114 additions and 21 deletions

View file

@ -436,26 +436,6 @@ func SearchUsers(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
sort := ctx.FormString("sort")
var orderBy db.SearchOrderBy
switch sort {
case "oldest":
orderBy = db.SearchOrderByOldest
case "newest":
orderBy = db.SearchOrderByNewest
case "alphabetically":
orderBy = db.SearchOrderByAlphabetically
case "reversealphabetically":
orderBy = db.SearchOrderByAlphabeticallyReverse
case "recentupdate":
orderBy = db.SearchOrderByRecentUpdated
case "leastupdate":
orderBy = db.SearchOrderByLeastUpdated
default:
orderBy = db.SearchOrderByAlphabetically
}
intSource, err := strconv.ParseInt(ctx.FormString("source_id"), 10, 64)
var sourceID optional.Option[int64]
if ctx.FormString("source_id") == "" || err != nil {
@ -469,7 +449,7 @@ func SearchUsers(ctx *context.APIContext) {
Type: user_model.UserTypeIndividual,
LoginName: ctx.FormTrim("login_name"),
SourceID: sourceID,
OrderBy: orderBy,
OrderBy: utils.GetDbSearchOrder(ctx),
ListOptions: listOptions,
})
if err != nil {