[MM-42192] Include deleted posts in GetPost (#20358)
* Introduced include_deleted query param on get posts endpoint * Update the correct func name in the comment. Co-authored-by: santoniriccardo <santoni.riccardo@gmail.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
@@ -1613,7 +1613,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if ok && len(postRootId) == 26 {
|
||||
rootPost, err := c.App.GetSinglePost(postRootId)
|
||||
rootPost, err := c.App.GetSinglePost(postRootId, false)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -164,7 +164,7 @@ func localAddChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if ok && len(postRootId) == 26 {
|
||||
rootPost, err := c.App.GetSinglePost(postRootId)
|
||||
rootPost, err := c.App.GetSinglePost(postRootId, false)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
18
api4/post.go
18
api4/post.go
@@ -387,7 +387,13 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
post, err := c.App.GetPostIfAuthorized(c.Params.PostId, c.AppContext.Session())
|
||||
includeDeleted, _ := strconv.ParseBool(r.URL.Query().Get("include_deleted"))
|
||||
if includeDeleted && !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionManageSystem) {
|
||||
c.SetPermissionError(model.PermissionManageSystem)
|
||||
return
|
||||
}
|
||||
|
||||
post, err := c.App.GetPostIfAuthorized(c.Params.PostId, c.AppContext.Session(), includeDeleted)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -471,7 +477,7 @@ func deletePost(c *Context, w http.ResponseWriter, _ *http.Request) {
|
||||
defer c.LogAuditRecWithLevel(auditRec, app.LevelContent)
|
||||
auditRec.AddMeta("post_id", c.Params.PostId)
|
||||
|
||||
post, err := c.App.GetSinglePost(c.Params.PostId)
|
||||
post, err := c.App.GetSinglePost(c.Params.PostId, false)
|
||||
if err != nil {
|
||||
c.SetPermissionError(model.PermissionDeletePost)
|
||||
return
|
||||
@@ -563,7 +569,7 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = c.App.GetPostIfAuthorized(post.Id, c.AppContext.Session()); err != nil {
|
||||
if _, err = c.App.GetPostIfAuthorized(post.Id, c.AppContext.Session(), false); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -708,7 +714,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
originalPost, err := c.App.GetSinglePost(c.Params.PostId)
|
||||
originalPost, err := c.App.GetSinglePost(c.Params.PostId, false)
|
||||
if err != nil {
|
||||
c.SetPermissionError(model.PermissionEditPost)
|
||||
return
|
||||
@@ -759,7 +765,7 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
// Updating the file_ids of a post is not a supported operation and will be ignored
|
||||
post.FileIds = nil
|
||||
|
||||
originalPost, err := c.App.GetSinglePost(c.Params.PostId)
|
||||
originalPost, err := c.App.GetSinglePost(c.Params.PostId, false)
|
||||
if err != nil {
|
||||
c.SetPermissionError(model.PermissionEditPost)
|
||||
return
|
||||
@@ -834,7 +840,7 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, isPinned bool) {
|
||||
return
|
||||
}
|
||||
|
||||
post, err := c.App.GetSinglePost(c.Params.PostId)
|
||||
post, err := c.App.GetSinglePost(c.Params.PostId, false)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -996,7 +996,7 @@ func TestPinPost(t *testing.T) {
|
||||
_, err := client.PinPost(post.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
rpost, appErr := th.App.GetSinglePost(post.Id)
|
||||
rpost, appErr := th.App.GetSinglePost(post.Id, false)
|
||||
require.Nil(t, appErr)
|
||||
require.True(t, rpost.IsPinned, "failed to pin post")
|
||||
|
||||
@@ -1026,7 +1026,7 @@ func TestUnpinPost(t *testing.T) {
|
||||
_, err := client.UnpinPost(pinnedPost.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
rpost, appErr := th.App.GetSinglePost(pinnedPost.Id)
|
||||
rpost, appErr := th.App.GetSinglePost(pinnedPost.Id, false)
|
||||
require.Nil(t, appErr)
|
||||
require.False(t, rpost.IsPinned)
|
||||
|
||||
@@ -2000,6 +2000,29 @@ func TestGetPost(t *testing.T) {
|
||||
_, _, err = th.LocalClient.GetPost(privatePost.Id, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Delete post
|
||||
th.SystemAdminClient.DeletePost(th.BasicPost.Id)
|
||||
|
||||
// Normal client should get 404 when trying to access deleted post normally
|
||||
_, resp, err = client.GetPost(th.BasicPost.Id, "")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
// Normal client should get unauthorized when trying to access deleted post
|
||||
_, resp, err = client.GetPostIncludeDeleted(th.BasicPost.Id, "")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// System client should get 404 when trying to access deleted post normally
|
||||
_, resp, err = th.SystemAdminClient.GetPost(th.BasicPost.Id, "")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
// System client should be able to access deleted post with include_deleted param
|
||||
post, _, err := th.SystemAdminClient.GetPostIncludeDeleted(th.BasicPost.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, th.BasicPost.Id, post.Id)
|
||||
|
||||
client.Logout()
|
||||
|
||||
// Normal client should get unauthorized, but local client should get 404.
|
||||
|
||||
@@ -110,7 +110,7 @@ func updatePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
for _, pref := range preferences {
|
||||
if pref.Category == model.PreferenceCategoryFlaggedPost {
|
||||
post, err := c.App.GetSinglePost(pref.Name)
|
||||
post, err := c.App.GetSinglePost(pref.Name, false)
|
||||
if err != nil {
|
||||
c.SetInvalidParam("preference.name")
|
||||
return
|
||||
|
||||
@@ -569,7 +569,7 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Return post data only when PostId is passed.
|
||||
if ack.PostId != "" && ack.NotificationType == model.PushTypeMessage {
|
||||
if _, appErr := c.App.GetPostIfAuthorized(ack.PostId, c.AppContext.Session()); appErr != nil {
|
||||
if _, appErr := c.App.GetPostIfAuthorized(ack.PostId, c.AppContext.Session(), false); appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user