[MM-17741] when converting bot to a user set the correct email. (#11879)

* Send notifications when bot converted to user

* Revert notification sending from CLI.
If user is a bot, set email to CLI email, not the previous email because
previous email <botname>@localhost

* Add comment describing the additional if statement

* Rewording

* remove duplicate word

* Update Comment

* Add tests for bots.  In both cases of RequireEmailVerification settings,
the Email should be set to the value passed to the UpdateUser function
and the previous faked localhost email ignored
Этот коммит содержится в:
jfrerich
2019-08-16 09:37:22 -05:00
коммит произвёл Christopher Speller
родитель 7e7447eff7
Коммит baedcc856f
2 изменённых файлов: 38 добавлений и 1 удалений

Просмотреть файл

@@ -1116,7 +1116,13 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
return nil, model.NewAppError("UpdateUser", "store.sql_user.update.email_taken.app_error", nil, "user_id="+user.Id, http.StatusBadRequest)
}
user.Email = prev.Email
// When a bot is created, prev.Email will be an autogenerated faked email,
// which will not match a CLI email input during bot to user conversions.
// To update a bot users email, do not set the email to the faked email
// stored in prev.Email. Allow using the email defined in the CLI
if !user.IsBot {
user.Email = prev.Email
}
}
userUpdate, err := a.Srv.Store.User().Update(user, false)

Просмотреть файл

@@ -393,6 +393,22 @@ func TestUpdateUserEmail(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, newEmail, user2.Email)
assert.True(t, user2.EmailVerified)
// Create bot user
botuser := model.User{
Email: "botuser@localhost",
Username: model.NewId(),
IsBot: true,
}
_, err = th.App.Srv.Store.User().Save(&botuser)
assert.Nil(t, err)
newBotEmail := th.MakeEmail()
botuser.Email = newBotEmail
botuser2, err := th.App.UpdateUser(&botuser, false)
assert.Nil(t, err)
assert.Equal(t, botuser2.Email, newBotEmail)
})
t.Run("RequireVerificationAlreadyUsedEmail", func(t *testing.T) {
@@ -420,6 +436,21 @@ func TestUpdateUserEmail(t *testing.T) {
user2, err := th.App.UpdateUser(user, false)
assert.Nil(t, err)
assert.Equal(t, newEmail, user2.Email)
// Create bot user
botuser := model.User{
Email: "botuser@localhost",
Username: model.NewId(),
IsBot: true,
}
_, err = th.App.Srv.Store.User().Save(&botuser)
assert.Nil(t, err)
newBotEmail := th.MakeEmail()
botuser.Email = newBotEmail
botuser2, err := th.App.UpdateUser(&botuser, false)
assert.Nil(t, err)
assert.Equal(t, botuser2.Email, newBotEmail)
})
}