MM 15185 - Migrate "WebHook.GetOutgoingByChannel" to Sync by default (#10704)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
6d336e0666
Коммит
4f7f7070c0
@@ -793,13 +793,20 @@ func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelId s
|
||||
|
||||
func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppError {
|
||||
ihc := make(chan store.StoreResult, 1)
|
||||
ohc := a.Srv.Store.Webhook().GetOutgoingByChannel(channel.Id, -1, -1)
|
||||
ohc := make(chan store.StoreResult, 1)
|
||||
|
||||
go func() {
|
||||
webhooks, err := a.Srv.Store.Webhook().GetIncomingByChannel(channel.Id)
|
||||
ihc <- store.StoreResult{Data: webhooks, Err: err}
|
||||
close(ihc)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
outgoingHooks, err := a.Srv.Store.Webhook().GetOutgoingByChannel(channel.Id, -1, -1)
|
||||
ohc <- store.StoreResult{Data: outgoingHooks, Err: err}
|
||||
close(ohc)
|
||||
}()
|
||||
|
||||
var user *model.User
|
||||
if userId != "" {
|
||||
var err *model.AppError
|
||||
|
||||
@@ -503,11 +503,7 @@ func (a *App) GetOutgoingWebhooksForChannelPage(channelId string, page, perPage
|
||||
return nil, model.NewAppError("GetOutgoingWebhooksForChannelPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Webhook().GetOutgoingByChannel(channelId, page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.OutgoingWebhook), nil
|
||||
}
|
||||
return a.Srv.Store.Webhook().GetOutgoingByChannel(channelId, page*perPage, perPage)
|
||||
}
|
||||
|
||||
func (a *App) GetOutgoingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
|
||||
@@ -242,23 +242,21 @@ func (s SqlWebhookStore) GetOutgoingList(offset, limit int) ([]*model.OutgoingWe
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByChannel(channelId string, offset, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var webhooks []*model.OutgoingWebhook
|
||||
func (s SqlWebhookStore) GetOutgoingByChannel(channelId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
var webhooks []*model.OutgoingWebhook
|
||||
|
||||
query := ""
|
||||
if limit < 0 || offset < 0 {
|
||||
query = "SELECT * FROM OutgoingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0"
|
||||
} else {
|
||||
query = "SELECT * FROM OutgoingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0 LIMIT :Limit OFFSET :Offset"
|
||||
}
|
||||
query := ""
|
||||
if limit < 0 || offset < 0 {
|
||||
query = "SELECT * FROM OutgoingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0"
|
||||
} else {
|
||||
query = "SELECT * FROM OutgoingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0 LIMIT :Limit OFFSET :Offset"
|
||||
}
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, query, map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}); err != nil {
|
||||
result.Err = model.NewAppError("SqlWebhookStore.GetOutgoingByChannel", "store.sql_webhooks.get_outgoing_by_channel.app_error", nil, "channelId="+channelId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if _, err := s.GetReplica().Select(&webhooks, query, map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}); err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetOutgoingByChannel", "store.sql_webhooks.get_outgoing_by_channel.app_error", nil, "channelId="+channelId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
result.Data = webhooks
|
||||
})
|
||||
return webhooks, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByTeam(teamId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
|
||||
@@ -395,8 +395,8 @@ type WebhookStore interface {
|
||||
|
||||
SaveOutgoing(webhook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoing(id string) (*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingByChannel(channelId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingList(offset, limit int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingByChannel(channelId string, offset, limit int) StoreChannel
|
||||
GetOutgoingByTeam(teamId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
DeleteOutgoing(webhookId string, time int64) *model.AppError
|
||||
PermanentDeleteOutgoingByChannel(channelId string) *model.AppError
|
||||
|
||||
@@ -6,7 +6,6 @@ package mocks
|
||||
|
||||
import mock "github.com/stretchr/testify/mock"
|
||||
import model "github.com/mattermost/mattermost-server/model"
|
||||
import store "github.com/mattermost/mattermost-server/store"
|
||||
|
||||
// WebhookStore is an autogenerated mock type for the WebhookStore type
|
||||
type WebhookStore struct {
|
||||
@@ -222,19 +221,28 @@ func (_m *WebhookStore) GetOutgoing(id string) (*model.OutgoingWebhook, *model.A
|
||||
}
|
||||
|
||||
// GetOutgoingByChannel provides a mock function with given fields: channelId, offset, limit
|
||||
func (_m *WebhookStore) GetOutgoingByChannel(channelId string, offset int, limit int) store.StoreChannel {
|
||||
func (_m *WebhookStore) GetOutgoingByChannel(channelId string, offset int, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
ret := _m.Called(channelId, offset, limit)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) store.StoreChannel); ok {
|
||||
var r0 []*model.OutgoingWebhook
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) []*model.OutgoingWebhook); ok {
|
||||
r0 = rf(channelId, offset, limit)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).([]*model.OutgoingWebhook)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok {
|
||||
r1 = rf(channelId, offset, limit)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetOutgoingByTeam provides a mock function with given fields: teamId, offset, limit
|
||||
|
||||
@@ -371,18 +371,18 @@ func testWebhookStoreGetOutgoingByChannel(t *testing.T, ss store.Store) {
|
||||
|
||||
o1, _ = ss.Webhook().SaveOutgoing(o1)
|
||||
|
||||
if r1 := <-ss.Webhook().GetOutgoingByChannel(o1.ChannelId, 0, 100); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
if r1, err := ss.Webhook().GetOutgoingByChannel(o1.ChannelId, 0, 100); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
|
||||
if r1[0].CreateAt != o1.CreateAt {
|
||||
t.Fatal("invalid returned webhook")
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-ss.Webhook().GetOutgoingByChannel("123", -1, -1); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if result, err := ss.Webhook().GetOutgoingByChannel("123", -1, -1); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
|
||||
if len(result) != 0 {
|
||||
t.Fatal("no webhooks should have returned")
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user