mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
9304 added the attachments import to direct post (#9308)
This commit is contained in:
committed by
Carlos Tadeu Panato Junior
parent
c2676d964e
commit
7a3cf112c5
@@ -1118,6 +1118,14 @@ func (a *App) ImportDirectPost(data *DirectPostImportData, dryRun bool) *model.A
|
||||
|
||||
post.Hashtags, _ = model.ParseHashtags(post.Message)
|
||||
|
||||
if data.Attachments != nil {
|
||||
fileIds, err := a.uploadAttachments(data.Attachments, post, "noteam", dryRun)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
post.FileIds = append(post.FileIds, fileIds...)
|
||||
}
|
||||
|
||||
if post.Id == "" {
|
||||
if result := <-a.Srv.Store.Post().Save(post); result.Err != nil {
|
||||
return result.Err
|
||||
@@ -1171,6 +1179,7 @@ func (a *App) ImportDirectPost(data *DirectPostImportData, dryRun bool) *model.A
|
||||
}
|
||||
}
|
||||
|
||||
a.UpdateFileInfoWithPostId(post)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2553,3 +2553,54 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
|
||||
AssertFileIdsInPost(attachments, th, t)
|
||||
|
||||
}
|
||||
|
||||
func TestImportDirectPostWithAttachments(t *testing.T) {
|
||||
|
||||
th := Setup()
|
||||
defer th.TearDown()
|
||||
|
||||
testsDir, _ := utils.FindDir("tests")
|
||||
testImage := filepath.Join(testsDir, "test.png")
|
||||
|
||||
// Create a user.
|
||||
username := model.NewId()
|
||||
th.App.ImportUser(&UserImportData{
|
||||
Username: &username,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
user1, err := th.App.GetUserByUsername(username)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get user1 from database.")
|
||||
}
|
||||
|
||||
username2 := model.NewId()
|
||||
th.App.ImportUser(&UserImportData{
|
||||
Username: &username2,
|
||||
Email: ptrStr(model.NewId() + "@example.com"),
|
||||
}, false)
|
||||
|
||||
user2, err := th.App.GetUserByUsername(username2)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get user2 from database.")
|
||||
}
|
||||
|
||||
directImportData := &DirectPostImportData{
|
||||
ChannelMembers: &[]string{
|
||||
user1.Username,
|
||||
user2.Username,
|
||||
},
|
||||
User: &user1.Username,
|
||||
Message: ptrStr("Direct message"),
|
||||
CreateAt: ptrInt64(model.GetMillis()),
|
||||
Attachments: &[]AttachmentImportData{{Path: &testImage}},
|
||||
}
|
||||
|
||||
if err := th.App.ImportDirectPost(directImportData, false); err != nil {
|
||||
t.Fatalf("Expected success.")
|
||||
}
|
||||
|
||||
attachments := GetAttachments(user1.Id, th, t)
|
||||
assert.Equal(t, len(attachments), 1)
|
||||
assert.Contains(t, attachments[0].Path, "noteam")
|
||||
AssertFileIdsInPost(attachments, th, t)
|
||||
}
|
||||
|
||||
@@ -148,9 +148,10 @@ type DirectPostImportData struct {
|
||||
Message *string `json:"message"`
|
||||
CreateAt *int64 `json:"create_at"`
|
||||
|
||||
FlaggedBy *[]string `json:"flagged_by"`
|
||||
Reactions *[]ReactionImportData `json:"reactions"`
|
||||
Replies *[]ReplyImportData `json:"replies"`
|
||||
FlaggedBy *[]string `json:"flagged_by"`
|
||||
Reactions *[]ReactionImportData `json:"reactions"`
|
||||
Replies *[]ReplyImportData `json:"replies"`
|
||||
Attachments *[]AttachmentImportData `json:"attachments"`
|
||||
}
|
||||
|
||||
type SchemeImportData struct {
|
||||
|
||||
Reference in New Issue
Block a user