summaryrefslogtreecommitdiffstats
path: root/api4/post.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-03-30 00:06:51 +0900
committerCorey Hulen <corey@hulen.com>2017-03-29 08:06:51 -0700
commit2f15523fe88c3a382abda1e64b2ef962c3ab5128 (patch)
treeb82d0f98d68c16fd23e886072f8a513d8450bef0 /api4/post.go
parent31830ffc7b578de643f5748227e4b783ee0782dd (diff)
downloadchat-2f15523fe88c3a382abda1e64b2ef962c3ab5128.tar.gz
chat-2f15523fe88c3a382abda1e64b2ef962c3ab5128.tar.bz2
chat-2f15523fe88c3a382abda1e64b2ef962c3ab5128.zip
APIv4 put /posts/{post_id}/patch (#5883)
* APIv4 put /posts/{post_id}/patch * Add props and edit permission
Diffstat (limited to 'api4/post.go')
-rw-r--r--api4/post.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/api4/post.go b/api4/post.go
index 329241139..af5fc8cfa 100644
--- a/api4/post.go
+++ b/api4/post.go
@@ -25,6 +25,7 @@ func InitPost() {
BaseRoutes.Team.Handle("/posts/search", ApiSessionRequired(searchPosts)).Methods("POST")
BaseRoutes.Post.Handle("", ApiSessionRequired(updatePost)).Methods("PUT")
+ BaseRoutes.Post.Handle("/patch", ApiSessionRequired(patchPost)).Methods("PUT")
}
func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -245,6 +246,33 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(rpost.ToJson()))
}
+func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
+ c.RequirePostId()
+ if c.Err != nil {
+ return
+ }
+
+ post := model.PostPatchFromJson(r.Body)
+
+ if post == nil {
+ c.SetInvalidParam("post")
+ return
+ }
+
+ if !app.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) {
+ c.SetPermissionError(model.PERMISSION_EDIT_OTHERS_POSTS)
+ return
+ }
+
+ patchedPost, err := app.PatchPost(c.Params.PostId, post)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ w.Write([]byte(patchedPost.ToJson()))
+}
+
func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequirePostId()
if c.Err != nil {