Merge branch 'master' into advanced-permissions-phase-2

Этот коммит содержится в:
Martin Kraft
2018-05-22 14:15:54 -04:00
коммит произвёл GitHub
родитель 4c683aff76 ce378adc97
Коммит f40666f9e8
9 изменённых файлов: 53 добавлений и 12 удалений

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

@@ -338,6 +338,7 @@ func (a *App) trackConfig() {
"enable_email_batching": *cfg.EmailSettings.EnableEmailBatching,
"email_batching_buffer_size": *cfg.EmailSettings.EmailBatchingBufferSize,
"email_batching_interval": *cfg.EmailSettings.EmailBatchingInterval,
"enable_preview_mode_banner": *cfg.EmailSettings.EnablePreviewModeBanner,
"isdefault_feedback_name": isDefault(cfg.EmailSettings.FeedbackName, ""),
"isdefault_feedback_email": isDefault(cfg.EmailSettings.FeedbackEmail, ""),
"isdefault_feedback_organization": isDefault(*cfg.EmailSettings.FeedbackOrganization, model.EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION),

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

@@ -633,6 +633,10 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
}
}
if hook.ChannelLocked && hook.ChannelId != channel.Id {
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel_locked.app_error", nil, "", http.StatusForbidden)
}
if a.License() != nil && *a.Config().TeamSettings.ExperimentalTownSquareIsReadOnly &&
channel.Name == model.DEFAULT_CHANNEL {
return model.NewAppError("HandleIncomingWebhook", "api.post.create_post.town_square_read_only", nil, "", http.StatusForbidden)

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

@@ -177,6 +177,7 @@
"EnableEmailBatching": false,
"EmailBatchingBufferSize": 256,
"EmailBatchingInterval": 30,
"EnablePreviewModeBanner": true,
"SkipServerCertificateVerification": false,
"EmailNotificationContentsType": "full",
"LoginButtonColor": "",

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

@@ -6886,6 +6886,10 @@
"id": "store.sql_role.get_by_names.app_error",
"translation": "Unable to get roles"
},
{
"id": "web.incoming_webhook.channel_locked.app_error",
"translation": "This webhook is not permitted to post to the requested channel"
},
{
"id": "store.sql_role.permanent_delete_all.app_error",
"translation": "We could not permanently delete all the roles"

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

@@ -739,6 +739,7 @@ type EmailSettings struct {
EnableEmailBatching *bool
EmailBatchingBufferSize *int
EmailBatchingInterval *int
EnablePreviewModeBanner *bool
SkipServerCertificateVerification *bool
EmailNotificationContentsType *string
LoginButtonColor *string
@@ -791,6 +792,10 @@ func (s *EmailSettings) SetDefaults() {
s.EmailBatchingInterval = NewInt(EMAIL_BATCHING_INTERVAL)
}
if s.EnablePreviewModeBanner == nil {
s.EnablePreviewModeBanner = NewBool(true)
}
if s.EnableSMTPAuth == nil {
s.EnableSMTPAuth = new(bool)
if s.ConnectionSecurity == CONN_SECURITY_NONE {

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

@@ -16,17 +16,18 @@ const (
)
type IncomingWebhook struct {
Id string `json:"id"`
CreateAt int64 `json:"create_at"`
UpdateAt int64 `json:"update_at"`
DeleteAt int64 `json:"delete_at"`
UserId string `json:"user_id"`
ChannelId string `json:"channel_id"`
TeamId string `json:"team_id"`
DisplayName string `json:"display_name"`
Description string `json:"description"`
Username string `json:"username"`
IconURL string `json:"icon_url"`
Id string `json:"id"`
CreateAt int64 `json:"create_at"`
UpdateAt int64 `json:"update_at"`
DeleteAt int64 `json:"delete_at"`
UserId string `json:"user_id"`
ChannelId string `json:"channel_id"`
TeamId string `json:"team_id"`
DisplayName string `json:"display_name"`
Description string `json:"description"`
Username string `json:"username"`
IconURL string `json:"icon_url"`
ChannelLocked bool `json:"channel_locked"`
}
type IncomingWebhookRequest struct {

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

@@ -427,7 +427,7 @@ func UpgradeDatabaseToVersion410(sqlStore SqlStore) {
func UpgradeDatabaseToVersion50(sqlStore SqlStore) {
// TODO: Uncomment following condition when version 5.0.0 is released
//if shouldPerformUpgrade(sqlStore, VERSION_4_10_0, VERSION_5_0_0) {
sqlStore.CreateColumnIfNotExistsNoDefault("Teams", "SchemeId", "varchar(26)", "varchar(26)")
sqlStore.CreateColumnIfNotExistsNoDefault("Channels", "SchemeId", "varchar(26)", "varchar(26)")
@@ -439,6 +439,7 @@ func UpgradeDatabaseToVersion50(sqlStore SqlStore) {
sqlStore.CreateColumnIfNotExists("Roles", "BuiltIn", "boolean", "boolean", "0")
sqlStore.GetMaster().Exec("UPDATE Roles SET BuiltIn=true")
sqlStore.GetMaster().Exec("UPDATE Roles SET SchemeManaged=false WHERE Name NOT IN ('system_user', 'system_admin', 'team_user', 'team_admin', 'channel_user', 'channel_admin')")
sqlStore.CreateColumnIfNotExists("IncomingWebhooks", "ChannelLocked", "boolean", "boolean", "0")
// saveSchemaVersion(sqlStore, VERSION_5_0_0)
//}

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

@@ -501,6 +501,7 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L
props["EnableSignInWithUsername"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithUsername)
props["RequireEmailVerification"] = strconv.FormatBool(c.EmailSettings.RequireEmailVerification)
props["EnableEmailBatching"] = strconv.FormatBool(*c.EmailSettings.EnableEmailBatching)
props["EnablePreviewModeBanner"] = strconv.FormatBool(*c.EmailSettings.EnablePreviewModeBanner)
props["EmailNotificationContentsType"] = *c.EmailSettings.EmailNotificationContentsType
props["EmailLoginButtonColor"] = *c.EmailSettings.LoginButtonColor

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

@@ -182,6 +182,29 @@ func TestIncomingWebhook(t *testing.T) {
assert.True(t, resp.StatusCode == http.StatusOK)
})
t.Run("ChannelLockedWebhook", func(t *testing.T) {
channel, err := th.App.CreateChannel(&model.Channel{TeamId: th.BasicTeam.Id, Name: model.NewId(), DisplayName: model.NewId(), Type: model.CHANNEL_OPEN, CreatorId: th.BasicUser.Id}, true)
require.Nil(t, err)
hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id, ChannelLocked: true})
require.Nil(t, err)
url := ApiClient.Url + "/hooks/" + hook.Id
payload := "payload={\"text\": \"test text\"}"
resp, err2 := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(payload))
require.Nil(t, err2)
assert.True(t, resp.StatusCode == http.StatusOK)
resp, err2 = http.Post(url, "application/json", strings.NewReader(fmt.Sprintf("{\"text\":\"this is a test\", \"channel\":\"%s\"}", th.BasicChannel.Name)))
require.Nil(t, err2)
assert.True(t, resp.StatusCode == http.StatusOK)
resp, err2 = http.Post(url, "application/json", strings.NewReader(fmt.Sprintf("{\"text\":\"this is a test\", \"channel\":\"%s\"}", channel.Name)))
require.Nil(t, err2)
assert.True(t, resp.StatusCode == http.StatusForbidden)
})
t.Run("DisableWebhooks", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = false })
resp, err := http.Post(url, "application/json", strings.NewReader("{\"text\":\"this is a test\"}"))