Bulk import/export supports direct messages from a user to themselves (#13200)
* Test added to check support for import of messages sent to your own DM channel * Support for single member direct channel messages and posts Now bulk import is able to export/import the self direct channel and the posts inside * Improve how the copy of channel members for DM and DM posts * Improved the tests for the export self-channels
Этот коммит содержится в:
коммит произвёл
Saturnino Abril
родитель
8cafd11162
Коммит
8347f3e1fa
@@ -532,12 +532,6 @@ func (a *App) ExportAllDirectChannels(writer io.Writer) *model.AppError {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// There's no import support for single member channels yet.
|
|
||||||
if len(*channel.Members) == 1 {
|
|
||||||
mlog.Debug("Bulk export for direct channels containing a single member is not supported.")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
channelLine := ImportLineFromDirectChannel(channel)
|
channelLine := ImportLineFromDirectChannel(channel)
|
||||||
if err := a.ExportWriteLine(writer, channelLine); err != nil {
|
if err := a.ExportWriteLine(writer, channelLine); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -568,12 +562,6 @@ func (a *App) ExportAllDirectPosts(writer io.Writer) *model.AppError {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// There's no import support for single member channels yet.
|
|
||||||
if len(*post.ChannelMembers) == 1 {
|
|
||||||
mlog.Debug("Bulk export for posts containing a single member is not supported.")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do the Replies.
|
// Do the Replies.
|
||||||
replies, err := a.buildPostReplies(post.Id)
|
replies, err := a.buildPostReplies(post.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -39,11 +39,15 @@ func ImportLineFromChannel(channel *model.ChannelForExport) *LineImportData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ImportLineFromDirectChannel(channel *model.DirectChannelForExport) *LineImportData {
|
func ImportLineFromDirectChannel(channel *model.DirectChannelForExport) *LineImportData {
|
||||||
|
channelMembers := *channel.Members
|
||||||
|
if len(channelMembers) == 1 {
|
||||||
|
channelMembers = []string{channelMembers[0], channelMembers[0]}
|
||||||
|
}
|
||||||
return &LineImportData{
|
return &LineImportData{
|
||||||
Type: "direct_channel",
|
Type: "direct_channel",
|
||||||
DirectChannel: &DirectChannelImportData{
|
DirectChannel: &DirectChannelImportData{
|
||||||
Header: &channel.Header,
|
Header: &channel.Header,
|
||||||
Members: channel.Members,
|
Members: &channelMembers,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,10 +162,14 @@ func ImportLineForPost(post *model.PostForExport) *LineImportData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ImportLineForDirectPost(post *model.DirectPostForExport) *LineImportData {
|
func ImportLineForDirectPost(post *model.DirectPostForExport) *LineImportData {
|
||||||
|
channelMembers := *post.ChannelMembers
|
||||||
|
if len(channelMembers) == 1 {
|
||||||
|
channelMembers = []string{channelMembers[0], channelMembers[0]}
|
||||||
|
}
|
||||||
return &LineImportData{
|
return &LineImportData{
|
||||||
Type: "direct_post",
|
Type: "direct_post",
|
||||||
DirectPost: &DirectPostImportData{
|
DirectPost: &DirectPostImportData{
|
||||||
ChannelMembers: post.ChannelMembers,
|
ChannelMembers: &channelMembers,
|
||||||
User: &post.User,
|
User: &post.User,
|
||||||
Message: &post.Message,
|
Message: &post.Message,
|
||||||
CreateAt: &post.CreateAt,
|
CreateAt: &post.CreateAt,
|
||||||
|
|||||||
@@ -284,10 +284,11 @@ func TestExportDMChannelToSelf(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, 0, i)
|
assert.Equal(t, 0, i)
|
||||||
|
|
||||||
// Ensure no channels were imported
|
|
||||||
channels, err = th2.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
channels, err = th2.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, 0, len(channels))
|
assert.Equal(t, 1, len(channels))
|
||||||
|
assert.Equal(t, 1, len((*channels[0].Members)))
|
||||||
|
assert.Equal(t, th1.BasicUser.Username, (*channels[0].Members)[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExportGMChannel(t *testing.T) {
|
func TestExportGMChannel(t *testing.T) {
|
||||||
@@ -478,5 +479,7 @@ func TestExportDMPostWithSelf(t *testing.T) {
|
|||||||
|
|
||||||
posts, err = th2.App.Srv.Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
posts, err = th2.App.Srv.Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, 0, len(posts))
|
assert.Equal(t, 1, len(posts))
|
||||||
|
assert.Equal(t, 1, len((*posts[0].ChannelMembers)))
|
||||||
|
assert.Equal(t, th1.BasicUser.Username, (*posts[0].ChannelMembers)[0])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,8 +163,10 @@ func TestImportBulkImport(t *testing.T) {
|
|||||||
{"type": "user", "user": {"username": "` + username3 + `", "email": "` + username3 + `@example.com", "teams": [{"name": "` + teamName + `", "channels": [{"name": "` + channelName + `"}], "delete_at": 123456789016}]}}
|
{"type": "user", "user": {"username": "` + username3 + `", "email": "` + username3 + `@example.com", "teams": [{"name": "` + teamName + `", "channels": [{"name": "` + channelName + `"}], "delete_at": 123456789016}]}}
|
||||||
{"type": "post", "post": {"team": "` + teamName + `", "channel": "` + channelName + `", "user": "` + username + `", "message": "Hello World", "create_at": 123456789012, "attachments":[{"path": "` + testImage + `"}]}}
|
{"type": "post", "post": {"team": "` + teamName + `", "channel": "` + channelName + `", "user": "` + username + `", "message": "Hello World", "create_at": 123456789012, "attachments":[{"path": "` + testImage + `"}]}}
|
||||||
{"type": "post", "post": {"team": "` + teamName + `", "channel": "` + channelName + `", "user": "` + username3 + `", "message": "Hey Everyone!", "create_at": 123456789013, "attachments":[{"path": "` + testImage + `"}]}}
|
{"type": "post", "post": {"team": "` + teamName + `", "channel": "` + channelName + `", "user": "` + username3 + `", "message": "Hey Everyone!", "create_at": 123456789013, "attachments":[{"path": "` + testImage + `"}]}}
|
||||||
|
{"type": "direct_channel", "direct_channel": {"members": ["` + username + `", "` + username + `"]}}
|
||||||
{"type": "direct_channel", "direct_channel": {"members": ["` + username + `", "` + username2 + `"]}}
|
{"type": "direct_channel", "direct_channel": {"members": ["` + username + `", "` + username2 + `"]}}
|
||||||
{"type": "direct_channel", "direct_channel": {"members": ["` + username + `", "` + username2 + `", "` + username3 + `"]}}
|
{"type": "direct_channel", "direct_channel": {"members": ["` + username + `", "` + username2 + `", "` + username3 + `"]}}
|
||||||
|
{"type": "direct_post", "direct_post": {"channel_members": ["` + username + `", "` + username + `"], "user": "` + username + `", "message": "Hello Direct Channel to myself", "create_at": 123456789014}}
|
||||||
{"type": "direct_post", "direct_post": {"channel_members": ["` + username + `", "` + username2 + `"], "user": "` + username + `", "message": "Hello Direct Channel", "create_at": 123456789014}}
|
{"type": "direct_post", "direct_post": {"channel_members": ["` + username + `", "` + username2 + `"], "user": "` + username + `", "message": "Hello Direct Channel", "create_at": 123456789014}}
|
||||||
{"type": "direct_post", "direct_post": {"channel_members": ["` + username + `", "` + username2 + `", "` + username3 + `"], "user": "` + username + `", "message": "Hello Group Channel", "create_at": 123456789015}}
|
{"type": "direct_post", "direct_post": {"channel_members": ["` + username + `", "` + username2 + `", "` + username3 + `"], "user": "` + username + `", "message": "Hello Group Channel", "create_at": 123456789015}}
|
||||||
{"type": "emoji", "emoji": {"name": "` + emojiName + `", "image": "` + testImage + `"}}`
|
{"type": "emoji", "emoji": {"name": "` + emojiName + `", "image": "` + testImage + `"}}`
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user