[MM-16501] Delete user from Bot table when deleting user with… (#11425)
* 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.
Этот коммит содержится в:
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
Ссылка в новой задаче
Block a user