mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
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
This commit is contained in:
@@ -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("")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user