[MM-12462] Include favorite channels in bulk export (#9692)

* Include favorite channels in bulk export

* Remove duplicate method
Этот коммит содержится в:
Shobhit Gupta
2018-11-05 05:18:00 -08:00
коммит произвёл George Goldberg
родитель 90f279c7d5
Коммит bce7a7c73d
3 изменённых файлов: 31 добавлений и 6 удалений

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

@@ -206,17 +206,21 @@ func (a *App) buildUserChannelMemberships(userId string, teamId string) (*[]User
var memberships []UserChannelImportData
result := <-a.Srv.Store.Channel().GetChannelMembersForExport(userId, teamId)
if result.Err != nil {
return nil, result.Err
}
members := result.Data.([]*model.ChannelMemberForExport)
for _, member := range members {
memberships = append(memberships, *ImportUserChannelDataFromChannelMember(member))
category := model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL
preferences, err := a.GetPreferenceByCategoryForUser(userId, category)
if err != nil {
return nil, err
}
for _, member := range members {
memberships = append(memberships, *ImportUserChannelDataFromChannelMemberAndPreferences(member, &preferences))
}
return &memberships, nil
}

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

@@ -71,7 +71,7 @@ func ImportUserTeamDataFromTeamMember(member *model.TeamMemberForExport) *UserTe
}
}
func ImportUserChannelDataFromChannelMember(member *model.ChannelMemberForExport) *UserChannelImportData {
func ImportUserChannelDataFromChannelMemberAndPreferences(member *model.ChannelMemberForExport, preferences *model.Preferences) *UserChannelImportData {
rolesList := strings.Fields(member.Roles)
if member.SchemeAdmin {
rolesList = append(rolesList, model.CHANNEL_ADMIN_ROLE_ID)
@@ -95,11 +95,19 @@ func ImportUserChannelDataFromChannelMember(member *model.ChannelMemberForExport
notifyProps.MarkUnread = &markUnread
}
favorite := false
for _, preference := range *preferences {
if member.ChannelId == preference.Name {
favorite = true
}
}
roles := strings.Join(rolesList, " ")
return &UserChannelImportData{
Name: &member.ChannelName,
Roles: &roles,
NotifyProps: &notifyProps,
Favorite: &favorite,
}
}

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

@@ -3,8 +3,9 @@ package app
import (
"testing"
"github.com/mattermost/mattermost-server/model"
"github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost-server/model"
"github.com/stretchr/testify/require"
)
@@ -60,7 +61,7 @@ func TestExportUserNotifyProps(t *testing.T) {
require.Equal(t, userNotifyProps[model.MENTION_KEYS_NOTIFY_PROP], *exportNotifyProps.MentionKeys)
}
func TestExportUserChannelsNotifyProps(t *testing.T) {
func TestExportUserChannels(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
channel := th.BasicChannel
@@ -71,22 +72,34 @@ func TestExportUserChannelsNotifyProps(t *testing.T) {
model.DESKTOP_NOTIFY_PROP: model.USER_NOTIFY_ALL,
model.PUSH_NOTIFY_PROP: model.USER_NOTIFY_NONE,
}
preference := model.Preference{
UserId: user.Id,
Category: model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL,
Name: channel.Id,
Value: "true",
}
var preferences model.Preferences
preferences = append(preferences, preference)
channelMember := model.ChannelMember{
ChannelId: channel.Id,
UserId: user.Id,
}
th.App.Srv.Store.Channel().SaveMember(&channelMember)
th.App.Srv.Store.Preference().Save(&preferences)
th.App.UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id)
exportData, _ := th.App.buildUserChannelMemberships(user.Id, team.Id)
assert.Equal(t, len(*exportData), 3)
for _, data := range *exportData {
if *data.Name == channelName {
assert.Equal(t, *data.NotifyProps.Desktop, "all")
assert.Equal(t, *data.NotifyProps.Mobile, "none")
assert.Equal(t, *data.NotifyProps.MarkUnread, "all") // default value
assert.True(t, *data.Favorite)
} else { // default values
assert.Equal(t, *data.NotifyProps.Desktop, "default")
assert.Equal(t, *data.NotifyProps.Mobile, "default")
assert.Equal(t, *data.NotifyProps.MarkUnread, "all")
assert.False(t, *data.Favorite)
}
}
}