[MM-12461] Include the per-channel NotifyProps for Users in Bulk Export (#9773)

* Add per channel notify props to bulk export

* Check if key exists before assigning
This commit is contained in:
Shobhit Gupta
2018-10-31 11:43:47 -07:00
committed by Christopher Speller
parent e0f5ee97b4
commit 2e945e287d
2 changed files with 52 additions and 3 deletions

View File

@@ -4,8 +4,9 @@
package app
import (
"github.com/mattermost/mattermost-server/model"
"strings"
"github.com/mattermost/mattermost-server/model"
)
func ImportLineFromTeam(team *model.TeamForExport) *LineImportData {
@@ -78,10 +79,27 @@ func ImportUserChannelDataFromChannelMember(member *model.ChannelMemberForExport
if member.SchemeUser {
rolesList = append(rolesList, model.CHANNEL_USER_ROLE_ID)
}
props := member.NotifyProps
notifyProps := UserChannelNotifyPropsImportData{}
desktop, exist := props[model.DESKTOP_NOTIFY_PROP]
if exist {
notifyProps.Desktop = &desktop
}
mobile, exist := props[model.PUSH_NOTIFY_PROP]
if exist {
notifyProps.Mobile = &mobile
}
markUnread, exist := props[model.MARK_UNREAD_NOTIFY_PROP]
if exist {
notifyProps.MarkUnread = &markUnread
}
roles := strings.Join(rolesList, " ")
return &UserChannelImportData{
Name: &member.ChannelName,
Roles: &roles,
Name: &member.ChannelName,
Roles: &roles,
NotifyProps: &notifyProps,
}
}

View File

@@ -59,3 +59,34 @@ func TestExportUserNotifyProps(t *testing.T) {
require.Equal(t, userNotifyProps[model.COMMENTS_NOTIFY_PROP], *exportNotifyProps.CommentsTrigger)
require.Equal(t, userNotifyProps[model.MENTION_KEYS_NOTIFY_PROP], *exportNotifyProps.MentionKeys)
}
func TestExportUserChannelsNotifyProps(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
channel := th.BasicChannel
user := th.BasicUser
team := th.BasicTeam
channelName := channel.Name
notifyProps := model.StringMap{
model.DESKTOP_NOTIFY_PROP: model.USER_NOTIFY_ALL,
model.PUSH_NOTIFY_PROP: model.USER_NOTIFY_NONE,
}
channelMember := model.ChannelMember{
ChannelId: channel.Id,
UserId: user.Id,
}
th.App.Srv.Store.Channel().SaveMember(&channelMember)
th.App.UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id)
exportData, _ := th.App.buildUserChannelMemberships(user.Id, team.Id)
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
} else { // default values
assert.Equal(t, *data.NotifyProps.Desktop, "default")
assert.Equal(t, *data.NotifyProps.Mobile, "default")
assert.Equal(t, *data.NotifyProps.MarkUnread, "all")
}
}
}