MM-56579: Include deactivated users from DM posts (#25985)

There were 2 separate bugs here:
1. We were not including deactivated users while fetching posts from
DM channels.
2. We were not respecting the includeArchivedChannels flag while
fetching DM channels.

We fix both of these issues here.

```release-note
Include posts from deactivated users in DM channel export. Also
respect the --include-archived-channels flag for DM channels.
```

https://mattermost.atlassian.net/browse/MM-56579

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Agniva De Sarker
2024-02-14 20:59:46 +05:30
коммит произвёл GitHub
родитель 62f616dfbf
Коммит 28cb8d0441
9 изменённых файлов: 44 добавлений и 43 удалений

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

@@ -141,25 +141,25 @@ func (_m *PostStore) Get(ctx context.Context, id string, opts model.GetPostsOpti
return r0, r1
}
// GetDirectPostParentsForExportAfter provides a mock function with given fields: limit, afterID
func (_m *PostStore) GetDirectPostParentsForExportAfter(limit int, afterID string) ([]*model.DirectPostForExport, error) {
ret := _m.Called(limit, afterID)
// GetDirectPostParentsForExportAfter provides a mock function with given fields: limit, afterID, includeArchivedChannels
func (_m *PostStore) GetDirectPostParentsForExportAfter(limit int, afterID string, includeArchivedChannels bool) ([]*model.DirectPostForExport, error) {
ret := _m.Called(limit, afterID, includeArchivedChannels)
var r0 []*model.DirectPostForExport
var r1 error
if rf, ok := ret.Get(0).(func(int, string) ([]*model.DirectPostForExport, error)); ok {
return rf(limit, afterID)
if rf, ok := ret.Get(0).(func(int, string, bool) ([]*model.DirectPostForExport, error)); ok {
return rf(limit, afterID, includeArchivedChannels)
}
if rf, ok := ret.Get(0).(func(int, string) []*model.DirectPostForExport); ok {
r0 = rf(limit, afterID)
if rf, ok := ret.Get(0).(func(int, string, bool) []*model.DirectPostForExport); ok {
r0 = rf(limit, afterID, includeArchivedChannels)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.DirectPostForExport)
}
}
if rf, ok := ret.Get(1).(func(int, string) error); ok {
r1 = rf(limit, afterID)
if rf, ok := ret.Get(1).(func(int, string, bool) error); ok {
r1 = rf(limit, afterID, includeArchivedChannels)
} else {
r1 = ret.Error(1)
}

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

@@ -4457,7 +4457,7 @@ func testPostStoreGetDirectPostParentsForExportAfter(t *testing.T, rctx request.
p1, nErr = ss.Post().Save(p1)
require.NoError(t, nErr)
r1, nErr := ss.Post().GetDirectPostParentsForExportAfter(10000, strings.Repeat("0", 26))
r1, nErr := ss.Post().GetDirectPostParentsForExportAfter(10000, strings.Repeat("0", 26), false)
assert.NoError(t, nErr)
assert.Equal(t, p1.Message, r1[0].Message)
@@ -4514,20 +4514,17 @@ func testPostStoreGetDirectPostParentsForExportAfterDeleted(t *testing.T, rctx r
p1.UserId = u1.Id
p1.Message = NewTestId()
p1.CreateAt = 1000
p1, nErr = ss.Post().Save(p1)
_, nErr = ss.Post().Save(p1)
require.NoError(t, nErr)
o1a := p1.Clone()
o1a.DeleteAt = 1
o1a.Message = p1.Message + "BBBBBBBBBB"
_, nErr = ss.Post().Update(rctx, o1a, p1)
require.NoError(t, nErr)
r1, nErr := ss.Post().GetDirectPostParentsForExportAfter(10000, strings.Repeat("0", 26))
r1, nErr := ss.Post().GetDirectPostParentsForExportAfter(10000, strings.Repeat("0", 26), false)
assert.NoError(t, nErr)
assert.Equal(t, 0, len(r1))
r1, nErr = ss.Post().GetDirectPostParentsForExportAfter(10000, strings.Repeat("0", 26), true)
assert.NoError(t, nErr)
assert.Equal(t, 1, len(r1))
// Manually truncate Channels table until testlib can handle cleanups
s.GetMasterX().Exec("TRUNCATE Channels")
}
@@ -4583,7 +4580,7 @@ func testPostStoreGetDirectPostParentsForExportAfterBatched(t *testing.T, rctx r
sort.Slice(postIds, func(i, j int) bool { return postIds[i] < postIds[j] })
// Get all posts
r1, err := ss.Post().GetDirectPostParentsForExportAfter(10000, strings.Repeat("0", 26))
r1, err := ss.Post().GetDirectPostParentsForExportAfter(10000, strings.Repeat("0", 26), false)
assert.NoError(t, err)
assert.Equal(t, len(postIds), len(r1))
var exportedPostIds []string
@@ -4594,7 +4591,7 @@ func testPostStoreGetDirectPostParentsForExportAfterBatched(t *testing.T, rctx r
assert.ElementsMatch(t, postIds, exportedPostIds)
// Get 100
r1, err = ss.Post().GetDirectPostParentsForExportAfter(100, strings.Repeat("0", 26))
r1, err = ss.Post().GetDirectPostParentsForExportAfter(100, strings.Repeat("0", 26), false)
assert.NoError(t, err)
assert.Equal(t, 100, len(r1))
exportedPostIds = []string{}