diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-02-16 09:46:55 -0500 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-02-16 09:46:55 -0500 |
commit | f87d42916f1ec4287daad29d6ffd4145dfc4b5cd (patch) | |
tree | dd0296f0023efe031dbacbb39b724540bed2d8a5 /api4/user.go | |
parent | 8f262241595cc9377e4c3adce9c728eaff38c5f3 (diff) | |
download | chat-f87d42916f1ec4287daad29d6ffd4145dfc4b5cd.tar.gz chat-f87d42916f1ec4287daad29d6ffd4145dfc4b5cd.tar.bz2 chat-f87d42916f1ec4287daad29d6ffd4145dfc4b5cd.zip |
Implement PUT /users/{user_id}/patch endpoint for APIv4 (#5418)
Diffstat (limited to 'api4/user.go')
-rw-r--r-- | api4/user.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/api4/user.go b/api4/user.go index d8d071cd2..e394b9661 100644 --- a/api4/user.go +++ b/api4/user.go @@ -21,6 +21,7 @@ func InitUser() { BaseRoutes.User.Handle("", ApiSessionRequired(getUser)).Methods("GET") BaseRoutes.User.Handle("", ApiSessionRequired(updateUser)).Methods("PUT") + BaseRoutes.User.Handle("/patch", ApiSessionRequired(patchUser)).Methods("PUT") BaseRoutes.User.Handle("", ApiSessionRequired(deleteUser)).Methods("DELETE") BaseRoutes.User.Handle("/roles", ApiSessionRequired(updateUserRoles)).Methods("PUT") BaseRoutes.User.Handle("/password", ApiSessionRequired(updatePassword)).Methods("PUT") @@ -255,6 +256,32 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) { } } +func patchUser(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequireUserId() + if c.Err != nil { + return + } + + patch := model.UserPatchFromJson(r.Body) + if patch == nil { + c.SetInvalidParam("user") + return + } + + if !app.SessionHasPermissionToUser(c.Session, c.Params.UserId) { + c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS) + return + } + + if ruser, err := app.PatchUser(c.Params.UserId, patch, c.GetSiteURL(), c.IsSystemAdmin()); err != nil { + c.Err = err + return + } else { + c.LogAudit("") + w.Write([]byte(ruser.ToJson())) + } +} + func deleteUser(c *Context, w http.ResponseWriter, r *http.Request) { c.RequireUserId() if c.Err != nil { |