summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/admin/user.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api/v1/admin/user.go')
-rw-r--r--routers/api/v1/admin/user.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go
index 184024a246..acab883107 100644
--- a/routers/api/v1/admin/user.go
+++ b/routers/api/v1/admin/user.go
@@ -416,6 +416,11 @@ func SearchUsers(ctx *context.APIContext) {
// in: query
// description: user's login name to search for
// type: string
+ // - name: sort
+ // in: query
+ // description: sort order of results
+ // type: string
+ // enum: [oldest, newest, alphabetically, reversealphabetically, recentupdate, leastupdate]
// - name: page
// in: query
// description: page number of results to return (1-based)
@@ -431,6 +436,27 @@ func SearchUsers(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
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 {
@@ -444,7 +470,7 @@ func SearchUsers(ctx *context.APIContext) {
Type: user_model.UserTypeIndividual,
LoginName: ctx.FormTrim("login_name"),
SourceID: sourceID,
- OrderBy: db.SearchOrderByAlphabetically,
+ OrderBy: orderBy,
ListOptions: listOptions,
})
if err != nil {