summaryrefslogtreecommitdiffstats
path: root/api4/user.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-02-28 22:11:56 +0900
committerJoram Wilander <jwawilander@gmail.com>2017-02-28 08:11:55 -0500
commit66c5f7a31c5d0f26d394b94747c17ee55e5d5ce4 (patch)
tree5ccb3fc95f07d996cc0830431a64a341fee6eb3a /api4/user.go
parentda902ef8bacb0751c7bd681abdc58039812d6430 (diff)
downloadchat-66c5f7a31c5d0f26d394b94747c17ee55e5d5ce4.tar.gz
chat-66c5f7a31c5d0f26d394b94747c17ee55e5d5ce4.tar.bz2
chat-66c5f7a31c5d0f26d394b94747c17ee55e5d5ce4.zip
Implementation of APIv4: POST users/{user_id}/image (#5537)
* APIv4: POST users/{user_id}/image * removed 'return' and rebased to master
Diffstat (limited to 'api4/user.go')
-rw-r--r--api4/user.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/api4/user.go b/api4/user.go
index 9fa6568d3..822cd60c4 100644
--- a/api4/user.go
+++ b/api4/user.go
@@ -23,6 +23,7 @@ func InitUser() {
BaseRoutes.User.Handle("", ApiSessionRequired(getUser)).Methods("GET")
BaseRoutes.User.Handle("/image", ApiSessionRequired(getProfileImage)).Methods("GET")
+ BaseRoutes.User.Handle("/image", ApiSessionRequired(setProfileImage)).Methods("POST")
BaseRoutes.User.Handle("", ApiSessionRequired(updateUser)).Methods("PUT")
BaseRoutes.User.Handle("/patch", ApiSessionRequired(patchUser)).Methods("PUT")
BaseRoutes.User.Handle("", ApiSessionRequired(deleteUser)).Methods("DELETE")
@@ -197,6 +198,60 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
+func setProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
+ c.RequireUserId()
+ if c.Err != nil {
+ return
+ }
+
+ if !app.SessionHasPermissionToUser(c.Session, c.Params.UserId) {
+ c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
+ return
+ }
+
+ if len(utils.Cfg.FileSettings.DriverName) == 0 {
+ c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.storage.app_error", nil, "")
+ c.Err.StatusCode = http.StatusNotImplemented
+ return
+ }
+
+ if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize {
+ c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.too_large.app_error", nil, "")
+ c.Err.StatusCode = http.StatusRequestEntityTooLarge
+ return
+ }
+
+ if err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize); err != nil {
+ c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.parse.app_error", nil, "")
+ return
+ }
+
+ m := r.MultipartForm
+
+ imageArray, ok := m.File["image"]
+ if !ok {
+ c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.no_file.app_error", nil, "")
+ c.Err.StatusCode = http.StatusBadRequest
+ return
+ }
+
+ if len(imageArray) <= 0 {
+ c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.array.app_error", nil, "")
+ c.Err.StatusCode = http.StatusBadRequest
+ return
+ }
+
+ imageData := imageArray[0]
+
+ if err := app.SetProfileImage(c.Session.UserId, imageData); err != nil {
+ c.Err = err
+ return
+ }
+
+ c.LogAudit("")
+ ReturnStatusOK(w)
+}
+
func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
inTeamId := r.URL.Query().Get("in_team")
inChannelId := r.URL.Query().Get("in_channel")