MM-45494: Add endpoint for message history (#20945)

* add api url

* write sql in store

* update app and client golang driver

* update layers and tests

* change sql query sort

* update layers

* fix style

* fix style post_store.go

* fix comments

* add test for app/post_test.go

* update layers

* fix test

* fix style

* fix style again :)

* add permission check

* add additional checks and tests

* change from nil to empty

* update app-layers

* fix style

* add index for OriginalId for Posts table

* fix postgres query

* update migration file names

* update app-layers

* address PR reviews

* write tests for post store

* fix style

* Update file name

* Update file name 2

* Update file name 3

* Update file name 4

* change the error orders

* update migration file name

---------

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Sinan Sonmez (Chaush)
2023-02-07 15:30:37 +01:00
коммит произвёл GitHub
родитель eabf454764
Коммит 50fec7c892
19 изменённых файлов: 433 добавлений и 0 удалений

Просмотреть файл

@@ -22,6 +22,7 @@ func (api *API) InitPost() {
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("/edit_history", api.APISessionRequired(getEditHistoryForPost)).Methods("GET")
api.BaseRoutes.Post.Handle("/thread", api.APISessionRequired(getPostThread)).Methods("GET")
api.BaseRoutes.Post.Handle("/info", api.APISessionRequired(getPostInfo)).Methods("GET")
api.BaseRoutes.Post.Handle("/files/info", api.APISessionRequired(getFileInfosForPost)).Methods("GET")
@@ -495,6 +496,39 @@ func getPostsByIds(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
func getEditHistoryForPost(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequirePostId()
if c.Err != nil {
return
}
if !c.App.SessionHasPermissionToChannelByPost(*c.AppContext.Session(), c.Params.PostId, model.PermissionEditPost) {
c.SetPermissionError(model.PermissionEditPost)
return
}
originalPost, err := c.App.GetSinglePost(c.Params.PostId, false)
if err != nil {
c.SetPermissionError(model.PermissionEditPost)
return
}
if c.AppContext.Session().UserId != originalPost.UserId {
c.SetPermissionError(model.PermissionEditPost)
return
}
postsList, err := c.App.GetEditHistoryForPost(c.Params.PostId)
if err != nil {
c.Err = err
return
}
if err := json.NewEncoder(w).Encode(postsList); err != nil {
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
func deletePost(c *Context, w http.ResponseWriter, _ *http.Request) {
c.RequirePostId()
if c.Err != nil {