From b2706507e60a344a78a792433ddcd6f6cdad4e92 Mon Sep 17 00:00:00 2001 From: jfrerich Date: Fri, 19 Jul 2019 10:16:02 -0500 Subject: [PATCH] =?UTF-8?q?[MM-16501]=20Delete=20user=20from=20Bot=20table?= =?UTF-8?q?=20when=20deleting=20user=20with=E2=80=A6=20(#11425)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add bot store PermanentDelete() method to PermanentDeleteUser method * Test the that bot is deleted from bots table after user is deleted from users table. Notes GetBots() method on bots store cannot be used to get and compare bots from before and after the PermanentDeleteUser() call. Had to directly query the Bots table. --- app/user.go | 4 ++++ app/user_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/app/user.go b/app/user.go index b9f90bb28b..680189aedf 100644 --- a/app/user.go +++ b/app/user.go @@ -1426,6 +1426,10 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError { return err } + if err := a.Srv.Store.Bot().PermanentDelete(user.Id); err != nil { + return err + } + infos, err := a.Srv.Store.FileInfo().GetForUser(user.Id) if err != nil { mlog.Warn("Error getting file list for user from FileInfoStore") diff --git a/app/user_test.go b/app/user_test.go index dc001bb0e5..ce0006e3b0 100644 --- a/app/user_test.go +++ b/app/user_test.go @@ -636,6 +636,32 @@ func TestPermanentDeleteUser(t *testing.T) { t.Fatal("Unable to upload file") } + bot, err := th.App.CreateBot(&model.Bot{ + Username: "botname", + Description: "a bot", + OwnerId: model.NewId(), + }) + assert.Nil(t, err) + + var bots1 []*model.Bot + var bots2 []*model.Bot + + sqlSupplier := mainHelper.GetSqlSupplier() + _, err1 := sqlSupplier.GetMaster().Select(&bots1, "SELECT * FROM Bots") + assert.Nil(t, err1) + assert.Equal(t, 1, len(bots1)) + + // test that bot is deleted from bots table + retUser1, err := th.App.GetUser(bot.UserId) + assert.Nil(t, err) + + err = th.App.PermanentDeleteUser(retUser1) + assert.Nil(t, err) + + _, err1 = sqlSupplier.GetMaster().Select(&bots2, "SELECT * FROM Bots") + assert.Nil(t, err1) + assert.Equal(t, 0, len(bots2)) + err = th.App.PermanentDeleteUser(th.BasicUser) if err != nil { t.Log(err)