summaryrefslogtreecommitdiffstats
path: root/api4/user.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-06-30 12:07:23 -0400
committerHarrison Healey <harrisonmhealey@gmail.com>2017-06-30 12:07:23 -0400
commit5507154992eedd323385c37e59b2008586b9aaa0 (patch)
treeb017d2a40207cb437b9aa84703990577539df9f8 /api4/user.go
parent6b77a054c25acb0437a58107c4592ad66c830993 (diff)
downloadchat-5507154992eedd323385c37e59b2008586b9aaa0.tar.gz
chat-5507154992eedd323385c37e59b2008586b9aaa0.tar.bz2
chat-5507154992eedd323385c37e59b2008586b9aaa0.zip
Add some basic sorting support for GET /users endpoint (#6801)
Diffstat (limited to 'api4/user.go')
-rw-r--r--api4/user.go32
1 files changed, 25 insertions, 7 deletions
diff --git a/api4/user.go b/api4/user.go
index 24c1c917b..04faf13c4 100644
--- a/api4/user.go
+++ b/api4/user.go
@@ -277,9 +277,21 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
inChannelId := r.URL.Query().Get("in_channel")
notInChannelId := r.URL.Query().Get("not_in_channel")
withoutTeam := r.URL.Query().Get("without_team")
+ sort := r.URL.Query().Get("sort")
if len(notInChannelId) > 0 && len(inTeamId) == 0 {
- c.SetInvalidParam("team_id")
+ c.SetInvalidUrlParam("team_id")
+ return
+ }
+
+ if sort != "" && sort != "last_activity_at" && sort != "create_at" {
+ c.SetInvalidUrlParam("sort")
+ return
+ }
+
+ // Currently only supports sorting on a team
+ if (sort == "last_activity_at" || sort == "create_at") && (inTeamId == "" || notInTeamId != "" || inChannelId != "" || notInChannelId != "" || withoutTeam != "") {
+ c.SetInvalidUrlParam("sort")
return
}
@@ -287,7 +299,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
etag := ""
- if withoutTeamBool, err := strconv.ParseBool(withoutTeam); err == nil && withoutTeamBool {
+ if withoutTeamBool, _ := strconv.ParseBool(withoutTeam); withoutTeamBool {
// Use a special permission for now
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_LIST_USERS_WITHOUT_TEAM) {
c.SetPermissionError(model.PERMISSION_LIST_USERS_WITHOUT_TEAM)
@@ -320,12 +332,18 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- etag = app.GetUsersInTeamEtag(inTeamId)
- if HandleEtag(etag, "Get Users in Team", w, r) {
- return
- }
+ if sort == "last_activity_at" {
+ profiles, err = app.GetRecentlyActiveUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
+ } else if sort == "create_at" {
+ profiles, err = app.GetNewUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
+ } else {
+ etag = app.GetUsersInTeamEtag(inTeamId)
+ if HandleEtag(etag, "Get Users in Team", w, r) {
+ return
+ }
- profiles, err = app.GetUsersInTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
+ profiles, err = app.GetUsersInTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
+ }
} else if len(inChannelId) > 0 {
if !app.SessionHasPermissionToChannel(c.Session, inChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)