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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
62f616dfbf
Коммит
28cb8d0441
@@ -6192,7 +6192,7 @@ func (s *OpenTracingLayerPostStore) Get(ctx context.Context, id string, opts mod
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerPostStore) GetDirectPostParentsForExportAfter(limit int, afterID string) ([]*model.DirectPostForExport, error) {
|
||||
func (s *OpenTracingLayerPostStore) GetDirectPostParentsForExportAfter(limit int, afterID string, includeArchivedChannels bool) ([]*model.DirectPostForExport, error) {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.GetDirectPostParentsForExportAfter")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
@@ -6201,7 +6201,7 @@ func (s *OpenTracingLayerPostStore) GetDirectPostParentsForExportAfter(limit int
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
result, err := s.PostStore.GetDirectPostParentsForExportAfter(limit, afterID)
|
||||
result, err := s.PostStore.GetDirectPostParentsForExportAfter(limit, afterID, includeArchivedChannels)
|
||||
if err != nil {
|
||||
span.LogFields(spanlog.Error(err))
|
||||
ext.Error.Set(span, true)
|
||||
|
||||
@@ -7028,11 +7028,11 @@ func (s *RetryLayerPostStore) Get(ctx context.Context, id string, opts model.Get
|
||||
|
||||
}
|
||||
|
||||
func (s *RetryLayerPostStore) GetDirectPostParentsForExportAfter(limit int, afterID string) ([]*model.DirectPostForExport, error) {
|
||||
func (s *RetryLayerPostStore) GetDirectPostParentsForExportAfter(limit int, afterID string, includeArchivedChannels bool) ([]*model.DirectPostForExport, error) {
|
||||
|
||||
tries := 0
|
||||
for {
|
||||
result, err := s.PostStore.GetDirectPostParentsForExportAfter(limit, afterID)
|
||||
result, err := s.PostStore.GetDirectPostParentsForExportAfter(limit, afterID, includeArchivedChannels)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -2686,7 +2686,7 @@ func (s *SqlPostStore) GetRepliesForExport(rootId string) ([]*model.ReplyForExpo
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId string) ([]*model.DirectPostForExport, error) {
|
||||
func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId string, includeArchivedChannels bool) ([]*model.DirectPostForExport, error) {
|
||||
query := s.getQueryBuilder().
|
||||
Select("p.*", "Users.Username as User").
|
||||
From("Posts p").
|
||||
@@ -2696,13 +2696,17 @@ func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId str
|
||||
sq.Gt{"p.Id": afterId},
|
||||
sq.Eq{"p.RootId": ""},
|
||||
sq.Eq{"p.DeleteAt": 0},
|
||||
sq.Eq{"Channels.DeleteAt": 0},
|
||||
sq.Eq{"Users.DeleteAt": 0},
|
||||
sq.Eq{"Channels.Type": []model.ChannelType{model.ChannelTypeDirect, model.ChannelTypeGroup}},
|
||||
}).
|
||||
OrderBy("p.Id").
|
||||
Limit(uint64(limit))
|
||||
|
||||
if !includeArchivedChannels {
|
||||
query = query.Where(
|
||||
sq.Eq{"Channels.DeleteAt": 0},
|
||||
)
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "post_tosql")
|
||||
|
||||
@@ -390,7 +390,7 @@ type PostStore interface {
|
||||
GetMaxPostSize() int
|
||||
GetParentsForExportAfter(limit int, afterID string, includeArchivedChannels bool) ([]*model.PostForExport, error)
|
||||
GetRepliesForExport(parentID string) ([]*model.ReplyForExport, error)
|
||||
GetDirectPostParentsForExportAfter(limit int, afterID string) ([]*model.DirectPostForExport, error)
|
||||
GetDirectPostParentsForExportAfter(limit int, afterID string, includeArchivedChannels bool) ([]*model.DirectPostForExport, error)
|
||||
SearchPostsForUser(rctx request.CTX, paramsList []*model.SearchParams, userID, teamID string, page, perPage int) (*model.PostSearchResults, error)
|
||||
GetOldestEntityCreationTime() (int64, error)
|
||||
HasAutoResponsePostByUserSince(options model.GetPostsSinceOptions, userId string) (bool, error)
|
||||
|
||||
@@ -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{}
|
||||
|
||||
@@ -5610,10 +5610,10 @@ func (s *TimerLayerPostStore) Get(ctx context.Context, id string, opts model.Get
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerPostStore) GetDirectPostParentsForExportAfter(limit int, afterID string) ([]*model.DirectPostForExport, error) {
|
||||
func (s *TimerLayerPostStore) GetDirectPostParentsForExportAfter(limit int, afterID string, includeArchivedChannels bool) ([]*model.DirectPostForExport, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.PostStore.GetDirectPostParentsForExportAfter(limit, afterID)
|
||||
result, err := s.PostStore.GetDirectPostParentsForExportAfter(limit, afterID, includeArchivedChannels)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user