MM-13220: Fixes for bulk export problems (#9980)

* MM-13220: Fixes for bulk export problems

* fixing tests
Этот коммит содержится в:
Jesús Espino
2018-12-12 14:20:22 +01:00
коммит произвёл GitHub
родитель a7b6c71421
Коммит febc5115fd
4 изменённых файлов: 23 добавлений и 24 удалений

Просмотреть файл

@@ -220,7 +220,7 @@ func (a *App) buildUserChannelMemberships(userId string, teamId string) (*[]User
category := model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL category := model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL
preferences, err := a.GetPreferenceByCategoryForUser(userId, category) preferences, err := a.GetPreferenceByCategoryForUser(userId, category)
if err != nil { if err != nil && err.StatusCode != http.StatusNotFound {
return nil, err return nil, err
} }
@@ -243,8 +243,8 @@ func (a *App) buildUserNotifyProps(notifyProps model.StringMap) *UserNotifyProps
Desktop: getProp(model.DESKTOP_NOTIFY_PROP), Desktop: getProp(model.DESKTOP_NOTIFY_PROP),
DesktopSound: getProp(model.DESKTOP_SOUND_NOTIFY_PROP), DesktopSound: getProp(model.DESKTOP_SOUND_NOTIFY_PROP),
Email: getProp(model.EMAIL_NOTIFY_PROP), Email: getProp(model.EMAIL_NOTIFY_PROP),
Mobile: getProp(model.MOBILE_NOTIFY_PROP), Mobile: getProp(model.PUSH_NOTIFY_PROP),
MobilePushStatus: getProp(model.MOBILE_PUSH_STATUS_NOTIFY_PROP), MobilePushStatus: getProp(model.PUSH_STATUS_NOTIFY_PROP),
ChannelTrigger: getProp(model.CHANNEL_MENTIONS_NOTIFY_PROP), ChannelTrigger: getProp(model.CHANNEL_MENTIONS_NOTIFY_PROP),
CommentsTrigger: getProp(model.COMMENTS_NOTIFY_PROP), CommentsTrigger: getProp(model.COMMENTS_NOTIFY_PROP),
MentionKeys: getProp(model.MENTION_KEYS_NOTIFY_PROP), MentionKeys: getProp(model.MENTION_KEYS_NOTIFY_PROP),
@@ -330,7 +330,6 @@ func (a *App) BuildPostReactions(postId string) (*[]ReactionImportData, *model.A
var reactionsOfPost []ReactionImportData var reactionsOfPost []ReactionImportData
result := <-a.Srv.Store.Reaction().GetForPost(postId, true) result := <-a.Srv.Store.Reaction().GetForPost(postId, true)
if result.Err != nil { if result.Err != nil {
return nil, result.Err return nil, result.Err
} }
@@ -338,7 +337,12 @@ func (a *App) BuildPostReactions(postId string) (*[]ReactionImportData, *model.A
reactions := result.Data.([]*model.Reaction) reactions := result.Data.([]*model.Reaction)
for _, reaction := range reactions { for _, reaction := range reactions {
reactionsOfPost = append(reactionsOfPost, *ImportReactionFromPost(reaction)) result := <-a.Srv.Store.User().Get(reaction.UserId)
if result.Err != nil {
return nil, result.Err
}
user := result.Data.(*model.User)
reactionsOfPost = append(reactionsOfPost, *ImportReactionFromPost(user, reaction))
} }
return &reactionsOfPost, nil return &reactionsOfPost, nil

Просмотреть файл

@@ -132,9 +132,9 @@ func ImportReplyFromPost(post *model.ReplyForExport) *ReplyImportData {
} }
} }
func ImportReactionFromPost(reaction *model.Reaction) *ReactionImportData { func ImportReactionFromPost(user *model.User, reaction *model.Reaction) *ReactionImportData {
return &ReactionImportData{ return &ReactionImportData{
User: &reaction.UserId, User: &user.Username,
EmojiName: &reaction.EmojiName, EmojiName: &reaction.EmojiName,
CreateAt: &reaction.CreateAt, CreateAt: &reaction.CreateAt,
} }

Просмотреть файл

@@ -18,7 +18,7 @@ func TestReactionsOfPost(t *testing.T) {
post.HasReactions = true post.HasReactions = true
reactionObject := model.Reaction{ reactionObject := model.Reaction{
UserId: model.NewId(), UserId: th.BasicUser.Id,
PostId: post.Id, PostId: post.Id,
EmojiName: "emoji", EmojiName: "emoji",
CreateAt: model.GetMillis(), CreateAt: model.GetMillis(),
@@ -26,10 +26,7 @@ func TestReactionsOfPost(t *testing.T) {
th.App.SaveReactionForPost(&reactionObject) th.App.SaveReactionForPost(&reactionObject)
reactionsOfPost, err := th.App.BuildPostReactions(post.Id) reactionsOfPost, err := th.App.BuildPostReactions(post.Id)
require.Nil(t, err)
if err != nil {
t.Fatal("should have reactions")
}
assert.Equal(t, reactionObject.EmojiName, *(*reactionsOfPost)[0].EmojiName) assert.Equal(t, reactionObject.EmojiName, *(*reactionsOfPost)[0].EmojiName)
} }
@@ -40,14 +37,14 @@ func TestExportUserNotifyProps(t *testing.T) {
defer th.TearDown() defer th.TearDown()
userNotifyProps := model.StringMap{ userNotifyProps := model.StringMap{
model.DESKTOP_NOTIFY_PROP: model.USER_NOTIFY_ALL, model.DESKTOP_NOTIFY_PROP: model.USER_NOTIFY_ALL,
model.DESKTOP_SOUND_NOTIFY_PROP: "true", model.DESKTOP_SOUND_NOTIFY_PROP: "true",
model.EMAIL_NOTIFY_PROP: "true", model.EMAIL_NOTIFY_PROP: "true",
model.MOBILE_NOTIFY_PROP: model.USER_NOTIFY_ALL, model.PUSH_NOTIFY_PROP: model.USER_NOTIFY_ALL,
model.MOBILE_PUSH_STATUS_NOTIFY_PROP: model.STATUS_ONLINE, model.PUSH_STATUS_NOTIFY_PROP: model.STATUS_ONLINE,
model.CHANNEL_MENTIONS_NOTIFY_PROP: "true", model.CHANNEL_MENTIONS_NOTIFY_PROP: "true",
model.COMMENTS_NOTIFY_PROP: model.COMMENTS_NOTIFY_ROOT, model.COMMENTS_NOTIFY_PROP: model.COMMENTS_NOTIFY_ROOT,
model.MENTION_KEYS_NOTIFY_PROP: "valid,misc", model.MENTION_KEYS_NOTIFY_PROP: "valid,misc",
} }
exportNotifyProps := th.App.buildUserNotifyProps(userNotifyProps) exportNotifyProps := th.App.buildUserNotifyProps(userNotifyProps)
@@ -55,8 +52,8 @@ func TestExportUserNotifyProps(t *testing.T) {
require.Equal(t, userNotifyProps[model.DESKTOP_NOTIFY_PROP], *exportNotifyProps.Desktop) require.Equal(t, userNotifyProps[model.DESKTOP_NOTIFY_PROP], *exportNotifyProps.Desktop)
require.Equal(t, userNotifyProps[model.DESKTOP_SOUND_NOTIFY_PROP], *exportNotifyProps.DesktopSound) require.Equal(t, userNotifyProps[model.DESKTOP_SOUND_NOTIFY_PROP], *exportNotifyProps.DesktopSound)
require.Equal(t, userNotifyProps[model.EMAIL_NOTIFY_PROP], *exportNotifyProps.Email) require.Equal(t, userNotifyProps[model.EMAIL_NOTIFY_PROP], *exportNotifyProps.Email)
require.Equal(t, userNotifyProps[model.MOBILE_NOTIFY_PROP], *exportNotifyProps.Mobile) require.Equal(t, userNotifyProps[model.PUSH_NOTIFY_PROP], *exportNotifyProps.Mobile)
require.Equal(t, userNotifyProps[model.MOBILE_PUSH_STATUS_NOTIFY_PROP], *exportNotifyProps.MobilePushStatus) require.Equal(t, userNotifyProps[model.PUSH_STATUS_NOTIFY_PROP], *exportNotifyProps.MobilePushStatus)
require.Equal(t, userNotifyProps[model.CHANNEL_MENTIONS_NOTIFY_PROP], *exportNotifyProps.ChannelTrigger) require.Equal(t, userNotifyProps[model.CHANNEL_MENTIONS_NOTIFY_PROP], *exportNotifyProps.ChannelTrigger)
require.Equal(t, userNotifyProps[model.COMMENTS_NOTIFY_PROP], *exportNotifyProps.CommentsTrigger) require.Equal(t, userNotifyProps[model.COMMENTS_NOTIFY_PROP], *exportNotifyProps.CommentsTrigger)
require.Equal(t, userNotifyProps[model.MENTION_KEYS_NOTIFY_PROP], *exportNotifyProps.MentionKeys) require.Equal(t, userNotifyProps[model.MENTION_KEYS_NOTIFY_PROP], *exportNotifyProps.MentionKeys)

Просмотреть файл

@@ -26,8 +26,6 @@ const (
PUSH_NOTIFY_PROP = "push" PUSH_NOTIFY_PROP = "push"
PUSH_STATUS_NOTIFY_PROP = "push_status" PUSH_STATUS_NOTIFY_PROP = "push_status"
EMAIL_NOTIFY_PROP = "email" EMAIL_NOTIFY_PROP = "email"
MOBILE_NOTIFY_PROP = "mobile"
MOBILE_PUSH_STATUS_NOTIFY_PROP = "mobile_push_status"
CHANNEL_MENTIONS_NOTIFY_PROP = "channel" CHANNEL_MENTIONS_NOTIFY_PROP = "channel"
COMMENTS_NOTIFY_PROP = "comments" COMMENTS_NOTIFY_PROP = "comments"
MENTION_KEYS_NOTIFY_PROP = "mention_keys" MENTION_KEYS_NOTIFY_PROP = "mention_keys"