From 2f15523fe88c3a382abda1e64b2ef962c3ab5128 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Thu, 30 Mar 2017 00:06:51 +0900 Subject: APIv4 put /posts/{post_id}/patch (#5883) * APIv4 put /posts/{post_id}/patch * Add props and edit permission --- api4/post.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'api4/post.go') 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 { -- cgit v1.2.3-1-g7c22