MM-47537 Export and import read channels (#22145)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
62b3f22b48
Коммит
bc6c071c3a
@@ -371,8 +371,6 @@ func (a *App) buildUserTeamAndChannelMemberships(userID string) (*[]imports.User
|
||||
}
|
||||
|
||||
func (a *App) buildUserChannelMemberships(userID string, teamID string) (*[]imports.UserChannelImportData, *model.AppError) {
|
||||
var memberships []imports.UserChannelImportData
|
||||
|
||||
members, nErr := a.Srv().Store().Channel().GetChannelMembersForExport(userID, teamID)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("buildUserChannelMemberships", "app.channel.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
@@ -384,8 +382,9 @@ func (a *App) buildUserChannelMemberships(userID string, teamID string) (*[]impo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, member := range members {
|
||||
memberships = append(memberships, *ImportUserChannelDataFromChannelMemberAndPreferences(member, &preferences))
|
||||
memberships := make([]imports.UserChannelImportData, len(members))
|
||||
for i, member := range members {
|
||||
memberships[i] = *ImportUserChannelDataFromChannelMemberAndPreferences(member, &preferences)
|
||||
}
|
||||
return &memberships, nil
|
||||
}
|
||||
|
||||
@@ -150,10 +150,16 @@ func ImportUserChannelDataFromChannelMemberAndPreferences(member *model.ChannelM
|
||||
|
||||
roles := strings.Join(rolesList, " ")
|
||||
return &imports.UserChannelImportData{
|
||||
Name: &member.ChannelName,
|
||||
Roles: &roles,
|
||||
NotifyProps: ¬ifyProps,
|
||||
Favorite: &favorite,
|
||||
Name: &member.ChannelName,
|
||||
Roles: &roles,
|
||||
NotifyProps: ¬ifyProps,
|
||||
Favorite: &favorite,
|
||||
MentionCount: &member.MentionCount,
|
||||
MentionCountRoot: &member.MentionCountRoot,
|
||||
UrgentMentionCount: &member.UrgentMentionCount,
|
||||
MsgCount: &member.MsgCount,
|
||||
MsgCountRoot: &member.MsgCountRoot,
|
||||
LastViewedAt: &member.LastViewedAt,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ func TestExportUserNotifyProps(t *testing.T) {
|
||||
func TestExportUserChannels(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
channel := th.BasicChannel
|
||||
user := th.BasicUser
|
||||
team := th.BasicTeam
|
||||
@@ -91,6 +92,10 @@ func TestExportUserChannels(t *testing.T) {
|
||||
Name: channel.Id,
|
||||
Value: "true",
|
||||
}
|
||||
|
||||
_, appErr := th.App.MarkChannelsAsViewed(th.Context, []string{th.BasicPost.ChannelId}, user.Id, "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
var preferences model.Preferences
|
||||
preferences = append(preferences, preference)
|
||||
err := th.App.Srv().Store().Preference().Save(preferences)
|
||||
@@ -102,15 +107,19 @@ func TestExportUserChannels(t *testing.T) {
|
||||
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.Equal(t, "all", *data.NotifyProps.Desktop)
|
||||
assert.Equal(t, "none", *data.NotifyProps.Mobile)
|
||||
assert.Equal(t, "all", *data.NotifyProps.MarkUnread) // default value
|
||||
assert.True(t, *data.Favorite)
|
||||
assert.NotEqualValues(t, 0, *data.LastViewedAt)
|
||||
assert.NotEqualValues(t, 0, *data.MsgCount)
|
||||
} 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.Equal(t, "default", *data.NotifyProps.Desktop)
|
||||
assert.Equal(t, "default", *data.NotifyProps.Mobile)
|
||||
assert.Equal(t, "all", *data.NotifyProps.MarkUnread)
|
||||
assert.False(t, *data.Favorite)
|
||||
assert.EqualValues(t, 0, *data.LastViewedAt)
|
||||
assert.EqualValues(t, 0, *data.MsgCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -981,9 +981,7 @@ func (a *App) importUserChannels(c request.CTX, user *model.User, team *model.Te
|
||||
isUserByChannelId[channel.Id] = true
|
||||
isAdminByChannelId[channel.Id] = false
|
||||
|
||||
if cdata.Roles == nil {
|
||||
isUserByChannelId[channel.Id] = true
|
||||
} else {
|
||||
if cdata.Roles != nil {
|
||||
rawRoles := *cdata.Roles
|
||||
explicitRoles := []string{}
|
||||
for _, role := range strings.Fields(rawRoles) {
|
||||
@@ -1027,6 +1025,21 @@ func (a *App) importUserChannels(c request.CTX, user *model.User, team *model.Te
|
||||
member.SchemeAdmin = userShouldBeAdmin
|
||||
}
|
||||
|
||||
if cdata.MentionCount != nil && cdata.MentionCountRoot != nil {
|
||||
member.MentionCount = *cdata.MentionCount
|
||||
member.MentionCountRoot = *cdata.MentionCountRoot
|
||||
}
|
||||
if cdata.UrgentMentionCount != nil {
|
||||
member.UrgentMentionCount = *cdata.UrgentMentionCount
|
||||
}
|
||||
if cdata.MsgCount != nil && cdata.MsgCountRoot != nil {
|
||||
member.MsgCount = *cdata.MsgCount
|
||||
member.MsgCountRoot = *cdata.MsgCountRoot
|
||||
}
|
||||
if cdata.LastViewedAt != nil {
|
||||
member.LastViewedAt = *cdata.LastViewedAt
|
||||
}
|
||||
|
||||
if cdata.NotifyProps != nil {
|
||||
if cdata.NotifyProps.Desktop != nil {
|
||||
member.NotifyProps[model.DesktopNotifyProp] = *cdata.NotifyProps.Desktop
|
||||
|
||||
@@ -108,10 +108,16 @@ type UserTeamImportData struct {
|
||||
}
|
||||
|
||||
type UserChannelImportData struct {
|
||||
Name *string `json:"name"`
|
||||
Roles *string `json:"roles"`
|
||||
NotifyProps *UserChannelNotifyPropsImportData `json:"notify_props,omitempty"`
|
||||
Favorite *bool `json:"favorite,omitempty"`
|
||||
Name *string `json:"name"`
|
||||
Roles *string `json:"roles"`
|
||||
NotifyProps *UserChannelNotifyPropsImportData `json:"notify_props,omitempty"`
|
||||
Favorite *bool `json:"favorite,omitempty"`
|
||||
MentionCount *int64 `json:"mention_count,omitempty"`
|
||||
MentionCountRoot *int64 `json:"mention_count_root,omitempty"`
|
||||
UrgentMentionCount *int64 `json:"urgend_mention_count,omitempty"`
|
||||
MsgCount *int64 `json:"msg_count,omitempty"`
|
||||
MsgCountRoot *int64 `json:"msg_count_root,omitempty"`
|
||||
LastViewedAt *int64 `json:"last_viewed_at,omitempty"`
|
||||
}
|
||||
|
||||
type UserChannelNotifyPropsImportData struct {
|
||||
|
||||
@@ -4082,6 +4082,7 @@ func (s SqlChannelStore) GetChannelMembersForExport(userId string, teamId string
|
||||
ChannelMembers.MentionCount,
|
||||
ChannelMembers.MentionCountRoot,
|
||||
COALESCE(ChannelMembers.UrgentMentionCount, 0) AS UrgentMentionCount,
|
||||
ChannelMembers.MsgCountRoot,
|
||||
ChannelMembers.NotifyProps,
|
||||
ChannelMembers.LastUpdateAt,
|
||||
ChannelMembers.SchemeUser,
|
||||
|
||||
Ссылка в новой задаче
Block a user