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 {
|
func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppError {
|
||||||
ihc := make(chan store.StoreResult, 1)
|
ihc := make(chan store.StoreResult, 1)
|
||||||
ohc := a.Srv.Store.Webhook().GetOutgoingByChannel(channel.Id, -1, -1)
|
ohc := make(chan store.StoreResult, 1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
webhooks, err := a.Srv.Store.Webhook().GetIncomingByChannel(channel.Id)
|
webhooks, err := a.Srv.Store.Webhook().GetIncomingByChannel(channel.Id)
|
||||||
ihc <- store.StoreResult{Data: webhooks, Err: err}
|
ihc <- store.StoreResult{Data: webhooks, Err: err}
|
||||||
close(ihc)
|
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
|
var user *model.User
|
||||||
if userId != "" {
|
if userId != "" {
|
||||||
var err *model.AppError
|
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)
|
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 a.Srv.Store.Webhook().GetOutgoingByChannel(channelId, page*perPage, perPage)
|
||||||
return nil, result.Err
|
|
||||||
} else {
|
|
||||||
return result.Data.([]*model.OutgoingWebhook), nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetOutgoingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
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
|
return webhooks, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlWebhookStore) GetOutgoingByChannel(channelId string, offset, limit int) store.StoreChannel {
|
func (s SqlWebhookStore) GetOutgoingByChannel(channelId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
var webhooks []*model.OutgoingWebhook
|
||||||
var webhooks []*model.OutgoingWebhook
|
|
||||||
|
|
||||||
query := ""
|
query := ""
|
||||||
if limit < 0 || offset < 0 {
|
if limit < 0 || offset < 0 {
|
||||||
query = "SELECT * FROM OutgoingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0"
|
query = "SELECT * FROM OutgoingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0"
|
||||||
} else {
|
} else {
|
||||||
query = "SELECT * FROM OutgoingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0 LIMIT :Limit OFFSET :Offset"
|
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 {
|
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)
|
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) {
|
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)
|
SaveOutgoing(webhook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||||
GetOutgoing(id string) (*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)
|
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)
|
GetOutgoingByTeam(teamId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||||
DeleteOutgoing(webhookId string, time int64) *model.AppError
|
DeleteOutgoing(webhookId string, time int64) *model.AppError
|
||||||
PermanentDeleteOutgoingByChannel(channelId string) *model.AppError
|
PermanentDeleteOutgoingByChannel(channelId string) *model.AppError
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ package mocks
|
|||||||
|
|
||||||
import mock "github.com/stretchr/testify/mock"
|
import mock "github.com/stretchr/testify/mock"
|
||||||
import model "github.com/mattermost/mattermost-server/model"
|
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
|
// WebhookStore is an autogenerated mock type for the WebhookStore type
|
||||||
type WebhookStore struct {
|
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
|
// 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)
|
ret := _m.Called(channelId, offset, limit)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.OutgoingWebhook
|
||||||
if rf, ok := ret.Get(0).(func(string, int, int) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, int, int) []*model.OutgoingWebhook); ok {
|
||||||
r0 = rf(channelId, offset, limit)
|
r0 = rf(channelId, offset, limit)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
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
|
// 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)
|
o1, _ = ss.Webhook().SaveOutgoing(o1)
|
||||||
|
|
||||||
if r1 := <-ss.Webhook().GetOutgoingByChannel(o1.ChannelId, 0, 100); r1.Err != nil {
|
if r1, err := ss.Webhook().GetOutgoingByChannel(o1.ChannelId, 0, 100); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
|
if r1[0].CreateAt != o1.CreateAt {
|
||||||
t.Fatal("invalid returned webhook")
|
t.Fatal("invalid returned webhook")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-ss.Webhook().GetOutgoingByChannel("123", -1, -1); result.Err != nil {
|
if result, err := ss.Webhook().GetOutgoingByChannel("123", -1, -1); err != nil {
|
||||||
t.Fatal(result.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
|
if len(result) != 0 {
|
||||||
t.Fatal("no webhooks should have returned")
|
t.Fatal("no webhooks should have returned")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user