MM-43878: don't err when reply createAt before parent createAt (#20292)
Summary In a bulk import, if the createAt of a reply is older than the createAt of the parent post, then instead of erroring, we log a warning and set the createAt of the reply to that of the parent post. I checked the exporting logic, there doesn't appear to be away for the reply createAt to be older than the parent createAt, as a side-effect of the exporting logic. Ticket Link https://mattermost.atlassian.net/browse/MM-43878
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
84dbf894ea
Коммит
c5e6d0e1ba
@@ -1118,6 +1118,10 @@ func (a *App) importReplies(c *request.Context, data []ReplyImportData, post *mo
|
||||
reply.RootId = post.Id
|
||||
reply.Message = *replyData.Message
|
||||
reply.CreateAt = *replyData.CreateAt
|
||||
if reply.CreateAt < post.CreateAt {
|
||||
mlog.Warn("Reply CreateAt is before parent post CreateAt, setting it to parent post CreateAt", mlog.Int64("reply_create_at", reply.CreateAt), mlog.Int64("parent_create_at", post.CreateAt))
|
||||
reply.CreateAt = post.CreateAt
|
||||
}
|
||||
if replyData.Type != nil {
|
||||
reply.Type = *replyData.Type
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
"github.com/mattermost/mattermost-server/v6/testlib"
|
||||
"github.com/mattermost/mattermost-server/v6/utils/fileutils"
|
||||
)
|
||||
|
||||
@@ -3091,6 +3093,46 @@ func TestImportImportPost(t *testing.T) {
|
||||
postBool := post.Message != *data.Post.Message || post.CreateAt != *data.Post.CreateAt || post.UserId != user.Id || post.EditAt != *data.Post.EditAt
|
||||
require.False(t, postBool, "Post properties not as expected")
|
||||
})
|
||||
|
||||
t.Run("Reply CreateAt before parent post CreateAt", func(t *testing.T) {
|
||||
now := model.GetMillis()
|
||||
before := now - 10
|
||||
data := LineImportWorkerData{
|
||||
LineImportData{
|
||||
Post: &PostImportData{
|
||||
Team: &teamName,
|
||||
Channel: &channelName,
|
||||
User: &user2.Username,
|
||||
Message: ptrStr("Message with reply"),
|
||||
CreateAt: &now,
|
||||
Replies: &[]ReplyImportData{{
|
||||
User: &username,
|
||||
Message: ptrStr("Message reply 2"),
|
||||
CreateAt: &before,
|
||||
}},
|
||||
},
|
||||
},
|
||||
1,
|
||||
}
|
||||
|
||||
errLine, err := th.App.importMultiplePostLines(th.Context, []LineImportWorkerData{data}, false)
|
||||
require.Nil(t, err, "Expected success.")
|
||||
require.Equal(t, 0, errLine)
|
||||
|
||||
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, now)
|
||||
require.NoError(t, nErr)
|
||||
require.Len(t, posts, 2, "Unexpected number of posts found.")
|
||||
testlib.AssertLog(t, th.LogBuffer, mlog.LvlWarn.Name, "Reply CreateAt is before parent post CreateAt, setting it to parent post CreateAt")
|
||||
|
||||
rootPost := posts[0]
|
||||
replyPost := posts[1]
|
||||
if rootPost.RootId != "" {
|
||||
replyPost = posts[0]
|
||||
rootPost = posts[1]
|
||||
}
|
||||
require.Equal(t, rootPost.Id, replyPost.RootId)
|
||||
require.Equal(t, now, replyPost.CreateAt)
|
||||
})
|
||||
}
|
||||
|
||||
func TestImportImportDirectChannel(t *testing.T) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func validateSchemeImportData(data *SchemeImportData) *model.AppError {
|
||||
@@ -412,7 +413,7 @@ func validateReplyImportData(data *ReplyImportData, parentCreateAt int64, maxPos
|
||||
} else if *data.CreateAt == 0 {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_reply_import_data.create_at_zero.error", nil, "", http.StatusBadRequest)
|
||||
} else if *data.CreateAt < parentCreateAt {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_reply_import_data.create_at_before_parent.error", nil, "", http.StatusBadRequest)
|
||||
mlog.Warn("Reply CreateAt is before parent post CreateAt", mlog.Int64("reply_create_at", *data.CreateAt), mlog.Int64("parent_create_at", parentCreateAt))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -887,14 +887,6 @@ func TestImportValidateReplyImportData(t *testing.T) {
|
||||
}
|
||||
err = validateReplyImportData(&data, parentCreateAt, maxPostSize)
|
||||
require.NotNil(t, err, "Should have failed due to 0 create-at value.")
|
||||
|
||||
data = ReplyImportData{
|
||||
User: ptrStr("username"),
|
||||
Message: ptrStr("message"),
|
||||
CreateAt: ptrInt64(parentCreateAt - 100),
|
||||
}
|
||||
err = validateReplyImportData(&data, parentCreateAt, maxPostSize)
|
||||
require.NotNil(t, err, "Should have failed due parent with newer create-at value.")
|
||||
}
|
||||
|
||||
func TestImportValidatePostImportData(t *testing.T) {
|
||||
|
||||
@@ -5203,10 +5203,6 @@
|
||||
"id": "app.import.validate_reaction_import_data.user_missing.error",
|
||||
"translation": "Missing required Reaction property: User."
|
||||
},
|
||||
{
|
||||
"id": "app.import.validate_reply_import_data.create_at_before_parent.error",
|
||||
"translation": "Reply CreateAt property must be greater than the parent post CreateAt."
|
||||
},
|
||||
{
|
||||
"id": "app.import.validate_reply_import_data.create_at_missing.error",
|
||||
"translation": "Missing required Reply property: create_at."
|
||||
|
||||
Ссылка в новой задаче
Block a user