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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fdf9c3e218
Коммит
62a94d53f4
@@ -446,6 +446,8 @@ func (a *App) ImportUser(data *UserImportData, dryRun bool) *model.AppError {
|
|||||||
user.AddNotifyProp(model.MENTION_KEYS_NOTIFY_PROP, *data.NotifyProps.MentionKeys)
|
user.AddNotifyProp(model.MENTION_KEYS_NOTIFY_PROP, *data.NotifyProps.MentionKeys)
|
||||||
hasNotifyPropsChanged = true
|
hasNotifyPropsChanged = true
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
user.UpdateMentionKeysFromUsername("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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_TUTORIAL_STEPS, user.Id, *data.TutorialStep)
|
||||||
checkPreference(t, th.App, user.Id, model.PREFERENCE_CATEGORY_NOTIFICATIONS, model.PREFERENCE_NAME_EMAIL_INTERVAL, "3600")
|
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{
|
data.NotifyProps = &UserNotifyPropsImportData{
|
||||||
Desktop: ptrStr(model.USER_NOTIFY_ALL),
|
Desktop: ptrStr(model.USER_NOTIFY_ALL),
|
||||||
DesktopSound: ptrStr("true"),
|
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.COMMENTS_NOTIFY_PROP, model.COMMENTS_NOTIFY_ROOT)
|
||||||
checkNotifyProp(t, user, model.MENTION_KEYS_NOTIFY_PROP, "valid,misc")
|
checkNotifyProp(t, user, model.MENTION_KEYS_NOTIFY_PROP, "valid,misc")
|
||||||
|
|
||||||
// Change Notify Props
|
// Change Notify Props with mention keys
|
||||||
data.NotifyProps = &UserNotifyPropsImportData{
|
data.NotifyProps = &UserNotifyPropsImportData{
|
||||||
Desktop: ptrStr(model.USER_NOTIFY_MENTION),
|
Desktop: ptrStr(model.USER_NOTIFY_MENTION),
|
||||||
DesktopSound: ptrStr("false"),
|
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.COMMENTS_NOTIFY_PROP, model.COMMENTS_NOTIFY_ANY)
|
||||||
checkNotifyProp(t, user, model.MENTION_KEYS_NOTIFY_PROP, "misc")
|
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.
|
// Check Notify Props get set on *create* user.
|
||||||
username = model.NewId()
|
username = model.NewId()
|
||||||
data = UserImportData{
|
data = UserImportData{
|
||||||
@@ -1318,7 +1373,6 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
assert.True(t, channelMember.SchemeUser)
|
assert.True(t, channelMember.SchemeUser)
|
||||||
assert.Equal(t, "", channelMember.ExplicitRoles)
|
assert.Equal(t, "", channelMember.ExplicitRoles)
|
||||||
|
|
||||||
|
|
||||||
// Test importing deleted user with a valid team & valid channel name in apply mode.
|
// Test importing deleted user with a valid team & valid channel name in apply mode.
|
||||||
username = model.NewId()
|
username = model.NewId()
|
||||||
deleteAt := model.GetMillis()
|
deleteAt := model.GetMillis()
|
||||||
@@ -1389,7 +1443,7 @@ func TestImportUserDefaultNotifyProps(t *testing.T) {
|
|||||||
assert.Equal(t, "false", val)
|
assert.Equal(t, "false", val)
|
||||||
|
|
||||||
// Check all the other notify props are set to their default values.
|
// Check all the other notify props are set to their default values.
|
||||||
comparisonUser := model.User{}
|
comparisonUser := model.User{Username: user.Username}
|
||||||
comparisonUser.SetDefaultNotifications()
|
comparisonUser.SetDefaultNotifications()
|
||||||
|
|
||||||
for key, expectedValue := range comparisonUser.NotifyProps {
|
for key, expectedValue := range comparisonUser.NotifyProps {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user