From 213a072b38d29d3c3ec8e150584685b1144a7d6a Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 29 Aug 2017 16:14:59 -0500 Subject: PLT-6403: Interactive messages (#7274) * wip * finish first pass * requested changes * add DoPostAction to Client4 --- api4/context.go | 11 +++++++++++ api4/params.go | 5 +++++ api4/post.go | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+) (limited to 'api4') diff --git a/api4/context.go b/api4/context.go index 69351a098..e95e29991 100644 --- a/api4/context.go +++ b/api4/context.go @@ -586,3 +586,14 @@ func (c *Context) RequireJobType() *Context { } return c } + +func (c *Context) RequireActionId() *Context { + if c.Err != nil { + return c + } + + if len(c.Params.ActionId) != 26 { + c.SetInvalidUrlParam("action_id") + } + return c +} diff --git a/api4/params.go b/api4/params.go index b48e5fc1b..8b1d0febe 100644 --- a/api4/params.go +++ b/api4/params.go @@ -39,6 +39,7 @@ type ApiParams struct { Service string JobId string JobType string + ActionId string Page int PerPage int Permanent bool @@ -137,6 +138,10 @@ func ApiParamsFromRequest(r *http.Request) *ApiParams { params.JobType = val } + if val, ok := props["action_id"]; ok { + params.ActionId = val + } + if val, err := strconv.Atoi(r.URL.Query().Get("page")); err != nil || val < 0 { params.Page = PAGE_DEFAULT } else { diff --git a/api4/post.go b/api4/post.go index deaad1e1c..ea23e098b 100644 --- a/api4/post.go +++ b/api4/post.go @@ -27,6 +27,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") + BaseRoutes.Post.Handle("/actions/{action_id:[A-Za-z0-9]+}", ApiSessionRequired(doPostAction)).Methods("POST") BaseRoutes.Post.Handle("/pin", ApiSessionRequired(pinPost)).Methods("POST") BaseRoutes.Post.Handle("/unpin", ApiSessionRequired(unpinPost)).Methods("POST") } @@ -428,3 +429,22 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(model.FileInfosToJson(infos))) } } + +func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequirePostId().RequireActionId() + if c.Err != nil { + return + } + + if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) { + c.SetPermissionError(model.PERMISSION_READ_CHANNEL) + return + } + + if err := app.DoPostAction(c.Params.PostId, c.Params.ActionId, c.Session.UserId); err != nil { + c.Err = err + return + } + + ReturnStatusOK(w) +} -- cgit v1.2.3-1-g7c22