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) {
|
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)
|
members, nErr := a.Srv().Store().Channel().GetChannelMembersForExport(userID, teamID)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
return nil, model.NewAppError("buildUserChannelMemberships", "app.channel.get_members.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, member := range members {
|
memberships := make([]imports.UserChannelImportData, len(members))
|
||||||
memberships = append(memberships, *ImportUserChannelDataFromChannelMemberAndPreferences(member, &preferences))
|
for i, member := range members {
|
||||||
|
memberships[i] = *ImportUserChannelDataFromChannelMemberAndPreferences(member, &preferences)
|
||||||
}
|
}
|
||||||
return &memberships, nil
|
return &memberships, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,10 +150,16 @@ func ImportUserChannelDataFromChannelMemberAndPreferences(member *model.ChannelM
|
|||||||
|
|
||||||
roles := strings.Join(rolesList, " ")
|
roles := strings.Join(rolesList, " ")
|
||||||
return &imports.UserChannelImportData{
|
return &imports.UserChannelImportData{
|
||||||
Name: &member.ChannelName,
|
Name: &member.ChannelName,
|
||||||
Roles: &roles,
|
Roles: &roles,
|
||||||
NotifyProps: ¬ifyProps,
|
NotifyProps: ¬ifyProps,
|
||||||
Favorite: &favorite,
|
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) {
|
func TestExportUserChannels(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
channel := th.BasicChannel
|
channel := th.BasicChannel
|
||||||
user := th.BasicUser
|
user := th.BasicUser
|
||||||
team := th.BasicTeam
|
team := th.BasicTeam
|
||||||
@@ -91,6 +92,10 @@ func TestExportUserChannels(t *testing.T) {
|
|||||||
Name: channel.Id,
|
Name: channel.Id,
|
||||||
Value: "true",
|
Value: "true",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, appErr := th.App.MarkChannelsAsViewed(th.Context, []string{th.BasicPost.ChannelId}, user.Id, "", true)
|
||||||
|
require.Nil(t, appErr)
|
||||||
|
|
||||||
var preferences model.Preferences
|
var preferences model.Preferences
|
||||||
preferences = append(preferences, preference)
|
preferences = append(preferences, preference)
|
||||||
err := th.App.Srv().Store().Preference().Save(preferences)
|
err := th.App.Srv().Store().Preference().Save(preferences)
|
||||||
@@ -102,15 +107,19 @@ func TestExportUserChannels(t *testing.T) {
|
|||||||
assert.Equal(t, len(*exportData), 3)
|
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, "all", *data.NotifyProps.Desktop)
|
||||||
assert.Equal(t, *data.NotifyProps.Mobile, "none")
|
assert.Equal(t, "none", *data.NotifyProps.Mobile)
|
||||||
assert.Equal(t, *data.NotifyProps.MarkUnread, "all") // default value
|
assert.Equal(t, "all", *data.NotifyProps.MarkUnread) // default value
|
||||||
assert.True(t, *data.Favorite)
|
assert.True(t, *data.Favorite)
|
||||||
|
assert.NotEqualValues(t, 0, *data.LastViewedAt)
|
||||||
|
assert.NotEqualValues(t, 0, *data.MsgCount)
|
||||||
} else { // default values
|
} else { // default values
|
||||||
assert.Equal(t, *data.NotifyProps.Desktop, "default")
|
assert.Equal(t, "default", *data.NotifyProps.Desktop)
|
||||||
assert.Equal(t, *data.NotifyProps.Mobile, "default")
|
assert.Equal(t, "default", *data.NotifyProps.Mobile)
|
||||||
assert.Equal(t, *data.NotifyProps.MarkUnread, "all")
|
assert.Equal(t, "all", *data.NotifyProps.MarkUnread)
|
||||||
assert.False(t, *data.Favorite)
|
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
|
isUserByChannelId[channel.Id] = true
|
||||||
isAdminByChannelId[channel.Id] = false
|
isAdminByChannelId[channel.Id] = false
|
||||||
|
|
||||||
if cdata.Roles == nil {
|
if cdata.Roles != nil {
|
||||||
isUserByChannelId[channel.Id] = true
|
|
||||||
} else {
|
|
||||||
rawRoles := *cdata.Roles
|
rawRoles := *cdata.Roles
|
||||||
explicitRoles := []string{}
|
explicitRoles := []string{}
|
||||||
for _, role := range strings.Fields(rawRoles) {
|
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
|
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 != nil {
|
||||||
if cdata.NotifyProps.Desktop != nil {
|
if cdata.NotifyProps.Desktop != nil {
|
||||||
member.NotifyProps[model.DesktopNotifyProp] = *cdata.NotifyProps.Desktop
|
member.NotifyProps[model.DesktopNotifyProp] = *cdata.NotifyProps.Desktop
|
||||||
|
|||||||
@@ -108,10 +108,16 @@ type UserTeamImportData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UserChannelImportData struct {
|
type UserChannelImportData struct {
|
||||||
Name *string `json:"name"`
|
Name *string `json:"name"`
|
||||||
Roles *string `json:"roles"`
|
Roles *string `json:"roles"`
|
||||||
NotifyProps *UserChannelNotifyPropsImportData `json:"notify_props,omitempty"`
|
NotifyProps *UserChannelNotifyPropsImportData `json:"notify_props,omitempty"`
|
||||||
Favorite *bool `json:"favorite,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 {
|
type UserChannelNotifyPropsImportData struct {
|
||||||
|
|||||||
@@ -4082,6 +4082,7 @@ func (s SqlChannelStore) GetChannelMembersForExport(userId string, teamId string
|
|||||||
ChannelMembers.MentionCount,
|
ChannelMembers.MentionCount,
|
||||||
ChannelMembers.MentionCountRoot,
|
ChannelMembers.MentionCountRoot,
|
||||||
COALESCE(ChannelMembers.UrgentMentionCount, 0) AS UrgentMentionCount,
|
COALESCE(ChannelMembers.UrgentMentionCount, 0) AS UrgentMentionCount,
|
||||||
|
ChannelMembers.MsgCountRoot,
|
||||||
ChannelMembers.NotifyProps,
|
ChannelMembers.NotifyProps,
|
||||||
ChannelMembers.LastUpdateAt,
|
ChannelMembers.LastUpdateAt,
|
||||||
ChannelMembers.SchemeUser,
|
ChannelMembers.SchemeUser,
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user