PLT-6931 Properly parse request body in post search (#6768)
* Properly parse request body in post search * Update driver to use correct body
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
3e9b5c2776
Коммит
e527b6bbe4
12
api4/post.go
12
api4/post.go
@@ -277,18 +277,14 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
props := model.MapFromJson(r.Body)
|
props := model.StringInterfaceFromJson(r.Body)
|
||||||
terms := props["terms"]
|
terms, ok := props["terms"].(string)
|
||||||
|
if !ok || len(terms) == 0 {
|
||||||
if len(terms) == 0 {
|
|
||||||
c.SetInvalidParam("terms")
|
c.SetInvalidParam("terms")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isOrSearch := false
|
isOrSearch, _ := props["is_or_search"].(bool)
|
||||||
if val, ok := props["is_or_search"]; ok && val != "" {
|
|
||||||
isOrSearch, _ = strconv.ParseBool(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
posts, err := app.SearchPostsInTeam(terms, c.Session.UserId, c.Params.TeamId, isOrSearch)
|
posts, err := app.SearchPostsInTeam(terms, c.Session.UserId, c.Params.TeamId, isOrSearch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1684,8 +1684,8 @@ func (c *Client4) GetPostsBefore(channelId, postId string, page, perPage int, et
|
|||||||
|
|
||||||
// SearchPosts returns any posts with matching terms string.
|
// SearchPosts returns any posts with matching terms string.
|
||||||
func (c *Client4) SearchPosts(teamId string, terms string, isOrSearch bool) (*PostList, *Response) {
|
func (c *Client4) SearchPosts(teamId string, terms string, isOrSearch bool) (*PostList, *Response) {
|
||||||
requestBody := map[string]string{"terms": terms, "is_or_search": strconv.FormatBool(isOrSearch)}
|
requestBody := map[string]interface{}{"terms": terms, "is_or_search": isOrSearch}
|
||||||
if r, err := c.DoApiPost(c.GetTeamRoute(teamId)+"/posts/search", MapToJson(requestBody)); err != nil {
|
if r, err := c.DoApiPost(c.GetTeamRoute(teamId)+"/posts/search", StringInterfaceToJson(requestBody)); err != nil {
|
||||||
return nil, BuildErrorResponse(r, err)
|
return nil, BuildErrorResponse(r, err)
|
||||||
} else {
|
} else {
|
||||||
defer closeBody(r)
|
defer closeBody(r)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user