[MM-38239 & MM-39788] Recent files causing crash (#18942)
* wip * adding tests for new endpoint * tool updates * new function for getting postsByIds * fixing test * adding limit of 1000 to post query * fixing PR comments * fixing permission logic Co-authored-by: Collin <collineng@gmail.com> Co-authored-by: Collin Eng <eng.engineereng@gmail.com> Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MBP.ht.home>
Этот коммит содержится в:
52
api4/post.go
52
api4/post.go
@@ -19,6 +19,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("/ids", api.APISessionRequired(getPostsByIds)).Methods("POST")
|
||||
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")
|
||||
@@ -408,6 +409,57 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func getPostsByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
postIDs := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(postIDs) == 0 {
|
||||
c.SetInvalidParam("post_ids")
|
||||
return
|
||||
}
|
||||
|
||||
if len(postIDs) > 1000 {
|
||||
c.Err = model.NewAppError("getPostsByIds", "api.post.posts_by_ids.invalid_body.request_error", map[string]interface{}{"MaxLength": 1000}, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
postsList, err := c.App.GetPostsByIds(postIDs)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
var posts = []*model.Post{}
|
||||
channelMap := make(map[string]*model.Channel)
|
||||
|
||||
for _, post := range postsList {
|
||||
var channel *model.Channel
|
||||
if val, ok := channelMap[post.ChannelId]; ok {
|
||||
channel = val
|
||||
} else {
|
||||
channel, err = c.App.GetChannel(post.ChannelId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
channelMap[channel.Id] = channel
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(*c.AppContext.Session(), channel.Id, model.PermissionReadChannel) {
|
||||
if channel.Type != model.ChannelTypeOpen || (channel.Type == model.ChannelTypeOpen && !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), channel.TeamId, model.PermissionReadPublicChannel)) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
post = c.App.PreparePostForClient(post, false, false)
|
||||
|
||||
posts = append(posts, post)
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(posts); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func deletePost(c *Context, w http.ResponseWriter, _ *http.Request) {
|
||||
c.RequirePostId()
|
||||
if c.Err != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user