[MM-25648] api4: add user/bot convert endpoints (#14877)
* api4: add user/bot convert endpoints * api4: add convert user/bot to local mode * api4: fix linting issues * api4/bot: reflect review comments * api4: update convert user endpoint paths * remove shadow decl * fix translation problems
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
cb89c53dcc
Коммит
6a4e3293f8
34
api4/user.go
34
api4/user.go
@@ -46,6 +46,7 @@ func (api *API) InitUser() {
|
||||
api.BaseRoutes.User.Handle("/password", api.ApiSessionRequired(updatePassword)).Methods("PUT")
|
||||
api.BaseRoutes.User.Handle("/promote", api.ApiSessionRequired(promoteGuestToUser)).Methods("POST")
|
||||
api.BaseRoutes.User.Handle("/demote", api.ApiSessionRequired(demoteUserToGuest)).Methods("POST")
|
||||
api.BaseRoutes.User.Handle("/convert_to_bot", api.ApiSessionRequired(convertUserToBot)).Methods("POST")
|
||||
api.BaseRoutes.Users.Handle("/password/reset", api.ApiHandler(resetPassword)).Methods("POST")
|
||||
api.BaseRoutes.Users.Handle("/password/reset/send", api.ApiHandler(sendPasswordReset)).Methods("POST")
|
||||
api.BaseRoutes.Users.Handle("/email/verify", api.ApiHandler(verifyUserEmail)).Methods("POST")
|
||||
@@ -2485,3 +2486,36 @@ func verifyUserEmailWithoutToken(c *Context, w http.ResponseWriter, r *http.Requ
|
||||
|
||||
w.Write([]byte(user.ToJson()))
|
||||
}
|
||||
|
||||
func convertUserToBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequireUserId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := c.App.GetUser(c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
auditRec := c.MakeAuditRecord("convertUserToBot", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddMeta("user", user)
|
||||
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
||||
bot, err := c.App.ConvertUserToBot(user)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
auditRec.AddMeta("convertedTo", bot)
|
||||
|
||||
w.Write(bot.ToJson())
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user