Move webhook logic from api layer to app layer (#5527)

* Move webhook logic from api layer to app layer

* Consolidate error messages

* Fix permission check and unit test
Этот коммит содержится в:
Joram Wilander
2017-02-28 04:31:53 -05:00
коммит произвёл George Goldberg
родитель cef5028cbe
Коммит 76fa840b52
5 изменённых файлов: 453 добавлений и 460 удалений

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

@@ -716,19 +716,17 @@ func TestUpdateOutgoingHook(t *testing.T) {
Client.Logout()
Client.Must(Client.LoginById(user2.Id, user2.Password))
Client.SetTeamId(team.Id)
t.Run("UpdateByUserWithoutPermissions", func(t *testing.T) {
if _, err := Client.UpdateOutgoingWebhook(hook); err == nil {
t.Fatal("should have failed - user does not have permissions to manage webhooks")
}
if _, err := Client.UpdateOutgoingWebhook(hook); err == nil {
t.Fatal("should have failed - user does not have permissions to manage webhooks")
}
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
utils.SetDefaultRolesBasedOnConfig()
t.Run("WithoutOnlyAdminIntegrations", func(t *testing.T) {
if _, err := Client.UpdateOutgoingWebhook(hook); err != nil {
t.Fatal("update webhook failed when admin only integrations is turned off")
}
})
})
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
utils.SetDefaultRolesBasedOnConfig()
hook2 := createOutgoingWebhook(channel1.Id, []string{"http://nowhereelse.com"}, []string{"dogs"}, Client, t)
if _, err := Client.UpdateOutgoingWebhook(hook2); err != nil {
t.Fatal("update webhook failed when admin only integrations is turned off")
}
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
utils.SetDefaultRolesBasedOnConfig()
@@ -919,6 +917,11 @@ func TestRegenOutgoingHookToken(t *testing.T) {
}
}
Client.SetTeamId(model.NewId())
if _, err := Client.RegenOutgoingWebhookToken(hook.Id); err == nil {
t.Fatal("should have failed - wrong team id")
}
Client.Logout()
Client.Must(Client.LoginById(user2.Id, user2.Password))
Client.SetTeamId(team.Id)