Adding is_pinned attribute to post and direct_post objects when doing bulk import (#19487)
* refactor: added is_pinned attribute to post and direct_post objects when doing bulk import * fix: handling IsPinned nil value in post and direct_post objects import * refactor: added pinned post tests for post and direct_post objects import * refactor: TestImportimportMultiplePostLines code enhancements + added pinned post tests in TestImportImportDirectPost * fix: test message text * fix: typo Post => DirectPost * fix: typo Post => DirectPost * refactor: remove redundant test * refactor: test enhancements * refactor: remove print statements. * refactor: using require instead of assert Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9521797b15
Коммит
3f5eb5f6f7
@@ -1407,6 +1407,9 @@ func (a *App) importMultiplePostLines(c *request.Context, lines []LineImportWork
|
|||||||
if line.Post.Props != nil {
|
if line.Post.Props != nil {
|
||||||
post.Props = *line.Post.Props
|
post.Props = *line.Post.Props
|
||||||
}
|
}
|
||||||
|
if line.Post.IsPinned != nil {
|
||||||
|
post.IsPinned = *line.Post.IsPinned
|
||||||
|
}
|
||||||
|
|
||||||
fileIDs := a.uploadAttachments(c, line.Post.Attachments, post, team.Id)
|
fileIDs := a.uploadAttachments(c, line.Post.Attachments, post, team.Id)
|
||||||
for _, fileID := range post.FileIds {
|
for _, fileID := range post.FileIds {
|
||||||
@@ -1715,6 +1718,9 @@ func (a *App) importMultipleDirectPostLines(c *request.Context, lines []LineImpo
|
|||||||
if line.DirectPost.Props != nil {
|
if line.DirectPost.Props != nil {
|
||||||
post.Props = *line.DirectPost.Props
|
post.Props = *line.DirectPost.Props
|
||||||
}
|
}
|
||||||
|
if line.DirectPost.IsPinned != nil {
|
||||||
|
post.IsPinned = *line.DirectPost.IsPinned
|
||||||
|
}
|
||||||
|
|
||||||
fileIDs := a.uploadAttachments(c, line.DirectPost.Attachments, post, "noteam")
|
fileIDs := a.uploadAttachments(c, line.DirectPost.Attachments, post, "noteam")
|
||||||
for _, fileID := range post.FileIds {
|
for _, fileID := range post.FileIds {
|
||||||
|
|||||||
@@ -2501,9 +2501,34 @@ func TestImportimportMultiplePostLines(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, 0, errLine)
|
assert.Equal(t, 0, errLine)
|
||||||
|
|
||||||
|
// Create a pinned message.
|
||||||
|
data = LineImportWorkerData{
|
||||||
|
LineImportData{
|
||||||
|
Post: &PostImportData{
|
||||||
|
Team: &teamName,
|
||||||
|
Channel: &channelName,
|
||||||
|
User: &user2.Username,
|
||||||
|
Message: ptrStr("Pinned Message"),
|
||||||
|
CreateAt: ptrInt64(model.GetMillis()),
|
||||||
|
IsPinned: ptrBool(true),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
1,
|
||||||
|
}
|
||||||
|
errLine, err = th.App.importMultiplePostLines(th.Context, []LineImportWorkerData{data}, false)
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.Equal(t, 0, errLine)
|
||||||
|
|
||||||
|
resultPosts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, *data.Post.CreateAt)
|
||||||
|
require.NoError(t, nErr, "Expected success.")
|
||||||
|
// Should be one post only created at this time.
|
||||||
|
require.Equal(t, 1, len(resultPosts))
|
||||||
|
resultPost := resultPosts[0]
|
||||||
|
require.True(t, resultPost.IsPinned, "This post should be pinned.")
|
||||||
|
|
||||||
// Posts should be added to the right team
|
// Posts should be added to the right team
|
||||||
AssertAllPostsCount(t, th.App, initialPostCountForTeam2, 1, team2.Id)
|
AssertAllPostsCount(t, th.App, initialPostCountForTeam2, 1, team2.Id)
|
||||||
AssertAllPostsCount(t, th.App, initialPostCount, 14, team.Id)
|
AssertAllPostsCount(t, th.App, initialPostCount, 15, team.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImportImportPost(t *testing.T) {
|
func TestImportImportPost(t *testing.T) {
|
||||||
@@ -3561,6 +3586,37 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||||||
assert.Equal(t, post.UserId, th.BasicUser.Id)
|
assert.Equal(t, post.UserId, th.BasicUser.Id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Test with IsPinned", func(t *testing.T) {
|
||||||
|
pinnedValue := true
|
||||||
|
creationTime := model.GetMillis()
|
||||||
|
data := LineImportWorkerData{
|
||||||
|
LineImportData{
|
||||||
|
DirectPost: &DirectPostImportData{
|
||||||
|
ChannelMembers: &[]string{
|
||||||
|
th.BasicUser.Username,
|
||||||
|
th.BasicUser2.Username,
|
||||||
|
},
|
||||||
|
User: ptrStr(th.BasicUser.Username),
|
||||||
|
Message: ptrStr("Message with EditAt"),
|
||||||
|
CreateAt: &creationTime,
|
||||||
|
IsPinned: &pinnedValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
1,
|
||||||
|
}
|
||||||
|
errLine, err := th.App.importMultipleDirectPostLines(th.Context, []LineImportWorkerData{data}, false)
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.Equal(t, 0, errLine)
|
||||||
|
AssertAllPostsCount(t, th.App, initialPostCount, 8, "")
|
||||||
|
|
||||||
|
posts, nErr := th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.DirectPost.CreateAt)
|
||||||
|
require.NoError(t, nErr)
|
||||||
|
require.Len(t, posts, 1)
|
||||||
|
|
||||||
|
post := posts[0]
|
||||||
|
require.True(t, post.IsPinned)
|
||||||
|
})
|
||||||
|
|
||||||
// ------------------ Group Channel -------------------------
|
// ------------------ Group Channel -------------------------
|
||||||
|
|
||||||
// Create the GROUP channel.
|
// Create the GROUP channel.
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ type PostImportData struct {
|
|||||||
Reactions *[]ReactionImportData `json:"reactions,omitempty"`
|
Reactions *[]ReactionImportData `json:"reactions,omitempty"`
|
||||||
Replies *[]ReplyImportData `json:"replies,omitempty"`
|
Replies *[]ReplyImportData `json:"replies,omitempty"`
|
||||||
Attachments *[]AttachmentImportData `json:"attachments,omitempty"`
|
Attachments *[]AttachmentImportData `json:"attachments,omitempty"`
|
||||||
|
IsPinned *bool `json:"is_pinned,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DirectChannelImportData struct {
|
type DirectChannelImportData struct {
|
||||||
@@ -172,6 +173,7 @@ type DirectPostImportData struct {
|
|||||||
Reactions *[]ReactionImportData `json:"reactions"`
|
Reactions *[]ReactionImportData `json:"reactions"`
|
||||||
Replies *[]ReplyImportData `json:"replies"`
|
Replies *[]ReplyImportData `json:"replies"`
|
||||||
Attachments *[]AttachmentImportData `json:"attachments"`
|
Attachments *[]AttachmentImportData `json:"attachments"`
|
||||||
|
IsPinned *bool `json:"is_pinned,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SchemeImportData struct {
|
type SchemeImportData struct {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user