From bf4d41954a6944fc2550211eb3e2f9b7d186bba0 Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Wed, 18 Dec 2024 17:36:17 +0100 Subject: [PATCH] [MM-53245] export/import: add Props to the replies (#29531) --- server/channels/app/export_converters.go | 1 + server/channels/app/import_functions.go | 3 +++ server/channels/app/import_functions_test.go | 5 +++++ server/channels/app/imports/import_types.go | 9 +++++---- server/channels/app/imports/import_validators.go | 13 +++++++++++++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/server/channels/app/export_converters.go b/server/channels/app/export_converters.go index 6c668c8192..c9be99bb9a 100644 --- a/server/channels/app/export_converters.go +++ b/server/channels/app/export_converters.go @@ -308,6 +308,7 @@ func importReplyFromPost(post *model.ReplyForExport) *imports.ReplyImportData { EditAt: &post.EditAt, IsPinned: &post.IsPinned, FlaggedBy: &f, + Props: &post.Props, } } diff --git a/server/channels/app/import_functions.go b/server/channels/app/import_functions.go index c86bad772f..58e602bb74 100644 --- a/server/channels/app/import_functions.go +++ b/server/channels/app/import_functions.go @@ -1412,6 +1412,9 @@ func (a *App) importReplies(rctx request.CTX, data []imports.ReplyImportData, po rctx.Logger().Warn("Reply CreateAt is before parent post CreateAt, setting it to parent post CreateAt", mlog.Int("reply_create_at", reply.CreateAt), mlog.Int("parent_create_at", post.CreateAt)) reply.CreateAt = post.CreateAt } + if replyData.Props != nil { + reply.Props = *replyData.Props + } if replyData.Type != nil { reply.Type = *replyData.Type } diff --git a/server/channels/app/import_functions_test.go b/server/channels/app/import_functions_test.go index f7d6ba19a0..790df9da7a 100644 --- a/server/channels/app/import_functions_test.go +++ b/server/channels/app/import_functions_test.go @@ -2663,6 +2663,7 @@ func TestImportimportMultiplePostLines(t *testing.T) { User: &user2.Username, Message: model.NewPointer("Message reply"), CreateAt: &replyTime, + Props: &model.StringInterface{"key": "value"}, }}, }, }, @@ -2694,6 +2695,10 @@ func TestImportimportMultiplePostLines(t *testing.T) { replyBool := reply.Message != *(*data.Post.Replies)[0].Message || reply.CreateAt != *(*data.Post.Replies)[0].CreateAt || reply.UserId != user2.Id require.False(t, replyBool, "Post properties not as expected") + v := reply.GetProp("key") + require.NotNil(t, v, "Post prop should exist") + require.Equal(t, "value", v, "Post props not as expected") + require.Equal(t, post.Id, reply.RootId, "Unexpected reply RootId") }) diff --git a/server/channels/app/imports/import_types.go b/server/channels/app/imports/import_types.go index 9e48f04eb3..6acddd7acc 100644 --- a/server/channels/app/imports/import_types.go +++ b/server/channels/app/imports/import_types.go @@ -183,10 +183,11 @@ type ReactionImportData struct { type ReplyImportData struct { User *string `json:"user"` - Type *string `json:"type"` - Message *string `json:"message"` - CreateAt *int64 `json:"create_at"` - EditAt *int64 `json:"edit_at"` + Type *string `json:"type"` + Message *string `json:"message"` + Props *model.StringInterface `json:"props"` + CreateAt *int64 `json:"create_at"` + EditAt *int64 `json:"edit_at"` FlaggedBy *[]string `json:"flagged_by,omitempty"` Reactions *[]ReactionImportData `json:"reactions,omitempty"` diff --git a/server/channels/app/imports/import_validators.go b/server/channels/app/imports/import_validators.go index 90a24efc94..e758da3148 100644 --- a/server/channels/app/imports/import_validators.go +++ b/server/channels/app/imports/import_validators.go @@ -474,6 +474,19 @@ func ValidateReplyImportData(data *ReplyImportData, parentCreateAt int64, maxPos mlog.Warn("Reply CreateAt is before parent post CreateAt", mlog.Int("reply_create_at", *data.CreateAt), mlog.Int("parent_create_at", parentCreateAt)) } + if data.Props != nil && utf8.RuneCountInString(model.StringInterfaceToJSON(*data.Props)) > model.PostPropsMaxRunes { + return model.NewAppError("BulkImport", "app.import.validate_post_import_data.props_too_large.error", nil, "", http.StatusBadRequest) + } + + if data.Reactions != nil { + for _, reaction := range *data.Reactions { + reaction := reaction + if err := ValidateReactionImportData(&reaction, *data.CreateAt); err != nil { + return err + } + } + } + return nil }