[MM-42194] Get file information from a deleted post (#20279)
* Introduced inlcude_deleted query parameter to allow admins to retrieve contents of post regardless of deletion status * Introduced new client route and tests for getting file info of deleted posts * Fixed tests due to caching of posts * gofmt * Small formatting updates * Invalidating file infos cache on delete of post if post includes files * Including deleted in migration flow * Moved invalidating of cache Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
bc7f961d75
Коммит
3d7859396d
@@ -898,7 +898,13 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
infos, err := c.App.GetFileInfosForPostWithMigration(c.Params.PostId)
|
||||
includeDeleted, _ := strconv.ParseBool(r.URL.Query().Get("include_deleted"))
|
||||
if includeDeleted && !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionManageSystem) {
|
||||
c.SetPermissionError(model.PermissionManageSystem)
|
||||
return
|
||||
}
|
||||
|
||||
infos, err := c.App.GetFileInfosForPostWithMigration(c.Params.PostId, includeDeleted)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -2623,6 +2623,39 @@ func TestGetFileInfosForPost(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// Delete post
|
||||
th.SystemAdminClient.DeletePost(post.Id)
|
||||
|
||||
// Normal client should get 404 when trying to access deleted post normally
|
||||
_, resp, err = client.GetFileInfosForPost(post.Id, "")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
// Normal client should get unauthorized when trying to access deleted post
|
||||
_, resp, err = client.GetFileInfosForPostIncludeDeleted(post.Id, "")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// System client should get 404 when trying to access deleted post normally
|
||||
_, resp, err = th.SystemAdminClient.GetFileInfosForPost(post.Id, "")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
// System client should be able to access deleted post with include_deleted param
|
||||
infos, _, err = th.SystemAdminClient.GetFileInfosForPostIncludeDeleted(post.Id, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, infos, 3, "missing file infos")
|
||||
|
||||
found = false
|
||||
for _, info := range infos {
|
||||
if info.Id == fileIds[0] {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
require.True(t, found, "missing file info")
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetFileInfosForPost(model.NewId(), "")
|
||||
require.Error(t, err)
|
||||
|
||||
Ссылка в новой задаче
Block a user