MM-11106: Allow systeadmin webook to post to read only town square. (#9051)

Этот коммит содержится в:
George Goldberg
2018-07-06 09:07:36 +01:00
коммит произвёл Carlos Tadeu Panato Junior
родитель 8d3ea1bbf6
Коммит 0896b5c64e
3 изменённых файлов: 43 добавлений и 12 удалений

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

@@ -97,13 +97,30 @@ func TestIncomingWebhook(t *testing.T) {
assert.True(t, resp.StatusCode == http.StatusOK)
})
t.Run("WebhookExperimentReadOnly", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = false })
_, err := http.Post(url, "application/json", strings.NewReader(fmt.Sprintf("{\"text\":\"this is a test\", \"channel\":\"%s\"}", model.DEFAULT_CHANNEL)))
assert.Nil(t, err, "Not read only")
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true })
t.Run("WebhookExperimentalReadOnly", func(t *testing.T) {
th.App.SetLicense(model.NewTestLicense())
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true })
// Read only default channel should fail.
resp, err := http.Post(url, "application/json", strings.NewReader(fmt.Sprintf("{\"text\":\"this is a test\", \"channel\":\"%s\"}", model.DEFAULT_CHANNEL)))
require.Nil(t, err)
assert.True(t, resp.StatusCode != http.StatusOK)
// None-default channel should still work.
resp, err = http.Post(url, "application/json", strings.NewReader(fmt.Sprintf("{\"text\":\"this is a test\", \"channel\":\"%s\"}", th.BasicChannel.Name)))
require.Nil(t, err)
assert.True(t, resp.StatusCode == http.StatusOK)
// System-Admin Owned Hook
adminHook, err := th.App.CreateIncomingWebhookForChannel(th.SystemAdminUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
require.Nil(t, err)
adminUrl := ApiClient.Url + "/hooks/" + adminHook.Id
resp, err = http.Post(adminUrl, "application/json", strings.NewReader(fmt.Sprintf("{\"text\":\"this is a test\", \"channel\":\"%s\"}", model.DEFAULT_CHANNEL)))
require.Nil(t, err)
assert.True(t, resp.StatusCode == http.StatusOK)
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = false })
})
t.Run("WebhookAttachments", func(t *testing.T) {