PLT-5427: Import ChannelMember Notify Props. (#5329)
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
ff2a36e9c0
Коммит
8277945363
@@ -68,6 +68,12 @@ type UserTeamImportData struct {
|
||||
type UserChannelImportData struct {
|
||||
Name *string `json:"name"`
|
||||
Roles *string `json:"roles"`
|
||||
NotifyProps *UserChannelNotifyPropsImportData `json:"notify_props"`
|
||||
}
|
||||
|
||||
type UserChannelNotifyPropsImportData struct {
|
||||
Desktop *string `json:"desktop"`
|
||||
MarkUnread *string `json:"mark_unread"`
|
||||
}
|
||||
|
||||
//
|
||||
@@ -472,6 +478,22 @@ func ImportUserChannels(user *model.User, team *model.Team, data *[]UserChannelI
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if cdata.NotifyProps != nil {
|
||||
notifyProps := member.NotifyProps
|
||||
|
||||
if cdata.NotifyProps.Desktop != nil {
|
||||
notifyProps["desktop"] = *cdata.NotifyProps.Desktop
|
||||
}
|
||||
|
||||
if cdata.NotifyProps.MarkUnread != nil {
|
||||
notifyProps["mark_unread"] = *cdata.NotifyProps.MarkUnread
|
||||
}
|
||||
|
||||
if _, err := UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -563,6 +585,16 @@ func validateUserChannelsImportData(data *[]UserChannelImportData) *model.AppErr
|
||||
if cdata.Roles != nil && !model.IsValidUserRoles(*cdata.Roles) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_channels_import_data.invalid_roles.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if cdata.NotifyProps != nil {
|
||||
if cdata.NotifyProps.Desktop != nil && !model.IsChannelNotifyLevelValid(*cdata.NotifyProps.Desktop) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_channels_import_data.invalid_notify_props_desktop.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if cdata.NotifyProps.MarkUnread != nil && !model.IsChannelMarkUnreadLevelValid(*cdata.NotifyProps.MarkUnread) {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_channels_import_data.invalid_notify_props_mark_unread.error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -5,9 +5,9 @@ package app
|
||||
|
||||
import (
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"strings"
|
||||
"testing"
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
|
||||
func ptrStr(s string) *string {
|
||||
@@ -423,6 +423,31 @@ func TestImportValidateUserChannelsImportData(t *testing.T) {
|
||||
if err := validateUserChannelsImportData(&data); err != nil {
|
||||
t.Fatal("Should have succeeded with valid roles.")
|
||||
}
|
||||
|
||||
// Empty notify props.
|
||||
data[0].NotifyProps = &UserChannelNotifyPropsImportData{}
|
||||
if err := validateUserChannelsImportData(&data); err != nil {
|
||||
t.Fatal("Should have succeeded with empty notify props.")
|
||||
}
|
||||
|
||||
// Invalid desktop notify props.
|
||||
data[0].NotifyProps.Desktop = ptrStr("invalid")
|
||||
if err := validateUserChannelsImportData(&data); err == nil {
|
||||
t.Fatal("Should have failed with invalid desktop notify props.")
|
||||
}
|
||||
|
||||
// Invalid desktop notify props.
|
||||
data[0].NotifyProps.Desktop = ptrStr("mention")
|
||||
data[0].NotifyProps.MarkUnread = ptrStr("invalid")
|
||||
if err := validateUserChannelsImportData(&data); err == nil {
|
||||
t.Fatal("Should have failed with invalid mark_unread notify props.")
|
||||
}
|
||||
|
||||
// Empty notify props.
|
||||
data[0].NotifyProps.MarkUnread = ptrStr("mention")
|
||||
if err := validateUserChannelsImportData(&data); err != nil {
|
||||
t.Fatal("Should have succeeded with valid notify props.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportImportTeam(t *testing.T) {
|
||||
@@ -543,7 +568,7 @@ func TestImportImportChannel(t *testing.T) {
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
}, false)
|
||||
team, err := GetTeamByName(teamName);
|
||||
team, err := GetTeamByName(teamName)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get team from database.")
|
||||
}
|
||||
@@ -874,7 +899,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
}, false)
|
||||
team, err := GetTeamByName(teamName);
|
||||
team, err := GetTeamByName(teamName)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get team from database.")
|
||||
}
|
||||
@@ -886,7 +911,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
DisplayName: ptrStr("Display Name"),
|
||||
Type: ptrStr("O"),
|
||||
}, false)
|
||||
channel, err := GetChannelByName(channelName, team.Id);
|
||||
channel, err := GetChannelByName(channelName, team.Id)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get channel from database.")
|
||||
}
|
||||
@@ -1087,7 +1112,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
}
|
||||
|
||||
// Check team member properties.
|
||||
user, err := GetUserByUsername(username);
|
||||
user, err := GetUserByUsername(username)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get user from database.")
|
||||
}
|
||||
@@ -1128,7 +1153,7 @@ func TestImportImportUser(t *testing.T) {
|
||||
// Check channel member properties.
|
||||
if channelMember, err := GetChannelMember(channel.Id, user.Id); err != nil {
|
||||
t.Fatalf("Failed to get channel member from database.")
|
||||
} else if channelMember.Roles != "channel_user" {
|
||||
} else if channelMember.Roles != "channel_user" || channelMember.NotifyProps["desktop"] != "default" || channelMember.NotifyProps["mark_unread"] != "all" {
|
||||
t.Fatalf("Channel member properties not as expected")
|
||||
}
|
||||
|
||||
@@ -1141,6 +1166,10 @@ func TestImportImportUser(t *testing.T) {
|
||||
{
|
||||
Name: &channelName,
|
||||
Roles: ptrStr("channel_user channel_admin"),
|
||||
NotifyProps: &UserChannelNotifyPropsImportData{
|
||||
Desktop: ptrStr("mention"),
|
||||
MarkUnread: ptrStr("mention"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1157,8 +1186,8 @@ func TestImportImportUser(t *testing.T) {
|
||||
}
|
||||
|
||||
if channelMember, err := GetChannelMember(channel.Id, user.Id); err != nil {
|
||||
t.Fatalf("Failed to get channel member from database.")
|
||||
} else if channelMember.Roles != "channel_user channel_admin" {
|
||||
t.Fatalf("Failed to get channel member Desktop from database.")
|
||||
} else if channelMember.Roles != "channel_user channel_admin" && channelMember.NotifyProps["desktop"] == "mention" && channelMember.NotifyProps["mark_unread"] == "mention" {
|
||||
t.Fatalf("Channel member properties not as expected")
|
||||
}
|
||||
|
||||
|
||||
@@ -2967,6 +2967,14 @@
|
||||
"id": "app.import.validate_user_channels_import_data.invalid_roles.error",
|
||||
"translation": "Invalid roles for User's Channel Membership."
|
||||
},
|
||||
{
|
||||
"id": "app.import.validate_user_channels_import_data.invalid_notify_props_desktop.error",
|
||||
"translation": "Invalid Desktop NotifyProps for User's Channel Membership."
|
||||
},
|
||||
{
|
||||
"id": "app.import.validate_user_channels_import_data.invalid_notify_props_mark_unread.error",
|
||||
"translation": "Invalid MarkUnread NotifyProps for User's Channel Membership."
|
||||
},
|
||||
{
|
||||
"id": "authentication.permissions.create_team_roles.description",
|
||||
"translation": "Ability to create new teams"
|
||||
|
||||
Ссылка в новой задаче
Block a user