PLT-7 adding loc db calls for webhooks table

Этот коммит содержится в:
=Corey Hulen
2016-01-20 08:44:05 -06:00
родитель 5b2ec62347
Коммит ef11df7532
8 изменённых файлов: 88 добавлений и 86 удалений

Просмотреть файл

@@ -593,8 +593,8 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
sc := Srv.Store.Channel().Get(id) sc := Srv.Store.Channel().Get(id)
scm := Srv.Store.Channel().GetMember(id, c.Session.UserId) scm := Srv.Store.Channel().GetMember(id, c.Session.UserId)
uc := Srv.Store.User().Get(c.Session.UserId) uc := Srv.Store.User().Get(c.Session.UserId)
ihc := Srv.Store.Webhook().GetIncomingByChannel(id) ihc := Srv.Store.Webhook().GetIncomingByChannel(c.T, id)
ohc := Srv.Store.Webhook().GetOutgoingByChannel(id) ohc := Srv.Store.Webhook().GetOutgoingByChannel(c.T, id)
if cresult := <-sc; cresult.Err != nil { if cresult := <-sc; cresult.Err != nil {
c.Err = cresult.Err c.Err = cresult.Err
@@ -643,7 +643,7 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
now := model.GetMillis() now := model.GetMillis()
for _, hook := range incomingHooks { for _, hook := range incomingHooks {
go func() { go func() {
if result := <-Srv.Store.Webhook().DeleteIncoming(hook.Id, now); result.Err != nil { if result := <-Srv.Store.Webhook().DeleteIncoming(c.T, hook.Id, now); result.Err != nil {
l4g.Error("Encountered error deleting incoming webhook, id=" + hook.Id) l4g.Error("Encountered error deleting incoming webhook, id=" + hook.Id)
} }
}() }()
@@ -651,7 +651,7 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
for _, hook := range outgoingHooks { for _, hook := range outgoingHooks {
go func() { go func() {
if result := <-Srv.Store.Webhook().DeleteOutgoing(hook.Id, now); result.Err != nil { if result := <-Srv.Store.Webhook().DeleteOutgoing(c.T, hook.Id, now); result.Err != nil {
l4g.Error("Encountered error deleting outgoing webhook, id=" + hook.Id) l4g.Error("Encountered error deleting outgoing webhook, id=" + hook.Id)
} }
}() }()

Просмотреть файл

@@ -310,7 +310,7 @@ func handleWebhookEventsAndForget(c *Context, post *model.Post, team *model.Team
return return
} }
hchan := Srv.Store.Webhook().GetOutgoingByTeam(c.Session.TeamId) hchan := Srv.Store.Webhook().GetOutgoingByTeam(c.T, c.Session.TeamId)
hooks := []*model.OutgoingWebhook{} hooks := []*model.OutgoingWebhook{}

Просмотреть файл

@@ -1444,11 +1444,11 @@ func PermanentDeleteUser(c *Context, user *model.User) *model.AppError {
return result.Err return result.Err
} }
if result := <-Srv.Store.Webhook().PermanentDeleteIncomingByUser(user.Id); result.Err != nil { if result := <-Srv.Store.Webhook().PermanentDeleteIncomingByUser(c.T, user.Id); result.Err != nil {
return result.Err return result.Err
} }
if result := <-Srv.Store.Webhook().PermanentDeleteOutgoingByUser(user.Id); result.Err != nil { if result := <-Srv.Store.Webhook().PermanentDeleteOutgoingByUser(c.T, user.Id); result.Err != nil {
return result.Err return result.Err
} }

Просмотреть файл

@@ -62,7 +62,7 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
} }
} }
if result := <-Srv.Store.Webhook().SaveIncoming(hook); result.Err != nil { if result := <-Srv.Store.Webhook().SaveIncoming(c.T, hook); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return return
} else { } else {
@@ -89,7 +89,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if result := <-Srv.Store.Webhook().GetIncoming(id); result.Err != nil { if result := <-Srv.Store.Webhook().GetIncoming(c.T, id); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return return
} else { } else {
@@ -100,7 +100,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
} }
} }
if err := (<-Srv.Store.Webhook().DeleteIncoming(id, model.GetMillis())).Err; err != nil { if err := (<-Srv.Store.Webhook().DeleteIncoming(c.T, id, model.GetMillis())).Err; err != nil {
c.Err = err c.Err = err
return return
} }
@@ -116,7 +116,7 @@ func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if result := <-Srv.Store.Webhook().GetIncomingByUser(c.Session.UserId); result.Err != nil { if result := <-Srv.Store.Webhook().GetIncomingByUser(c.T, c.Session.UserId); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return return
} else { } else {
@@ -171,7 +171,7 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if result := <-Srv.Store.Webhook().SaveOutgoing(hook); result.Err != nil { if result := <-Srv.Store.Webhook().SaveOutgoing(c.T, hook); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return return
} else { } else {
@@ -188,7 +188,7 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if result := <-Srv.Store.Webhook().GetOutgoingByCreator(c.Session.UserId); result.Err != nil { if result := <-Srv.Store.Webhook().GetOutgoingByCreator(c.T, c.Session.UserId); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return return
} else { } else {
@@ -214,7 +214,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if result := <-Srv.Store.Webhook().GetOutgoing(id); result.Err != nil { if result := <-Srv.Store.Webhook().GetOutgoing(c.T, id); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return return
} else { } else {
@@ -225,7 +225,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
} }
} }
if err := (<-Srv.Store.Webhook().DeleteOutgoing(id, model.GetMillis())).Err; err != nil { if err := (<-Srv.Store.Webhook().DeleteOutgoing(c.T, id, model.GetMillis())).Err; err != nil {
c.Err = err c.Err = err
return return
} }
@@ -252,7 +252,7 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request)
} }
var hook *model.OutgoingWebhook var hook *model.OutgoingWebhook
if result := <-Srv.Store.Webhook().GetOutgoing(id); result.Err != nil { if result := <-Srv.Store.Webhook().GetOutgoing(c.T, id); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return return
} else { } else {
@@ -267,7 +267,7 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request)
hook.Token = model.NewId() hook.Token = model.NewId()
if result := <-Srv.Store.Webhook().UpdateOutgoing(hook); result.Err != nil { if result := <-Srv.Store.Webhook().UpdateOutgoing(c.T, hook); result.Err != nil {
c.Err = result.Err c.Err = result.Err
return return
} else { } else {

Просмотреть файл

@@ -5,6 +5,7 @@ package store
import ( import (
"github.com/mattermost/platform/model" "github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
) )
type SqlWebhookStore struct { type SqlWebhookStore struct {
@@ -43,7 +44,7 @@ func (s SqlWebhookStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_outgoing_webhook_team_id", "OutgoingWebhooks", "TeamId") s.CreateIndexIfNotExists("idx_outgoing_webhook_team_id", "OutgoingWebhooks", "TeamId")
} }
func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) StoreChannel { func (s SqlWebhookStore) SaveIncoming(T goi18n.TranslateFunc, webhook *model.IncomingWebhook) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -77,7 +78,7 @@ func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) StoreChann
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) GetIncoming(id string) StoreChannel { func (s SqlWebhookStore) GetIncoming(T goi18n.TranslateFunc, id string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -98,7 +99,7 @@ func (s SqlWebhookStore) GetIncoming(id string) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) StoreChannel { func (s SqlWebhookStore) DeleteIncoming(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -116,7 +117,7 @@ func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) StoreChann
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) StoreChannel { func (s SqlWebhookStore) PermanentDeleteIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -134,7 +135,7 @@ func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) StoreChann
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) GetIncomingByUser(userId string) StoreChannel { func (s SqlWebhookStore) GetIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -155,7 +156,7 @@ func (s SqlWebhookStore) GetIncomingByUser(userId string) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) GetIncomingByChannel(channelId string) StoreChannel { func (s SqlWebhookStore) GetIncomingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -176,7 +177,7 @@ func (s SqlWebhookStore) GetIncomingByChannel(channelId string) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel { func (s SqlWebhookStore) SaveOutgoing(T goi18n.TranslateFunc, webhook *model.OutgoingWebhook) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -210,7 +211,7 @@ func (s SqlWebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) StoreChann
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) GetOutgoing(id string) StoreChannel { func (s SqlWebhookStore) GetOutgoing(T goi18n.TranslateFunc, id string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -231,7 +232,7 @@ func (s SqlWebhookStore) GetOutgoing(id string) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) GetOutgoingByCreator(userId string) StoreChannel { func (s SqlWebhookStore) GetOutgoingByCreator(T goi18n.TranslateFunc, userId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -252,7 +253,7 @@ func (s SqlWebhookStore) GetOutgoingByCreator(userId string) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) GetOutgoingByChannel(channelId string) StoreChannel { func (s SqlWebhookStore) GetOutgoingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -273,7 +274,7 @@ func (s SqlWebhookStore) GetOutgoingByChannel(channelId string) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) GetOutgoingByTeam(teamId string) StoreChannel { func (s SqlWebhookStore) GetOutgoingByTeam(T goi18n.TranslateFunc, teamId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -294,7 +295,7 @@ func (s SqlWebhookStore) GetOutgoingByTeam(teamId string) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) DeleteOutgoing(webhookId string, time int64) StoreChannel { func (s SqlWebhookStore) DeleteOutgoing(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -312,7 +313,7 @@ func (s SqlWebhookStore) DeleteOutgoing(webhookId string, time int64) StoreChann
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(userId string) StoreChannel { func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(T goi18n.TranslateFunc, userId string) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {
@@ -330,7 +331,7 @@ func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(userId string) StoreChann
return storeChannel return storeChannel
} }
func (s SqlWebhookStore) UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel { func (s SqlWebhookStore) UpdateOutgoing(T goi18n.TranslateFunc, hook *model.OutgoingWebhook) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
go func() { go func() {

Просмотреть файл

@@ -5,6 +5,7 @@ package store
import ( import (
"github.com/mattermost/platform/model" "github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"testing" "testing"
) )
@@ -16,11 +17,11 @@ func TestWebhookStoreSaveIncoming(t *testing.T) {
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
if err := (<-store.Webhook().SaveIncoming(&o1)).Err; err != nil { if err := (<-store.Webhook().SaveIncoming(utils.T, &o1)).Err; err != nil {
t.Fatal("couldn't save item", err) t.Fatal("couldn't save item", err)
} }
if err := (<-store.Webhook().SaveIncoming(&o1)).Err; err == nil { if err := (<-store.Webhook().SaveIncoming(utils.T, &o1)).Err; err == nil {
t.Fatal("shouldn't be able to update from save") t.Fatal("shouldn't be able to update from save")
} }
} }
@@ -33,9 +34,9 @@ func TestWebhookStoreGetIncoming(t *testing.T) {
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) o1 = (<-store.Webhook().SaveIncoming(utils.T, o1)).Data.(*model.IncomingWebhook)
if r1 := <-store.Webhook().GetIncoming(o1.Id); r1.Err != nil { if r1 := <-store.Webhook().GetIncoming(utils.T, o1.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt { if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt {
@@ -43,7 +44,7 @@ func TestWebhookStoreGetIncoming(t *testing.T) {
} }
} }
if err := (<-store.Webhook().GetIncoming("123")).Err; err == nil { if err := (<-store.Webhook().GetIncoming(utils.T, "123")).Err; err == nil {
t.Fatal("Missing id should have failed") t.Fatal("Missing id should have failed")
} }
} }
@@ -56,9 +57,9 @@ func TestWebhookStoreGetIncomingByUser(t *testing.T) {
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) o1 = (<-store.Webhook().SaveIncoming(utils.T, o1)).Data.(*model.IncomingWebhook)
if r1 := <-store.Webhook().GetIncomingByUser(o1.UserId); r1.Err != nil { if r1 := <-store.Webhook().GetIncomingByUser(utils.T, o1.UserId); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.([]*model.IncomingWebhook)[0].CreateAt != o1.CreateAt { if r1.Data.([]*model.IncomingWebhook)[0].CreateAt != o1.CreateAt {
@@ -66,7 +67,7 @@ func TestWebhookStoreGetIncomingByUser(t *testing.T) {
} }
} }
if result := <-store.Webhook().GetIncomingByUser("123"); result.Err != nil { if result := <-store.Webhook().GetIncomingByUser(utils.T, "123"); result.Err != nil {
t.Fatal(result.Err) t.Fatal(result.Err)
} else { } else {
if len(result.Data.([]*model.IncomingWebhook)) != 0 { if len(result.Data.([]*model.IncomingWebhook)) != 0 {
@@ -83,9 +84,9 @@ func TestWebhookStoreDeleteIncoming(t *testing.T) {
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) o1 = (<-store.Webhook().SaveIncoming(utils.T, o1)).Data.(*model.IncomingWebhook)
if r1 := <-store.Webhook().GetIncoming(o1.Id); r1.Err != nil { if r1 := <-store.Webhook().GetIncoming(utils.T, o1.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt { if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt {
@@ -93,11 +94,11 @@ func TestWebhookStoreDeleteIncoming(t *testing.T) {
} }
} }
if r2 := <-store.Webhook().DeleteIncoming(o1.Id, model.GetMillis()); r2.Err != nil { if r2 := <-store.Webhook().DeleteIncoming(utils.T, o1.Id, model.GetMillis()); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} }
if r3 := (<-store.Webhook().GetIncoming(o1.Id)); r3.Err == nil { if r3 := (<-store.Webhook().GetIncoming(utils.T, o1.Id)); r3.Err == nil {
t.Log(r3.Data) t.Log(r3.Data)
t.Fatal("Missing id should have failed") t.Fatal("Missing id should have failed")
} }
@@ -111,9 +112,9 @@ func TestWebhookStoreDeleteIncomingByUser(t *testing.T) {
o1.UserId = model.NewId() o1.UserId = model.NewId()
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) o1 = (<-store.Webhook().SaveIncoming(utils.T, o1)).Data.(*model.IncomingWebhook)
if r1 := <-store.Webhook().GetIncoming(o1.Id); r1.Err != nil { if r1 := <-store.Webhook().GetIncoming(utils.T, o1.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt { if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt {
@@ -121,11 +122,11 @@ func TestWebhookStoreDeleteIncomingByUser(t *testing.T) {
} }
} }
if r2 := <-store.Webhook().PermanentDeleteIncomingByUser(o1.UserId); r2.Err != nil { if r2 := <-store.Webhook().PermanentDeleteIncomingByUser(utils.T, o1.UserId); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} }
if r3 := (<-store.Webhook().GetIncoming(o1.Id)); r3.Err == nil { if r3 := (<-store.Webhook().GetIncoming(utils.T, o1.Id)); r3.Err == nil {
t.Log(r3.Data) t.Log(r3.Data)
t.Fatal("Missing id should have failed") t.Fatal("Missing id should have failed")
} }
@@ -140,11 +141,11 @@ func TestWebhookStoreSaveOutgoing(t *testing.T) {
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"} o1.CallbackURLs = []string{"http://nowhere.com/"}
if err := (<-store.Webhook().SaveOutgoing(&o1)).Err; err != nil { if err := (<-store.Webhook().SaveOutgoing(utils.T, &o1)).Err; err != nil {
t.Fatal("couldn't save item", err) t.Fatal("couldn't save item", err)
} }
if err := (<-store.Webhook().SaveOutgoing(&o1)).Err; err == nil { if err := (<-store.Webhook().SaveOutgoing(utils.T, &o1)).Err; err == nil {
t.Fatal("shouldn't be able to update from save") t.Fatal("shouldn't be able to update from save")
} }
} }
@@ -158,9 +159,9 @@ func TestWebhookStoreGetOutgoing(t *testing.T) {
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"} o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoing(o1.Id); r1.Err != nil { if r1 := <-store.Webhook().GetOutgoing(utils.T, o1.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt { if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
@@ -168,7 +169,7 @@ func TestWebhookStoreGetOutgoing(t *testing.T) {
} }
} }
if err := (<-store.Webhook().GetOutgoing("123")).Err; err == nil { if err := (<-store.Webhook().GetOutgoing(utils.T, "123")).Err; err == nil {
t.Fatal("Missing id should have failed") t.Fatal("Missing id should have failed")
} }
} }
@@ -182,9 +183,9 @@ func TestWebhookStoreGetOutgoingByChannel(t *testing.T) {
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"} o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoingByChannel(o1.ChannelId); r1.Err != nil { if r1 := <-store.Webhook().GetOutgoingByChannel(utils.T, o1.ChannelId); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt { if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
@@ -192,7 +193,7 @@ func TestWebhookStoreGetOutgoingByChannel(t *testing.T) {
} }
} }
if result := <-store.Webhook().GetOutgoingByChannel("123"); result.Err != nil { if result := <-store.Webhook().GetOutgoingByChannel(utils.T, "123"); result.Err != nil {
t.Fatal(result.Err) t.Fatal(result.Err)
} else { } else {
if len(result.Data.([]*model.OutgoingWebhook)) != 0 { if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
@@ -210,9 +211,9 @@ func TestWebhookStoreGetOutgoingByCreator(t *testing.T) {
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"} o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoingByCreator(o1.CreatorId); r1.Err != nil { if r1 := <-store.Webhook().GetOutgoingByCreator(utils.T, o1.CreatorId); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt { if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
@@ -220,7 +221,7 @@ func TestWebhookStoreGetOutgoingByCreator(t *testing.T) {
} }
} }
if result := <-store.Webhook().GetOutgoingByCreator("123"); result.Err != nil { if result := <-store.Webhook().GetOutgoingByCreator(utils.T, "123"); result.Err != nil {
t.Fatal(result.Err) t.Fatal(result.Err)
} else { } else {
if len(result.Data.([]*model.OutgoingWebhook)) != 0 { if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
@@ -238,9 +239,9 @@ func TestWebhookStoreGetOutgoingByTeam(t *testing.T) {
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"} o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoingByTeam(o1.TeamId); r1.Err != nil { if r1 := <-store.Webhook().GetOutgoingByTeam(utils.T, o1.TeamId); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt { if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
@@ -248,7 +249,7 @@ func TestWebhookStoreGetOutgoingByTeam(t *testing.T) {
} }
} }
if result := <-store.Webhook().GetOutgoingByTeam("123"); result.Err != nil { if result := <-store.Webhook().GetOutgoingByTeam(utils.T, "123"); result.Err != nil {
t.Fatal(result.Err) t.Fatal(result.Err)
} else { } else {
if len(result.Data.([]*model.OutgoingWebhook)) != 0 { if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
@@ -266,9 +267,9 @@ func TestWebhookStoreDeleteOutgoing(t *testing.T) {
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"} o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoing(o1.Id); r1.Err != nil { if r1 := <-store.Webhook().GetOutgoing(utils.T, o1.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt { if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
@@ -276,11 +277,11 @@ func TestWebhookStoreDeleteOutgoing(t *testing.T) {
} }
} }
if r2 := <-store.Webhook().DeleteOutgoing(o1.Id, model.GetMillis()); r2.Err != nil { if r2 := <-store.Webhook().DeleteOutgoing(utils.T, o1.Id, model.GetMillis()); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} }
if r3 := (<-store.Webhook().GetOutgoing(o1.Id)); r3.Err == nil { if r3 := (<-store.Webhook().GetOutgoing(utils.T, o1.Id)); r3.Err == nil {
t.Log(r3.Data) t.Log(r3.Data)
t.Fatal("Missing id should have failed") t.Fatal("Missing id should have failed")
} }
@@ -295,9 +296,9 @@ func TestWebhookStoreDeleteOutgoingByUser(t *testing.T) {
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"} o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
if r1 := <-store.Webhook().GetOutgoing(o1.Id); r1.Err != nil { if r1 := <-store.Webhook().GetOutgoing(utils.T, o1.Id); r1.Err != nil {
t.Fatal(r1.Err) t.Fatal(r1.Err)
} else { } else {
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt { if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
@@ -305,11 +306,11 @@ func TestWebhookStoreDeleteOutgoingByUser(t *testing.T) {
} }
} }
if r2 := <-store.Webhook().PermanentDeleteOutgoingByUser(o1.CreatorId); r2.Err != nil { if r2 := <-store.Webhook().PermanentDeleteOutgoingByUser(utils.T, o1.CreatorId); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} }
if r3 := (<-store.Webhook().GetOutgoing(o1.Id)); r3.Err == nil { if r3 := (<-store.Webhook().GetOutgoing(utils.T, o1.Id)); r3.Err == nil {
t.Log(r3.Data) t.Log(r3.Data)
t.Fatal("Missing id should have failed") t.Fatal("Missing id should have failed")
} }
@@ -324,11 +325,11 @@ func TestWebhookStoreUpdateOutgoing(t *testing.T) {
o1.TeamId = model.NewId() o1.TeamId = model.NewId()
o1.CallbackURLs = []string{"http://nowhere.com/"} o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) o1 = (<-store.Webhook().SaveOutgoing(utils.T, o1)).Data.(*model.OutgoingWebhook)
o1.Token = model.NewId() o1.Token = model.NewId()
if r2 := <-store.Webhook().UpdateOutgoing(o1); r2.Err != nil { if r2 := <-store.Webhook().UpdateOutgoing(utils.T, o1); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} }
} }

Просмотреть файл

@@ -168,20 +168,20 @@ type SystemStore interface {
} }
type WebhookStore interface { type WebhookStore interface {
SaveIncoming(webhook *model.IncomingWebhook) StoreChannel SaveIncoming(T goi18n.TranslateFunc, webhook *model.IncomingWebhook) StoreChannel
GetIncoming(id string) StoreChannel GetIncoming(T goi18n.TranslateFunc, id string) StoreChannel
GetIncomingByUser(userId string) StoreChannel GetIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel
GetIncomingByChannel(channelId string) StoreChannel GetIncomingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel
DeleteIncoming(webhookId string, time int64) StoreChannel DeleteIncoming(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel
PermanentDeleteIncomingByUser(userId string) StoreChannel PermanentDeleteIncomingByUser(T goi18n.TranslateFunc, userId string) StoreChannel
SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel SaveOutgoing(T goi18n.TranslateFunc, webhook *model.OutgoingWebhook) StoreChannel
GetOutgoing(id string) StoreChannel GetOutgoing(T goi18n.TranslateFunc, id string) StoreChannel
GetOutgoingByCreator(userId string) StoreChannel GetOutgoingByCreator(T goi18n.TranslateFunc, userId string) StoreChannel
GetOutgoingByChannel(channelId string) StoreChannel GetOutgoingByChannel(T goi18n.TranslateFunc, channelId string) StoreChannel
GetOutgoingByTeam(teamId string) StoreChannel GetOutgoingByTeam(T goi18n.TranslateFunc, teamId string) StoreChannel
DeleteOutgoing(webhookId string, time int64) StoreChannel DeleteOutgoing(T goi18n.TranslateFunc, webhookId string, time int64) StoreChannel
PermanentDeleteOutgoingByUser(userId string) StoreChannel PermanentDeleteOutgoingByUser(T goi18n.TranslateFunc, userId string) StoreChannel
UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel UpdateOutgoing(T goi18n.TranslateFunc, hook *model.OutgoingWebhook) StoreChannel
} }
type PreferenceStore interface { type PreferenceStore interface {

Просмотреть файл

@@ -1022,7 +1022,7 @@ func incomingWebhook(c *api.Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r) params := mux.Vars(r)
id := params["id"] id := params["id"]
hchan := api.Srv.Store.Webhook().GetIncoming(id) hchan := api.Srv.Store.Webhook().GetIncoming(c.T, id)
r.ParseForm() r.ParseForm()