[MM-56073] MMCTL delete post command (#27539)
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
@@ -183,6 +183,11 @@ var searchFileInfoStoreTests = []searchTest{
|
||||
Fn: testFileInfoSearchEmailsWithoutQuotes,
|
||||
Tags: []string{EngineElasticSearch},
|
||||
},
|
||||
{
|
||||
Name: "Should be removed from search index when deleted",
|
||||
Fn: testSearchFileDeletedPost,
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should not search files not attached to a post",
|
||||
Fn: testFileInfoSearchNoResultForPostlessFileInfos,
|
||||
@@ -1656,6 +1661,42 @@ func testFileInfoSearchEmailsWithoutQuotes(t *testing.T, th *SearchTestHelper) {
|
||||
th.checkFileInfoInSearchResults(t, p1.Id, results.FileInfos)
|
||||
}
|
||||
|
||||
func testSearchFileDeletedPost(t *testing.T, th *SearchTestHelper) {
|
||||
t.Run("Should not return file info for soft deleted post", func(t *testing.T) {
|
||||
post, err := th.createPost(th.User.Id, th.ChannelBasic.Id, "deletedmessage", "", model.PostTypeDefault, 0, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = th.createFileInfo(th.User.Id, post.Id, post.ChannelId, "deletedmessage", "deletedmessage", "jpg", "image/jpeg", 0, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = th.Store.FileInfo().DeleteForPost(th.Context, post.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
params := &model.SearchParams{Terms: "deletedmessage"}
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 0)
|
||||
})
|
||||
|
||||
t.Run("Should not return file info for hard deleted post", func(t *testing.T) {
|
||||
post, err := th.createPost(th.User.Id, th.ChannelBasic.Id, "deletedmessage", "", model.PostTypeDefault, 0, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = th.createFileInfo(th.User.Id, post.Id, post.ChannelId, "deletedmessage", "deletedmessage", "jpg", "image/jpeg", 0, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = th.Store.FileInfo().PermanentDeleteForPost(th.Context, post.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
params := &model.SearchParams{Terms: "deletedmessage"}
|
||||
results, err := th.Store.FileInfo().Search(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, results.FileInfos, 0)
|
||||
})
|
||||
}
|
||||
|
||||
func testFileInfoSearchNoResultForPostlessFileInfos(t *testing.T, th *SearchTestHelper) {
|
||||
_, err := th.createFileInfo(th.User.Id, "", th.ChannelBasic.Id, "message test@test.com", "message test@test.com", "jpg", "image/jpeg", 0, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -275,6 +275,11 @@ var searchPostStoreTests = []searchTest{
|
||||
Fn: testSearchAcrossTeams,
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be removed from search index when deleted",
|
||||
Fn: testSearchPostDeleted,
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
}
|
||||
|
||||
func TestSearchPostStore(t *testing.T, s store.Store, testEngine *SearchTestEngine) {
|
||||
@@ -1955,3 +1960,31 @@ func testSearchAcrossTeams(t *testing.T, th *SearchTestHelper) {
|
||||
|
||||
require.Len(t, results.Posts, 2)
|
||||
}
|
||||
|
||||
func testSearchPostDeleted(t *testing.T, th *SearchTestHelper) {
|
||||
t.Run("Search for soft deleted post", func(t *testing.T) {
|
||||
p1, err := th.createPost(th.User.Id, th.ChannelBasic.Id, "message to delete", "", model.PostTypeDefault, 0, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = th.Store.Post().Delete(th.Context, p1.Id, p1.UpdateAt, th.User.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
params := &model.SearchParams{Terms: "message to delete"}
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results.Posts, 0)
|
||||
})
|
||||
|
||||
t.Run("Search for hard deleted post", func(t *testing.T) {
|
||||
p2, err := th.createPost(th.User.Id, th.ChannelBasic.Id, "message to delete", "", model.PostTypeDefault, 0, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = th.Store.Post().PermanentDelete(th.Context, p2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
params := &model.SearchParams{Terms: "message to delete"}
|
||||
results, err := th.Store.Post().SearchPostsForUser(th.Context, []*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, results.Posts, 0)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user