diff options
author | Andrei Stanciu <andrei.stanciu@geminisols.ro> | 2017-02-28 11:34:32 +0200 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2017-02-28 09:34:32 +0000 |
commit | 6ff350380b209266282cff32872f94bb9cd31d57 (patch) | |
tree | 916390cf6af4358b599a67de4897bd68f100f432 /api4/post.go | |
parent | 76fa840b52ea79f05e5e681abca92b279de78182 (diff) | |
download | chat-6ff350380b209266282cff32872f94bb9cd31d57.tar.gz chat-6ff350380b209266282cff32872f94bb9cd31d57.tar.bz2 chat-6ff350380b209266282cff32872f94bb9cd31d57.zip |
ApiV4: PUT /posts/{post_id} (#5521)
Diffstat (limited to 'api4/post.go')
-rw-r--r-- | api4/post.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/api4/post.go b/api4/post.go index 6a8b1bff2..4632cb6df 100644 --- a/api4/post.go +++ b/api4/post.go @@ -24,6 +24,7 @@ func InitPost() { BaseRoutes.PostsForChannel.Handle("", ApiSessionRequired(getPostsForChannel)).Methods("GET") BaseRoutes.Team.Handle("/posts/search", ApiSessionRequired(searchPosts)).Methods("POST") + BaseRoutes.Post.Handle("", ApiSessionRequired(updatePost)).Methods("PUT") } func createPost(c *Context, w http.ResponseWriter, r *http.Request) { @@ -176,6 +177,31 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(posts.ToJson())) } +func updatePost(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequirePostId() + post := model.PostFromJson(r.Body) + + if post == nil { + c.SetInvalidParam("post") + return + } + + if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) { + c.SetPermissionError(model.PERMISSION_EDIT_POST) + return + } + + post.UserId = c.Session.UserId + + rpost, err := app.UpdatePost(post) + if err != nil { + c.Err = err + return + } + + w.Write([]byte(rpost.ToJson())) +} + func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) { c.RequirePostId() if c.Err != nil { @@ -198,3 +224,4 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(model.FileInfosToJson(infos))) } } + |