[MM-12462] Include favorite channels in bulk export (#9692)
* Include favorite channels in bulk export * Remove duplicate method
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
90f279c7d5
Коммит
bce7a7c73d
@@ -206,17 +206,21 @@ func (a *App) buildUserChannelMemberships(userId string, teamId string) (*[]User
|
|||||||
var memberships []UserChannelImportData
|
var memberships []UserChannelImportData
|
||||||
|
|
||||||
result := <-a.Srv.Store.Channel().GetChannelMembersForExport(userId, teamId)
|
result := <-a.Srv.Store.Channel().GetChannelMembersForExport(userId, teamId)
|
||||||
|
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
members := result.Data.([]*model.ChannelMemberForExport)
|
members := result.Data.([]*model.ChannelMemberForExport)
|
||||||
|
|
||||||
for _, member := range members {
|
category := model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL
|
||||||
memberships = append(memberships, *ImportUserChannelDataFromChannelMember(member))
|
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
|
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)
|
rolesList := strings.Fields(member.Roles)
|
||||||
if member.SchemeAdmin {
|
if member.SchemeAdmin {
|
||||||
rolesList = append(rolesList, model.CHANNEL_ADMIN_ROLE_ID)
|
rolesList = append(rolesList, model.CHANNEL_ADMIN_ROLE_ID)
|
||||||
@@ -95,11 +95,19 @@ func ImportUserChannelDataFromChannelMember(member *model.ChannelMemberForExport
|
|||||||
notifyProps.MarkUnread = &markUnread
|
notifyProps.MarkUnread = &markUnread
|
||||||
}
|
}
|
||||||
|
|
||||||
|
favorite := false
|
||||||
|
for _, preference := range *preferences {
|
||||||
|
if member.ChannelId == preference.Name {
|
||||||
|
favorite = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
roles := strings.Join(rolesList, " ")
|
roles := strings.Join(rolesList, " ")
|
||||||
return &UserChannelImportData{
|
return &UserChannelImportData{
|
||||||
Name: &member.ChannelName,
|
Name: &member.ChannelName,
|
||||||
Roles: &roles,
|
Roles: &roles,
|
||||||
NotifyProps: ¬ifyProps,
|
NotifyProps: ¬ifyProps,
|
||||||
|
Favorite: &favorite,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package app
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/stretchr/testify/require"
|
"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)
|
require.Equal(t, userNotifyProps[model.MENTION_KEYS_NOTIFY_PROP], *exportNotifyProps.MentionKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExportUserChannelsNotifyProps(t *testing.T) {
|
func TestExportUserChannels(t *testing.T) {
|
||||||
th := Setup().InitBasic()
|
th := Setup().InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
channel := th.BasicChannel
|
channel := th.BasicChannel
|
||||||
@@ -71,22 +72,34 @@ func TestExportUserChannelsNotifyProps(t *testing.T) {
|
|||||||
model.DESKTOP_NOTIFY_PROP: model.USER_NOTIFY_ALL,
|
model.DESKTOP_NOTIFY_PROP: model.USER_NOTIFY_ALL,
|
||||||
model.PUSH_NOTIFY_PROP: model.USER_NOTIFY_NONE,
|
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{
|
channelMember := model.ChannelMember{
|
||||||
ChannelId: channel.Id,
|
ChannelId: channel.Id,
|
||||||
UserId: user.Id,
|
UserId: user.Id,
|
||||||
}
|
}
|
||||||
th.App.Srv.Store.Channel().SaveMember(&channelMember)
|
th.App.Srv.Store.Channel().SaveMember(&channelMember)
|
||||||
|
th.App.Srv.Store.Preference().Save(&preferences)
|
||||||
th.App.UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id)
|
th.App.UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id)
|
||||||
exportData, _ := th.App.buildUserChannelMemberships(user.Id, team.Id)
|
exportData, _ := th.App.buildUserChannelMemberships(user.Id, team.Id)
|
||||||
|
assert.Equal(t, len(*exportData), 3)
|
||||||
for _, data := range *exportData {
|
for _, data := range *exportData {
|
||||||
if *data.Name == channelName {
|
if *data.Name == channelName {
|
||||||
assert.Equal(t, *data.NotifyProps.Desktop, "all")
|
assert.Equal(t, *data.NotifyProps.Desktop, "all")
|
||||||
assert.Equal(t, *data.NotifyProps.Mobile, "none")
|
assert.Equal(t, *data.NotifyProps.Mobile, "none")
|
||||||
assert.Equal(t, *data.NotifyProps.MarkUnread, "all") // default value
|
assert.Equal(t, *data.NotifyProps.MarkUnread, "all") // default value
|
||||||
|
assert.True(t, *data.Favorite)
|
||||||
} else { // default values
|
} else { // default values
|
||||||
assert.Equal(t, *data.NotifyProps.Desktop, "default")
|
assert.Equal(t, *data.NotifyProps.Desktop, "default")
|
||||||
assert.Equal(t, *data.NotifyProps.Mobile, "default")
|
assert.Equal(t, *data.NotifyProps.Mobile, "default")
|
||||||
assert.Equal(t, *data.NotifyProps.MarkUnread, "all")
|
assert.Equal(t, *data.NotifyProps.MarkUnread, "all")
|
||||||
|
assert.False(t, *data.Favorite)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user