MM 15119 : migrates the "WebHook.PermanentDeleteIncomingByUser" to Sync by default. (#10705)

* cherry commit for PermanentDeleteIncomingByUser and generate store mocks

* go fmt the code
This commit is contained in:
Puneeth Reddy
2019-04-26 08:34:29 -07:00
committed by Miguel de la Cruz
parent 3989b90a91
commit 2f237d68b7
5 changed files with 16 additions and 17 deletions

View File

@@ -1411,8 +1411,8 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
return result.Err
}
if result := <-a.Srv.Store.Webhook().PermanentDeleteIncomingByUser(user.Id); result.Err != nil {
return result.Err
if err := a.Srv.Store.Webhook().PermanentDeleteIncomingByUser(user.Id); err != nil {
return err
}
if result := <-a.Srv.Store.Webhook().PermanentDeleteOutgoingByUser(user.Id); result.Err != nil {

View File

@@ -153,15 +153,14 @@ func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) store.Stor
})
}
func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
_, err := s.GetMaster().Exec("DELETE FROM IncomingWebhooks WHERE UserId = :UserId", map[string]interface{}{"UserId": userId})
if err != nil {
result.Err = model.NewAppError("SqlWebhookStore.DeleteIncomingByUser", "store.sql_webhooks.permanent_delete_incoming_by_user.app_error", nil, "id="+userId+", err="+err.Error(), http.StatusInternalServerError)
}
func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) *model.AppError {
_, err := s.GetMaster().Exec("DELETE FROM IncomingWebhooks WHERE UserId = :UserId", map[string]interface{}{"UserId": userId})
if err != nil {
return model.NewAppError("SqlWebhookStore.DeleteIncomingByUser", "store.sql_webhooks.permanent_delete_incoming_by_user.app_error", nil, "id="+userId+", err="+err.Error(), http.StatusInternalServerError)
}
s.ClearCaches()
})
s.ClearCaches()
return nil
}
func (s SqlWebhookStore) PermanentDeleteIncomingByChannel(channelId string) *model.AppError {

View File

@@ -385,7 +385,7 @@ type WebhookStore interface {
GetIncomingByChannel(channelId string) ([]*model.IncomingWebhook, *model.AppError)
DeleteIncoming(webhookId string, time int64) StoreChannel
PermanentDeleteIncomingByChannel(channelId string) *model.AppError
PermanentDeleteIncomingByUser(userId string) StoreChannel
PermanentDeleteIncomingByUser(userId string) *model.AppError
SaveOutgoing(webhook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
GetOutgoing(id string) (*model.OutgoingWebhook, *model.AppError)

View File

@@ -293,15 +293,15 @@ func (_m *WebhookStore) PermanentDeleteIncomingByChannel(channelId string) *mode
}
// PermanentDeleteIncomingByUser provides a mock function with given fields: userId
func (_m *WebhookStore) PermanentDeleteIncomingByUser(userId string) store.StoreChannel {
func (_m *WebhookStore) PermanentDeleteIncomingByUser(userId string) *model.AppError {
ret := _m.Called(userId)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
r0 = rf(userId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).(*model.AppError)
}
}

View File

@@ -253,8 +253,8 @@ func testWebhookStoreDeleteIncomingByUser(t *testing.T, ss store.Store) {
t.Fatal("invalid returned webhook")
}
if r2 := <-ss.Webhook().PermanentDeleteIncomingByUser(o1.UserId); r2.Err != nil {
t.Fatal(r2.Err)
if err = ss.Webhook().PermanentDeleteIncomingByUser(o1.UserId); err != nil {
t.Fatal(err)
}
if _, err = ss.Webhook().GetIncoming(o1.Id, true); err == nil {