Commit 5fbec91c authored by Jesús Espino's avatar Jesús Espino Committed by Carlos Tadeu Panato Junior

MM-9747: Small fixes for attachments import (#9225)

* MM-9747: Small fixes for attachments import

* Adding unit test RootId check in replies
parent 7475cd26
......@@ -285,6 +285,7 @@ func getFilePreview(c *Context, w http.ResponseWriter, r *http.Request) {
if err != nil {
c.Err = err
c.Err.StatusCode = http.StatusNotFound
return
}
defer fileReader.Close()
......
......@@ -763,7 +763,7 @@ func (a *App) ImportReply(data *ReplyImportData, post *model.Post, teamId string
var reply *model.Post
for _, r := range replies {
if r.Message == *data.Message {
if r.Message == *data.Message && r.RootId == post.Id {
reply = r
break
}
......@@ -784,7 +784,7 @@ func (a *App) ImportReply(data *ReplyImportData, post *model.Post, teamId string
if err != nil {
return err
}
reply.FileIds = fileIds
reply.FileIds = append(reply.FileIds, fileIds...)
}
if reply.Id == "" {
......@@ -820,6 +820,8 @@ func (a *App) ImportAttachment(data *AttachmentImportData, post *model.Post, tea
return nil, fileUploadError
}
a.HandleImages([]string{fileInfo.PreviewPath}, []string{fileInfo.ThumbnailPath}, [][]byte{buf.Bytes()})
mlog.Info(fmt.Sprintf("uploading file with name %s", file.Name()))
return fileInfo, nil
}
......@@ -889,7 +891,7 @@ func (a *App) ImportPost(data *PostImportData, dryRun bool) *model.AppError {
if err != nil {
return err
}
post.FileIds = fileIds
post.FileIds = append(post.FileIds, fileIds...)
}
if post.Id == "" {
......
......@@ -1700,6 +1700,60 @@ func TestImportImportPost(t *testing.T) {
}
}
}
// Update post with replies.
data = &PostImportData{
Team: &teamName,
Channel: &channelName,
User: &user2.Username,
Message: ptrStr("Message with reply"),
CreateAt: &replyPostTime,
Replies: &[]ReplyImportData{{
User: &username,
Message: ptrStr("Message reply"),
CreateAt: &replyTime,
}},
}
if err := th.App.ImportPost(data, false); err != nil {
t.Fatalf("Expected success.")
}
AssertAllPostsCount(t, th.App, initialPostCount, 8, team.Id)
// Create new post with replies based on the previous one.
data = &PostImportData{
Team: &teamName,
Channel: &channelName,
User: &user2.Username,
Message: ptrStr("Message with reply 2"),
CreateAt: &replyPostTime,
Replies: &[]ReplyImportData{{
User: &username,
Message: ptrStr("Message reply"),
CreateAt: &replyTime,
}},
}
if err := th.App.ImportPost(data, false); err != nil {
t.Fatalf("Expected success.")
}
AssertAllPostsCount(t, th.App, initialPostCount, 10, team.Id)
// Create new reply for existing post with replies.
data = &PostImportData{
Team: &teamName,
Channel: &channelName,
User: &user2.Username,
Message: ptrStr("Message with reply"),
CreateAt: &replyPostTime,
Replies: &[]ReplyImportData{{
User: &username,
Message: ptrStr("Message reply 2"),
CreateAt: &replyTime,
}},
}
if err := th.App.ImportPost(data, false); err != nil {
t.Fatalf("Expected success.")
}
AssertAllPostsCount(t, th.App, initialPostCount, 11, team.Id)
}
func TestImportImportDirectChannel(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment