Chaning webhooks to be team wide
Этот коммит содержится в:
@@ -140,7 +140,7 @@ func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().GetIncomingByUser(c.Session.UserId); result.Err != nil {
|
||||
if result := <-Srv.Store.Webhook().GetIncomingByTeam(c.Session.TeamId); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
@@ -228,7 +228,7 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().GetOutgoingByCreator(c.Session.UserId); result.Err != nil {
|
||||
if result := <-Srv.Store.Webhook().GetOutgoingByTeam(c.Session.TeamId); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
|
||||
@@ -134,7 +134,7 @@ func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) StoreChann
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetIncomingByUser(userId string) StoreChannel {
|
||||
func (s SqlWebhookStore) GetIncomingByTeam(teamId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
go func() {
|
||||
@@ -142,8 +142,8 @@ func (s SqlWebhookStore) GetIncomingByUser(userId string) StoreChannel {
|
||||
|
||||
var webhooks []*model.IncomingWebhook
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM IncomingWebhooks WHERE UserId = :UserId AND DeleteAt = 0", map[string]interface{}{"UserId": userId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlWebhookStore.GetIncomingByUser", "We couldn't get the webhook", "userId="+userId+", err="+err.Error())
|
||||
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM IncomingWebhooks WHERE TeamId = :TeamId AND DeleteAt = 0", map[string]interface{}{"TeamId": teamId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlWebhookStore.GetIncomingByUser", "We couldn't get the webhook", "teamId="+teamId+", err="+err.Error())
|
||||
}
|
||||
|
||||
result.Data = webhooks
|
||||
@@ -231,27 +231,6 @@ func (s SqlWebhookStore) GetOutgoing(id string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByCreator(userId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
go func() {
|
||||
result := StoreResult{}
|
||||
|
||||
var webhooks []*model.OutgoingWebhook
|
||||
|
||||
if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM OutgoingWebhooks WHERE CreatorId = :UserId AND DeleteAt = 0", map[string]interface{}{"UserId": userId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlWebhookStore.GetOutgoingByCreator", "We couldn't get the webhooks", "userId="+userId+", err="+err.Error())
|
||||
}
|
||||
|
||||
result.Data = webhooks
|
||||
|
||||
storeChannel <- result
|
||||
close(storeChannel)
|
||||
}()
|
||||
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingByChannel(channelId string) StoreChannel {
|
||||
storeChannel := make(StoreChannel)
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestWebhookStoreGetIncoming(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebhookStoreGetIncomingByUser(t *testing.T) {
|
||||
func TestWebhookStoreGetIncomingByTeam(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
o1 := &model.IncomingWebhook{}
|
||||
@@ -58,7 +58,7 @@ func TestWebhookStoreGetIncomingByUser(t *testing.T) {
|
||||
|
||||
o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook)
|
||||
|
||||
if r1 := <-store.Webhook().GetIncomingByUser(o1.UserId); r1.Err != nil {
|
||||
if r1 := <-store.Webhook().GetIncomingByTeam(o1.TeamId); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
if r1.Data.([]*model.IncomingWebhook)[0].CreateAt != o1.CreateAt {
|
||||
@@ -66,7 +66,7 @@ func TestWebhookStoreGetIncomingByUser(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-store.Webhook().GetIncomingByUser("123"); result.Err != nil {
|
||||
if result := <-store.Webhook().GetIncomingByTeam("123"); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
if len(result.Data.([]*model.IncomingWebhook)) != 0 {
|
||||
@@ -201,34 +201,6 @@ func TestWebhookStoreGetOutgoingByChannel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebhookStoreGetOutgoingByCreator(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
o1 := &model.OutgoingWebhook{}
|
||||
o1.ChannelId = model.NewId()
|
||||
o1.CreatorId = model.NewId()
|
||||
o1.TeamId = model.NewId()
|
||||
o1.CallbackURLs = []string{"http://nowhere.com/"}
|
||||
|
||||
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
|
||||
|
||||
if r1 := <-store.Webhook().GetOutgoingByCreator(o1.CreatorId); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
|
||||
t.Fatal("invalid returned webhook")
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-store.Webhook().GetOutgoingByCreator("123"); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
|
||||
t.Fatal("no webhooks should have returned")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebhookStoreGetOutgoingByTeam(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
|
||||
@@ -169,13 +169,12 @@ type SystemStore interface {
|
||||
type WebhookStore interface {
|
||||
SaveIncoming(webhook *model.IncomingWebhook) StoreChannel
|
||||
GetIncoming(id string) StoreChannel
|
||||
GetIncomingByUser(userId string) StoreChannel
|
||||
GetIncomingByTeam(teamId string) StoreChannel
|
||||
GetIncomingByChannel(channelId string) StoreChannel
|
||||
DeleteIncoming(webhookId string, time int64) StoreChannel
|
||||
PermanentDeleteIncomingByUser(userId string) StoreChannel
|
||||
SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel
|
||||
GetOutgoing(id string) StoreChannel
|
||||
GetOutgoingByCreator(userId string) StoreChannel
|
||||
GetOutgoingByChannel(channelId string) StoreChannel
|
||||
GetOutgoingByTeam(teamId string) StoreChannel
|
||||
DeleteOutgoing(webhookId string, time int64) StoreChannel
|
||||
|
||||
Ссылка в новой задаче
Block a user