[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
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
8e19ba029f
Коммит
7fa4913f90
76
api4/user.go
76
api4/user.go
@@ -61,6 +61,8 @@ func (api *API) InitUser() {
|
||||
api.BaseRoutes.User.Handle("/tokens", api.ApiSessionRequired(getUserAccessTokens)).Methods("GET")
|
||||
api.BaseRoutes.Users.Handle("/tokens/{token_id:[A-Za-z0-9]+}", api.ApiSessionRequired(getUserAccessToken)).Methods("GET")
|
||||
api.BaseRoutes.Users.Handle("/tokens/revoke", api.ApiSessionRequired(revokeUserAccessToken)).Methods("POST")
|
||||
api.BaseRoutes.Users.Handle("/tokens/disable", api.ApiSessionRequired(disableUserAccessToken)).Methods("POST")
|
||||
api.BaseRoutes.Users.Handle("/tokens/enable", api.ApiSessionRequired(enableUserAccessToken)).Methods("POST")
|
||||
}
|
||||
|
||||
func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1290,3 +1292,77 @@ func revokeUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("success - token_id=" + accessToken.Id)
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func disableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
tokenId := props["token_id"]
|
||||
|
||||
if tokenId == "" {
|
||||
c.SetInvalidParam("token_id")
|
||||
}
|
||||
|
||||
c.LogAudit("")
|
||||
|
||||
// No separate permission for this action for now
|
||||
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_REVOKE_USER_ACCESS_TOKEN) {
|
||||
c.SetPermissionError(model.PERMISSION_REVOKE_USER_ACCESS_TOKEN)
|
||||
return
|
||||
}
|
||||
|
||||
accessToken, err := c.App.GetUserAccessToken(tokenId, false)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToUser(c.Session, accessToken.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
||||
err = c.App.DisableUserAccessToken(accessToken)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
c.LogAudit("success - token_id=" + accessToken.Id)
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
tokenId := props["token_id"]
|
||||
|
||||
if tokenId == "" {
|
||||
c.SetInvalidParam("token_id")
|
||||
}
|
||||
|
||||
c.LogAudit("")
|
||||
|
||||
// No separate permission for this action for now
|
||||
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_CREATE_USER_ACCESS_TOKEN) {
|
||||
c.SetPermissionError(model.PERMISSION_CREATE_USER_ACCESS_TOKEN)
|
||||
return
|
||||
}
|
||||
|
||||
accessToken, err := c.App.GetUserAccessToken(tokenId, false)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToUser(c.Session, accessToken.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
||||
err = c.App.EnableUserAccessToken(accessToken)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
c.LogAudit("success - token_id=" + accessToken.Id)
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user