diff options
author | Saturnino Abril <saturnino.abril@gmail.com> | 2017-03-31 22:58:47 +0900 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-03-31 09:58:47 -0400 |
commit | 5d56fbb036cc7044eae639c92836e0b14ffe7dab (patch) | |
tree | b497427cc50b4ca80694bde93e81878458660e0b /api4/post.go | |
parent | 5f6d50bff1b4098bc0ef3c120e7b12104e5c4894 (diff) | |
download | chat-5d56fbb036cc7044eae639c92836e0b14ffe7dab.tar.gz chat-5d56fbb036cc7044eae639c92836e0b14ffe7dab.tar.bz2 chat-5d56fbb036cc7044eae639c92836e0b14ffe7dab.zip |
APIv4 POST /posts/{post_id/pin & unpin (#5906)
* APIv4 get /posts/{post_id}/pin & unpin
* remove PinnedPost from api test helper
Diffstat (limited to 'api4/post.go')
-rw-r--r-- | api4/post.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/api4/post.go b/api4/post.go index 9c671ec21..f16a1ba3d 100644 --- a/api4/post.go +++ b/api4/post.go @@ -26,6 +26,8 @@ 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") + BaseRoutes.Post.Handle("/pin", ApiSessionRequired(pinPost)).Methods("POST") + BaseRoutes.Post.Handle("/unpin", ApiSessionRequired(unpinPost)).Methods("POST") } func createPost(c *Context, w http.ResponseWriter, r *http.Request) { @@ -274,6 +276,38 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(patchedPost.ToJson())) } +func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinned bool) { + c.RequirePostId() + if c.Err != nil { + return + } + + if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) { + c.SetPermissionError(model.PERMISSION_READ_CHANNEL) + return + } + + patch := &model.PostPatch{} + patch.IsPinned = new(bool) + *patch.IsPinned = isPinned + + _, err := app.PatchPost(c.Params.PostId, patch) + if err != nil { + c.Err = err + return + } + + ReturnStatusOK(w) +} + +func pinPost(c *Context, w http.ResponseWriter, r *http.Request) { + saveIsPinnedPost(c, w, r, true) +} + +func unpinPost(c *Context, w http.ResponseWriter, r *http.Request) { + saveIsPinnedPost(c, w, r, false) +} + func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) { c.RequirePostId() if c.Err != nil { |