MM-9747: Small fixes for attachments import (#9225)
* MM-9747: Small fixes for attachments import * Adding unit test RootId check in replies
Этот коммит содержится в:
коммит произвёл
Carlos Tadeu Panato Junior
родитель
7475cd260a
Коммит
5fbec91c35
@@ -285,6 +285,7 @@ func getFilePreview(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
c.Err.StatusCode = http.StatusNotFound
|
c.Err.StatusCode = http.StatusNotFound
|
||||||
|
return
|
||||||
}
|
}
|
||||||
defer fileReader.Close()
|
defer fileReader.Close()
|
||||||
|
|
||||||
|
|||||||
@@ -763,7 +763,7 @@ func (a *App) ImportReply(data *ReplyImportData, post *model.Post, teamId string
|
|||||||
|
|
||||||
var reply *model.Post
|
var reply *model.Post
|
||||||
for _, r := range replies {
|
for _, r := range replies {
|
||||||
if r.Message == *data.Message {
|
if r.Message == *data.Message && r.RootId == post.Id {
|
||||||
reply = r
|
reply = r
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -784,7 +784,7 @@ func (a *App) ImportReply(data *ReplyImportData, post *model.Post, teamId string
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
reply.FileIds = fileIds
|
reply.FileIds = append(reply.FileIds, fileIds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if reply.Id == "" {
|
if reply.Id == "" {
|
||||||
@@ -820,6 +820,8 @@ func (a *App) ImportAttachment(data *AttachmentImportData, post *model.Post, tea
|
|||||||
return nil, fileUploadError
|
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()))
|
mlog.Info(fmt.Sprintf("uploading file with name %s", file.Name()))
|
||||||
return fileInfo, nil
|
return fileInfo, nil
|
||||||
}
|
}
|
||||||
@@ -889,7 +891,7 @@ func (a *App) ImportPost(data *PostImportData, dryRun bool) *model.AppError {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
post.FileIds = fileIds
|
post.FileIds = append(post.FileIds, fileIds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if post.Id == "" {
|
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) {
|
func TestImportImportDirectChannel(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user