From 62a94d53f4d38debc49bfccfa6a76db75768edd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Tue, 12 Mar 2019 09:29:55 +0100 Subject: [PATCH] MM-14488: Autogenerate mention_keys on creation if mention_keys aren't provided (#10430) * MM-14488: Autogenerate mention_keys on creation if mention_keys aren't provided * Fixing test case --- app/import_functions.go | 2 ++ app/import_functions_test.go | 62 +++++++++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/app/import_functions.go b/app/import_functions.go index f611a7838e..c1e469c13d 100644 --- a/app/import_functions.go +++ b/app/import_functions.go @@ -446,6 +446,8 @@ func (a *App) ImportUser(data *UserImportData, dryRun bool) *model.AppError { user.AddNotifyProp(model.MENTION_KEYS_NOTIFY_PROP, *data.NotifyProps.MentionKeys) hasNotifyPropsChanged = true } + } else { + user.UpdateMentionKeysFromUsername("") } } diff --git a/app/import_functions_test.go b/app/import_functions_test.go index df9f611e4c..cfb6fc5d48 100644 --- a/app/import_functions_test.go +++ b/app/import_functions_test.go @@ -4,6 +4,7 @@ package app import ( + "fmt" "path/filepath" "strings" "testing" @@ -1113,7 +1114,34 @@ func TestImportImportUser(t *testing.T) { checkPreference(t, th.App, user.Id, model.PREFERENCE_CATEGORY_TUTORIAL_STEPS, user.Id, *data.TutorialStep) checkPreference(t, th.App, user.Id, model.PREFERENCE_CATEGORY_NOTIFICATIONS, model.PREFERENCE_NAME_EMAIL_INTERVAL, "3600") - // Set Notify Props + // Set Notify Without mention keys + data.NotifyProps = &UserNotifyPropsImportData{ + Desktop: ptrStr(model.USER_NOTIFY_ALL), + DesktopSound: ptrStr("true"), + Email: ptrStr("true"), + Mobile: ptrStr(model.USER_NOTIFY_ALL), + MobilePushStatus: ptrStr(model.STATUS_ONLINE), + ChannelTrigger: ptrStr("true"), + CommentsTrigger: ptrStr(model.COMMENTS_NOTIFY_ROOT), + } + err = th.App.ImportUser(&data, false) + assert.Nil(t, err) + + user, err = th.App.GetUserByUsername(username) + if err != nil { + t.Fatalf("Failed to get user from database.") + } + + checkNotifyProp(t, user, model.DESKTOP_NOTIFY_PROP, model.USER_NOTIFY_ALL) + checkNotifyProp(t, user, model.DESKTOP_SOUND_NOTIFY_PROP, "true") + checkNotifyProp(t, user, model.EMAIL_NOTIFY_PROP, "true") + checkNotifyProp(t, user, model.PUSH_NOTIFY_PROP, model.USER_NOTIFY_ALL) + checkNotifyProp(t, user, model.PUSH_STATUS_NOTIFY_PROP, model.STATUS_ONLINE) + checkNotifyProp(t, user, model.CHANNEL_MENTIONS_NOTIFY_PROP, "true") + checkNotifyProp(t, user, model.COMMENTS_NOTIFY_PROP, model.COMMENTS_NOTIFY_ROOT) + checkNotifyProp(t, user, model.MENTION_KEYS_NOTIFY_PROP, fmt.Sprintf("%s,@%s", username, username)) + + // Set Notify Props with Mention keys data.NotifyProps = &UserNotifyPropsImportData{ Desktop: ptrStr(model.USER_NOTIFY_ALL), DesktopSound: ptrStr("true"), @@ -1141,7 +1169,7 @@ func TestImportImportUser(t *testing.T) { checkNotifyProp(t, user, model.COMMENTS_NOTIFY_PROP, model.COMMENTS_NOTIFY_ROOT) checkNotifyProp(t, user, model.MENTION_KEYS_NOTIFY_PROP, "valid,misc") - // Change Notify Props + // Change Notify Props with mention keys data.NotifyProps = &UserNotifyPropsImportData{ Desktop: ptrStr(model.USER_NOTIFY_MENTION), DesktopSound: ptrStr("false"), @@ -1169,6 +1197,33 @@ func TestImportImportUser(t *testing.T) { checkNotifyProp(t, user, model.COMMENTS_NOTIFY_PROP, model.COMMENTS_NOTIFY_ANY) checkNotifyProp(t, user, model.MENTION_KEYS_NOTIFY_PROP, "misc") + // Change Notify Props without mention keys + data.NotifyProps = &UserNotifyPropsImportData{ + Desktop: ptrStr(model.USER_NOTIFY_MENTION), + DesktopSound: ptrStr("false"), + Email: ptrStr("false"), + Mobile: ptrStr(model.USER_NOTIFY_NONE), + MobilePushStatus: ptrStr(model.STATUS_AWAY), + ChannelTrigger: ptrStr("false"), + CommentsTrigger: ptrStr(model.COMMENTS_NOTIFY_ANY), + } + err = th.App.ImportUser(&data, false) + assert.Nil(t, err) + + user, err = th.App.GetUserByUsername(username) + if err != nil { + t.Fatalf("Failed to get user from database.") + } + + checkNotifyProp(t, user, model.DESKTOP_NOTIFY_PROP, model.USER_NOTIFY_MENTION) + checkNotifyProp(t, user, model.DESKTOP_SOUND_NOTIFY_PROP, "false") + checkNotifyProp(t, user, model.EMAIL_NOTIFY_PROP, "false") + checkNotifyProp(t, user, model.PUSH_NOTIFY_PROP, model.USER_NOTIFY_NONE) + checkNotifyProp(t, user, model.PUSH_STATUS_NOTIFY_PROP, model.STATUS_AWAY) + checkNotifyProp(t, user, model.CHANNEL_MENTIONS_NOTIFY_PROP, "false") + checkNotifyProp(t, user, model.COMMENTS_NOTIFY_PROP, model.COMMENTS_NOTIFY_ANY) + checkNotifyProp(t, user, model.MENTION_KEYS_NOTIFY_PROP, "misc") + // Check Notify Props get set on *create* user. username = model.NewId() data = UserImportData{ @@ -1318,7 +1373,6 @@ func TestImportImportUser(t *testing.T) { assert.True(t, channelMember.SchemeUser) assert.Equal(t, "", channelMember.ExplicitRoles) - // Test importing deleted user with a valid team & valid channel name in apply mode. username = model.NewId() deleteAt := model.GetMillis() @@ -1389,7 +1443,7 @@ func TestImportUserDefaultNotifyProps(t *testing.T) { assert.Equal(t, "false", val) // Check all the other notify props are set to their default values. - comparisonUser := model.User{} + comparisonUser := model.User{Username: user.Username} comparisonUser.SetDefaultNotifications() for key, expectedValue := range comparisonUser.NotifyProps {