From 82779453631916bcd4d88f987b34cb6246239f6d Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Wed, 8 Feb 2017 16:19:38 +0000 Subject: PLT-5427: Import ChannelMember Notify Props. (#5329) --- app/import.go | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'app/import.go') diff --git a/app/import.go b/app/import.go index 4a27bcd7e..599c08f9d 100644 --- a/app/import.go +++ b/app/import.go @@ -66,8 +66,14 @@ type UserTeamImportData struct { } type UserChannelImportData struct { - Name *string `json:"name"` - Roles *string `json:"roles"` + 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 -- cgit v1.2.3-1-g7c22