diff options
author | Jesús Espino <jespinog@gmail.com> | 2018-08-08 12:10:05 +0200 |
---|---|---|
committer | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2018-08-08 12:10:05 +0200 |
commit | 5fbec91c35d7ea5d9b920b26a01fc21da55bb08e (patch) | |
tree | 533f7dfb17e151cd5fc76d3ed8c30d19b8475723 | |
parent | 7475cd260a3aba46e0b7524656b42209c1779c22 (diff) | |
download | chat-5fbec91c35d7ea5d9b920b26a01fc21da55bb08e.tar.gz chat-5fbec91c35d7ea5d9b920b26a01fc21da55bb08e.tar.bz2 chat-5fbec91c35d7ea5d9b920b26a01fc21da55bb08e.zip |
MM-9747: Small fixes for attachments import (#9225)
* MM-9747: Small fixes for attachments import
* Adding unit test RootId check in replies
-rw-r--r-- | api4/file.go | 1 | ||||
-rw-r--r-- | app/import_functions.go | 8 | ||||
-rw-r--r-- | app/import_functions_test.go | 54 |
3 files changed, 60 insertions, 3 deletions
diff --git a/api4/file.go b/api4/file.go index f73a54fb4..cfb72cdcb 100644 --- a/api4/file.go +++ b/api4/file.go @@ -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() diff --git a/app/import_functions.go b/app/import_functions.go index f4ff5607f..e370099d9 100644 --- a/app/import_functions.go +++ b/app/import_functions.go @@ -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 == "" { diff --git a/app/import_functions_test.go b/app/import_functions_test.go index e0859af45..fd8ae462e 100644 --- a/app/import_functions_test.go +++ b/app/import_functions_test.go @@ -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) { |