From f3716caba9d6b55520e8431047db4b87b6f9f88f Mon Sep 17 00:00:00 2001 From: jfrerich Date: Thu, 31 Oct 2019 11:25:19 -0500 Subject: [PATCH] [MM-18331] When patching a bot send websocket notification (#12373) * When patching a bot, perform these two additional steps: 1. Update the user.UpdateAt value for the user/bot. 2. send the websocket event so all clients know a user update has occured. This will tell clients to update the displayname * Add check for UpdateAt. Check that createdBot.UpdateAt is not equal to patchedBot.UpdateAt * re-add unintentional empty line delete in previous commit * Don't create a fake updateAt time. Let the Update() method handle the change. User the returned updateUser for sending updated user event --- app/bot.go | 7 ++++++- app/bot_test.go | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/bot.go b/app/bot.go index 0691e127cc..1e9561488f 100644 --- a/app/bot.go +++ b/app/bot.go @@ -77,10 +77,15 @@ func (a *App) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, user.Username = patchedUser.Username user.Email = patchedUser.Email user.FirstName = patchedUser.FirstName - if _, err := a.Srv.Store.User().Update(user, true); err != nil { + + userUpdate, err := a.Srv.Store.User().Update(user, true) + if err != nil { return nil, err } + ruser := userUpdate.New + a.sendUpdatedUserEvent(*ruser) + return a.Srv.Store.Bot().Update(bot) } diff --git a/app/bot_test.go b/app/bot_test.go index b8a563047a..11c91b0a00 100644 --- a/app/bot_test.go +++ b/app/bot_test.go @@ -172,6 +172,9 @@ func TestPatchBot(t *testing.T) { patchedBot, err := th.App.PatchBot(createdBot.UserId, botPatch) require.Nil(t, err) + // patchedBot should create a new .UpdateAt time + require.NotEqual(t, createdBot.UpdateAt, patchedBot.UpdateAt) + createdBot.Username = "username2" createdBot.DisplayName = "updated bot" createdBot.Description = "an updated bot"