diff options
author | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2017-03-30 17:09:39 +0200 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-03-30 08:09:39 -0700 |
commit | 29e6db5713c57d7bb46d7aea38b1001b9e8a1212 (patch) | |
tree | 66d0a06a35068ce26024b0b9c030de0b1c8bab5c /api4 | |
parent | ee3b983a6344d78bafa553607133020e8e1fb0ed (diff) | |
download | chat-29e6db5713c57d7bb46d7aea38b1001b9e8a1212.tar.gz chat-29e6db5713c57d7bb46d7aea38b1001b9e8a1212.tar.bz2 chat-29e6db5713c57d7bb46d7aea38b1001b9e8a1212.zip |
Implement POST /users/status/ids for apiv4 (#5894)
Diffstat (limited to 'api4')
-rw-r--r-- | api4/status.go | 21 | ||||
-rw-r--r-- | api4/status_test.go | 36 |
2 files changed, 57 insertions, 0 deletions
diff --git a/api4/status.go b/api4/status.go index 5cd6a4536..142f5ce5a 100644 --- a/api4/status.go +++ b/api4/status.go @@ -17,6 +17,7 @@ func InitStatus() { l4g.Debug(utils.T("api.status.init.debug")) BaseRoutes.User.Handle("/status", ApiHandler(getUserStatus)).Methods("GET") + BaseRoutes.Users.Handle("/status/ids", ApiHandler(getUserStatusesByIds)).Methods("POST") } @@ -26,6 +27,8 @@ func getUserStatus(c *Context, w http.ResponseWriter, r *http.Request) { return } + // No permission check required + if statusMap, err := app.GetUserStatusesByIds([]string{c.Params.UserId}); err != nil { c.Err = err return @@ -38,3 +41,21 @@ func getUserStatus(c *Context, w http.ResponseWriter, r *http.Request) { } } } + +func getUserStatusesByIds(c *Context, w http.ResponseWriter, r *http.Request) { + userIds := model.ArrayFromJson(r.Body) + + if len(userIds) == 0 { + c.SetInvalidParam("user_ids") + return + } + + // No permission check required + + if statusMap, err := app.GetUserStatusesByIds(userIds); err != nil { + c.Err = err + return + } else { + w.Write([]byte(model.StatusListToJson(statusMap))) + } +} diff --git a/api4/status_test.go b/api4/status_test.go index da56ae435..35bf62379 100644 --- a/api4/status_test.go +++ b/api4/status_test.go @@ -53,3 +53,39 @@ func TestGetUserStatus(t *testing.T) { t.Fatal("Should return offline status") } } + +func TestGetUsersStatusesByIds(t *testing.T) { + th := Setup().InitBasic() + defer TearDown() + Client := th.Client + + usersIds := []string{th.BasicUser.Id, th.BasicUser2.Id} + + usersStatuses, resp := Client.GetUsersStatusesByIds(usersIds) + CheckNoError(t, resp) + for _, userStatus := range usersStatuses { + if userStatus.Status != "offline" { + t.Fatal("Status should be offline") + } + } + + app.SetStatusOnline(th.BasicUser.Id, "", true) + app.SetStatusOnline(th.BasicUser2.Id, "", true) + usersStatuses, resp = Client.GetUsersStatusesByIds(usersIds) + CheckNoError(t, resp) + for _, userStatus := range usersStatuses { + if userStatus.Status != "online" { + t.Fatal("Status should be offline") + } + } + + app.SetStatusAwayIfNeeded(th.BasicUser.Id, true) + app.SetStatusAwayIfNeeded(th.BasicUser2.Id, true) + usersStatuses, resp = Client.GetUsersStatusesByIds(usersIds) + CheckNoError(t, resp) + for _, userStatus := range usersStatuses { + if userStatus.Status != "away" { + t.Fatal("Status should be offline") + } + } +} |