summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorNick Frazier <nrflaw@gmail.com>2017-10-19 08:10:29 -0400
committerJoram Wilander <jwawilander@gmail.com>2017-10-19 08:10:29 -0400
commit7fa4913f902457dadb1a4806ce194eb122dbc090 (patch)
treeea340ad55f6dfa1e6ee647e0a87af69ac406e25d /model
parent8e19ba029f889519d93cf272960dce858971106c (diff)
downloadchat-7fa4913f902457dadb1a4806ce194eb122dbc090.tar.gz
chat-7fa4913f902457dadb1a4806ce194eb122dbc090.tar.bz2
chat-7fa4913f902457dadb1a4806ce194eb122dbc090.zip
[PLT-7794] Add user access token enable/disable endpoints (#7630)
* Add column to UserAccessTokens table * PLT-7794 Add user access token enable/disable endpoints * replaced eliminated global variable * updates to user_access_token_store and upgrade.go * style fix and cleanup
Diffstat (limited to 'model')
-rw-r--r--model/client4.go26
-rw-r--r--model/user_access_token.go2
2 files changed, 28 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go
index 5703c4143..dc5a25bec 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -1065,6 +1065,32 @@ func (c *Client4) RevokeUserAccessToken(tokenId string) (bool, *Response) {
}
}
+// DisableUserAccessToken will disable a user access token by id. Must have the
+// 'revoke_user_access_token' permission and if disabling for another user, must have the
+// 'edit_other_users' permission.
+func (c *Client4) DisableUserAccessToken(tokenId string) (bool, *Response) {
+ requestBody := map[string]string{"token_id": tokenId}
+ if r, err := c.DoApiPost(c.GetUsersRoute()+"/tokens/disable", MapToJson(requestBody)); err != nil {
+ return false, BuildErrorResponse(r, err)
+ } else {
+ defer closeBody(r)
+ return CheckStatusOK(r), BuildResponse(r)
+ }
+}
+
+// EnableUserAccessToken will enable a user access token by id. Must have the
+// 'create_user_access_token' permission and if enabling for another user, must have the
+// 'edit_other_users' permission.
+func (c *Client4) EnableUserAccessToken(tokenId string) (bool, *Response) {
+ requestBody := map[string]string{"token_id": tokenId}
+ if r, err := c.DoApiPost(c.GetUsersRoute()+"/tokens/enable", MapToJson(requestBody)); err != nil {
+ return false, BuildErrorResponse(r, err)
+ } else {
+ defer closeBody(r)
+ return CheckStatusOK(r), BuildResponse(r)
+ }
+}
+
// Team Section
// CreateTeam creates a team in the system based on the provided team struct.
diff --git a/model/user_access_token.go b/model/user_access_token.go
index 090780fd0..e189ec233 100644
--- a/model/user_access_token.go
+++ b/model/user_access_token.go
@@ -14,6 +14,7 @@ type UserAccessToken struct {
Token string `json:"token,omitempty"`
UserId string `json:"user_id"`
Description string `json:"description"`
+ IsActive bool `json:"is_active"`
}
func (t *UserAccessToken) IsValid() *AppError {
@@ -38,6 +39,7 @@ func (t *UserAccessToken) IsValid() *AppError {
func (t *UserAccessToken) PreSave() {
t.Id = NewId()
+ t.IsActive = true
}
func (t *UserAccessToken) ToJson() string {