[MM-15117] Migrate "WebHook.UpdateIncoming" to Sync by default (#10637)
* SyncStore: Migrate Webhooks.UpdateIncoming method to Sync * Changes requested by @jespino
Этот коммит содержится в:
коммит произвёл
Miguel de la Cruz
родитель
6cc36ab176
Коммит
17092e7e48
@@ -353,12 +353,12 @@ func (a *App) UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook)
|
|||||||
updatedHook.TeamId = oldHook.TeamId
|
updatedHook.TeamId = oldHook.TeamId
|
||||||
updatedHook.DeleteAt = oldHook.DeleteAt
|
updatedHook.DeleteAt = oldHook.DeleteAt
|
||||||
|
|
||||||
if result := <-a.Srv.Store.Webhook().UpdateIncoming(updatedHook); result.Err != nil {
|
newWebhook, err := a.Srv.Store.Webhook().UpdateIncoming(updatedHook)
|
||||||
return nil, result.Err
|
if err != nil {
|
||||||
} else {
|
return nil, err
|
||||||
a.InvalidateCacheForWebhook(oldHook.Id)
|
|
||||||
return result.Data.(*model.IncomingWebhook), nil
|
|
||||||
}
|
}
|
||||||
|
a.InvalidateCacheForWebhook(oldHook.Id)
|
||||||
|
return newWebhook, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeleteIncomingWebhook(hookId string) *model.AppError {
|
func (a *App) DeleteIncomingWebhook(hookId string) *model.AppError {
|
||||||
|
|||||||
@@ -408,7 +408,7 @@ func moveChannel(a *app.App, team *model.Team, channel *model.Channel, user *mod
|
|||||||
for _, webhook := range incomingWebhooks {
|
for _, webhook := range incomingWebhooks {
|
||||||
if webhook.ChannelId == channel.Id {
|
if webhook.ChannelId == channel.Id {
|
||||||
webhook.TeamId = team.Id
|
webhook.TeamId = team.Id
|
||||||
if result := <-a.Srv.Store.Webhook().UpdateIncoming(webhook); result.Err != nil {
|
if _, err := a.Srv.Store.Webhook().UpdateIncoming(webhook); err != nil {
|
||||||
CommandPrintErrorln("Failed to move incoming webhook '" + webhook.Id + "' to new team.")
|
CommandPrintErrorln("Failed to move incoming webhook '" + webhook.Id + "' to new team.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,16 +109,13 @@ func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) store.Stor
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlWebhookStore) UpdateIncoming(hook *model.IncomingWebhook) store.StoreChannel {
|
func (s SqlWebhookStore) UpdateIncoming(hook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
hook.UpdateAt = model.GetMillis()
|
||||||
hook.UpdateAt = model.GetMillis()
|
|
||||||
|
|
||||||
if _, err := s.GetMaster().Update(hook); err != nil {
|
if _, err := s.GetMaster().Update(hook); err != nil {
|
||||||
result.Err = model.NewAppError("SqlWebhookStore.UpdateIncoming", "store.sql_webhooks.update_incoming.app_error", nil, "id="+hook.Id+", "+err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlWebhookStore.UpdateIncoming", "store.sql_webhooks.update_incoming.app_error", nil, "id="+hook.Id+", "+err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
}
|
||||||
result.Data = hook
|
return hook, nil
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlWebhookStore) GetIncoming(id string, allowFromCache bool) (*model.IncomingWebhook, *model.AppError) {
|
func (s SqlWebhookStore) GetIncoming(id string, allowFromCache bool) (*model.IncomingWebhook, *model.AppError) {
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ type WebhookStore interface {
|
|||||||
GetIncoming(id string, allowFromCache bool) (*model.IncomingWebhook, *model.AppError)
|
GetIncoming(id string, allowFromCache bool) (*model.IncomingWebhook, *model.AppError)
|
||||||
GetIncomingList(offset, limit int) StoreChannel
|
GetIncomingList(offset, limit int) StoreChannel
|
||||||
GetIncomingByTeam(teamId string, offset, limit int) StoreChannel
|
GetIncomingByTeam(teamId string, offset, limit int) StoreChannel
|
||||||
UpdateIncoming(webhook *model.IncomingWebhook) StoreChannel
|
UpdateIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError)
|
||||||
GetIncomingByChannel(channelId string) StoreChannel
|
GetIncomingByChannel(channelId string) StoreChannel
|
||||||
DeleteIncoming(webhookId string, time int64) StoreChannel
|
DeleteIncoming(webhookId string, time int64) StoreChannel
|
||||||
PermanentDeleteIncomingByChannel(channelId string) StoreChannel
|
PermanentDeleteIncomingByChannel(channelId string) StoreChannel
|
||||||
|
|||||||
@@ -321,19 +321,28 @@ func (_m *WebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) store.Store
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateIncoming provides a mock function with given fields: webhook
|
// UpdateIncoming provides a mock function with given fields: webhook
|
||||||
func (_m *WebhookStore) UpdateIncoming(webhook *model.IncomingWebhook) store.StoreChannel {
|
func (_m *WebhookStore) UpdateIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) {
|
||||||
ret := _m.Called(webhook)
|
ret := _m.Called(webhook)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.IncomingWebhook
|
||||||
if rf, ok := ret.Get(0).(func(*model.IncomingWebhook) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(*model.IncomingWebhook) *model.IncomingWebhook); ok {
|
||||||
r0 = rf(webhook)
|
r0 = rf(webhook)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.IncomingWebhook)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(*model.IncomingWebhook) *model.AppError); ok {
|
||||||
|
r1 = rf(webhook)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateOutgoing provides a mock function with given fields: hook
|
// UpdateOutgoing provides a mock function with given fields: hook
|
||||||
|
|||||||
@@ -56,17 +56,17 @@ func testWebhookStoreUpdateIncoming(t *testing.T, ss store.Store) {
|
|||||||
o1.DisplayName = "TestHook"
|
o1.DisplayName = "TestHook"
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
|
||||||
if result := (<-ss.Webhook().UpdateIncoming(o1)); result.Err != nil {
|
webhook, err := ss.Webhook().UpdateIncoming(o1)
|
||||||
t.Fatal("updation of incoming hook failed", result.Err)
|
require.Nil(t, err)
|
||||||
} else {
|
|
||||||
if result.Data.(*model.IncomingWebhook).UpdateAt == previousUpdatedAt {
|
|
||||||
t.Fatal("should have updated the UpdatedAt of the hook")
|
|
||||||
}
|
|
||||||
|
|
||||||
if result.Data.(*model.IncomingWebhook).DisplayName != "TestHook" {
|
if webhook.UpdateAt == previousUpdatedAt {
|
||||||
t.Fatal("display name is not updated")
|
t.Fatal("should have updated the UpdatedAt of the hook")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if webhook.DisplayName != "TestHook" {
|
||||||
|
t.Fatal("display name is not updated")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testWebhookStoreGetIncoming(t *testing.T, ss store.Store) {
|
func testWebhookStoreGetIncoming(t *testing.T, ss store.Store) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user