summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorAdrian Carolli <adrian.caarolli@gmail.com>2018-01-05 14:46:48 -0500
committerJoram Wilander <jwawilander@gmail.com>2018-01-05 14:46:48 -0500
commitfd3fa8f8dcfa5de42a16db9b62e1d6628f43b0fd (patch)
treef60a1d693dc554dddfc9a365e53420359be932a1 /model
parent66bdf830b5c7bc2e2fe7598355a142720010de91 (diff)
downloadchat-fd3fa8f8dcfa5de42a16db9b62e1d6628f43b0fd.tar.gz
chat-fd3fa8f8dcfa5de42a16db9b62e1d6628f43b0fd.tar.bz2
chat-fd3fa8f8dcfa5de42a16db9b62e1d6628f43b0fd.zip
[PLT-7793] Added /users/tokens endpoint (#8038)
* Added /users/tokens/all endpoint - UserAccessStore now has getAll method - Added tests - Added route - Added handler * Remove space fix check-style * Remove blank space check-style * Fixes for make check-style * Remove extra code that is un-needed in user_test.go * Rename endpoint + grammar - Renamed /users/tokens/all to /users/tokens - Renamed getUserAccessTokens to getUserAccessTokensForUser - Renamed getAllUserAccessTokens to getUserAccessTokens - Minor Grammar changes * Add localization for sql_user_access_token.get_all * Fix minor plural spelling
Diffstat (limited to 'model')
-rw-r--r--model/client4.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/model/client4.go b/model/client4.go
index e84a23e5f..3f3439ebe 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -82,6 +82,10 @@ func (c *Client4) GetUserRoute(userId string) string {
return fmt.Sprintf(c.GetUsersRoute()+"/%v", userId)
}
+func (c *Client4) GetUserAccessTokensRoute() string {
+ return fmt.Sprintf(c.GetUsersRoute() + "/tokens")
+}
+
func (c *Client4) GetUserAccessTokenRoute(tokenId string) string {
return fmt.Sprintf(c.GetUsersRoute()+"/tokens/%v", tokenId)
}
@@ -1035,10 +1039,23 @@ func (c *Client4) CreateUserAccessToken(userId, description string) (*UserAccess
}
}
-// GetUserAccessToken will get a user access token's id, description and the user_id
-// of the user it is for. The actual token will not be returned. Must have the
-// 'read_user_access_token' permission and if getting for another user, must have the
-// 'edit_other_users' permission.
+// GetUserAccessTokens will get a page of access tokens' id, description, is_active
+// and the user_id in the system. The actual token will not be returned. Must have
+// the 'manage_system' permission.
+func (c *Client4) GetUserAccessTokens(page int, perPage int) ([]*UserAccessToken, *Response) {
+ query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
+ if r, err := c.DoApiGet(c.GetUserAccessTokensRoute()+query, ""); err != nil {
+ return nil, BuildErrorResponse(r, err)
+ } else {
+ defer closeBody(r)
+ return UserAccessTokenListFromJson(r.Body), BuildResponse(r)
+ }
+}
+
+// GetUserAccessToken will get a user access tokens' id, description, is_active
+// and the user_id of the user it is for. The actual token will not be returned.
+// Must have the 'read_user_access_token' permission and if getting for another
+// user, must have the 'edit_other_users' permission.
func (c *Client4) GetUserAccessToken(tokenId string) (*UserAccessToken, *Response) {
if r, err := c.DoApiGet(c.GetUserAccessTokenRoute(tokenId), ""); err != nil {
return nil, BuildErrorResponse(r, err)