diff options
Diffstat (limited to 'api4/post.go')
-rw-r--r-- | api4/post.go | 28 |
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 { |