Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APIV4] GET /users/{user_id}/status - user status endpoint for apiV4 (#…
- Loading branch information
1 parent
28ad645
commit 5bf6ae0
Showing
7 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
package api4 | ||
|
||
import ( | ||
"net/http" | ||
|
||
l4g "github.com/alecthomas/log4go" | ||
|
||
"github.com/mattermost/platform/app" | ||
"github.com/mattermost/platform/model" | ||
"github.com/mattermost/platform/utils" | ||
) | ||
|
||
func InitStatus() { | ||
l4g.Debug(utils.T("api.status.init.debug")) | ||
|
||
BaseRoutes.User.Handle("/status", ApiHandler(getUserStatus)).Methods("GET") | ||
|
||
} | ||
|
||
func getUserStatus(c *Context, w http.ResponseWriter, r *http.Request) { | ||
c.RequireUserId() | ||
if c.Err != nil { | ||
return | ||
} | ||
|
||
if statusMap, err := app.GetUserStatusesByIds([]string{c.Params.UserId}); err != nil { | ||
c.Err = err | ||
return | ||
} else { | ||
if len(statusMap) == 0 { | ||
c.Err = model.NewAppError("UserStatus", "api.status.user_not_found.app_error", nil, "", http.StatusNotFound) | ||
return | ||
} else { | ||
w.Write([]byte(statusMap[0].ToJson())) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package api4 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/mattermost/platform/app" | ||
) | ||
|
||
func TestGetUserStatus(t *testing.T) { | ||
th := Setup().InitBasic() | ||
defer TearDown() | ||
Client := th.Client | ||
|
||
userStatus, resp := Client.GetUserStatus(th.BasicUser.Id, "") | ||
CheckNoError(t, resp) | ||
if userStatus.Status != "offline" { | ||
t.Fatal("Should return offline status") | ||
} | ||
|
||
app.SetStatusOnline(th.BasicUser.Id, "", true) | ||
userStatus, resp = Client.GetUserStatus(th.BasicUser.Id, "") | ||
CheckNoError(t, resp) | ||
if userStatus.Status != "online" { | ||
t.Fatal("Should return online status") | ||
} | ||
|
||
app.SetStatusAwayIfNeeded(th.BasicUser.Id, true) | ||
userStatus, resp = Client.GetUserStatus(th.BasicUser.Id, "") | ||
CheckNoError(t, resp) | ||
if userStatus.Status != "away" { | ||
t.Fatal("Should return away status") | ||
} | ||
|
||
app.SetStatusOffline(th.BasicUser.Id, true) | ||
userStatus, resp = Client.GetUserStatus(th.BasicUser.Id, "") | ||
CheckNoError(t, resp) | ||
if userStatus.Status != "offline" { | ||
t.Fatal("Should return offline status") | ||
} | ||
|
||
//Get user2 status logged as user1 | ||
userStatus, resp = Client.GetUserStatus(th.BasicUser2.Id, "") | ||
CheckNoError(t, resp) | ||
if userStatus.Status != "offline" { | ||
t.Fatal("Should return offline status") | ||
} | ||
|
||
Client.Logout() | ||
th.LoginBasic2() | ||
userStatus, resp = Client.GetUserStatus(th.BasicUser2.Id, "") | ||
CheckNoError(t, resp) | ||
if userStatus.Status != "offline" { | ||
t.Fatal("Should return offline status") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters