From 997df03ac1455785b7a39e40edcd67b3b3e86f9e Mon Sep 17 00:00:00 2001 From: Daniel Schalla Date: Tue, 17 Apr 2018 14:20:47 +0200 Subject: Initial Commit of Ephemeral Message Support for System Admins (#8611) Fixed Permission Test Fixed and extended ephemeral message tests; Removed Online/Activity Updates Set Create Time to current time gofmt --- api4/post.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'api4/post.go') diff --git a/api4/post.go b/api4/post.go index 80088d9ef..189edfc20 100644 --- a/api4/post.go +++ b/api4/post.go @@ -4,6 +4,7 @@ package api4 import ( + "encoding/json" "net/http" "strconv" "time" @@ -15,6 +16,7 @@ func (api *API) InitPost() { api.BaseRoutes.Posts.Handle("", api.ApiSessionRequired(createPost)).Methods("POST") api.BaseRoutes.Post.Handle("", api.ApiSessionRequired(getPost)).Methods("GET") api.BaseRoutes.Post.Handle("", api.ApiSessionRequired(deletePost)).Methods("DELETE") + api.BaseRoutes.Posts.Handle("/ephemeral", api.ApiSessionRequired(createEphemeralPost)).Methods("POST") api.BaseRoutes.Post.Handle("/thread", api.ApiSessionRequired(getPostThread)).Methods("GET") api.BaseRoutes.Post.Handle("/files/info", api.ApiSessionRequired(getFileInfosForPost)).Methods("GET") api.BaseRoutes.PostsForChannel.Handle("", api.ApiSessionRequired(getPostsForChannel)).Methods("GET") @@ -69,6 +71,34 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(rp).ToJson())) } +func createEphemeralPost(c *Context, w http.ResponseWriter, r *http.Request) { + ephRequest := model.PostEphemeral{} + + json.NewDecoder(r.Body).Decode(&ephRequest) + if ephRequest.UserID == "" { + c.SetInvalidParam("user_id") + return + } + + if ephRequest.Post == nil { + c.SetInvalidParam("post") + return + } + + ephRequest.Post.UserId = c.Session.UserId + ephRequest.Post.CreateAt = model.GetMillis() + + if !c.App.SessionHasPermissionTo(c.Session, model.PERMISSION_CREATE_POST_EPHEMERAL) { + c.SetPermissionError(model.PERMISSION_CREATE_POST_EPHEMERAL) + return + } + + rp := c.App.SendEphemeralPost(ephRequest.UserID, c.App.PostWithProxyRemovedFromImageURLs(ephRequest.Post)) + + w.WriteHeader(http.StatusCreated) + w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(rp).ToJson())) +} + func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) { c.RequireChannelId() if c.Err != nil { -- cgit v1.2.3-1-g7c22