Merge branch 'master' into advanced-permissions-phase-2
Этот коммит содержится в:
@@ -338,6 +338,7 @@ func (a *App) trackConfig() {
|
|||||||
"enable_email_batching": *cfg.EmailSettings.EnableEmailBatching,
|
"enable_email_batching": *cfg.EmailSettings.EnableEmailBatching,
|
||||||
"email_batching_buffer_size": *cfg.EmailSettings.EmailBatchingBufferSize,
|
"email_batching_buffer_size": *cfg.EmailSettings.EmailBatchingBufferSize,
|
||||||
"email_batching_interval": *cfg.EmailSettings.EmailBatchingInterval,
|
"email_batching_interval": *cfg.EmailSettings.EmailBatchingInterval,
|
||||||
|
"enable_preview_mode_banner": *cfg.EmailSettings.EnablePreviewModeBanner,
|
||||||
"isdefault_feedback_name": isDefault(cfg.EmailSettings.FeedbackName, ""),
|
"isdefault_feedback_name": isDefault(cfg.EmailSettings.FeedbackName, ""),
|
||||||
"isdefault_feedback_email": isDefault(cfg.EmailSettings.FeedbackEmail, ""),
|
"isdefault_feedback_email": isDefault(cfg.EmailSettings.FeedbackEmail, ""),
|
||||||
"isdefault_feedback_organization": isDefault(*cfg.EmailSettings.FeedbackOrganization, model.EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION),
|
"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 &&
|
if a.License() != nil && *a.Config().TeamSettings.ExperimentalTownSquareIsReadOnly &&
|
||||||
channel.Name == model.DEFAULT_CHANNEL {
|
channel.Name == model.DEFAULT_CHANNEL {
|
||||||
return model.NewAppError("HandleIncomingWebhook", "api.post.create_post.town_square_read_only", nil, "", http.StatusForbidden)
|
return model.NewAppError("HandleIncomingWebhook", "api.post.create_post.town_square_read_only", nil, "", http.StatusForbidden)
|
||||||
|
|||||||
@@ -177,6 +177,7 @@
|
|||||||
"EnableEmailBatching": false,
|
"EnableEmailBatching": false,
|
||||||
"EmailBatchingBufferSize": 256,
|
"EmailBatchingBufferSize": 256,
|
||||||
"EmailBatchingInterval": 30,
|
"EmailBatchingInterval": 30,
|
||||||
|
"EnablePreviewModeBanner": true,
|
||||||
"SkipServerCertificateVerification": false,
|
"SkipServerCertificateVerification": false,
|
||||||
"EmailNotificationContentsType": "full",
|
"EmailNotificationContentsType": "full",
|
||||||
"LoginButtonColor": "",
|
"LoginButtonColor": "",
|
||||||
|
|||||||
@@ -6886,6 +6886,10 @@
|
|||||||
"id": "store.sql_role.get_by_names.app_error",
|
"id": "store.sql_role.get_by_names.app_error",
|
||||||
"translation": "Unable to get roles"
|
"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",
|
"id": "store.sql_role.permanent_delete_all.app_error",
|
||||||
"translation": "We could not permanently delete all the roles"
|
"translation": "We could not permanently delete all the roles"
|
||||||
|
|||||||
@@ -739,6 +739,7 @@ type EmailSettings struct {
|
|||||||
EnableEmailBatching *bool
|
EnableEmailBatching *bool
|
||||||
EmailBatchingBufferSize *int
|
EmailBatchingBufferSize *int
|
||||||
EmailBatchingInterval *int
|
EmailBatchingInterval *int
|
||||||
|
EnablePreviewModeBanner *bool
|
||||||
SkipServerCertificateVerification *bool
|
SkipServerCertificateVerification *bool
|
||||||
EmailNotificationContentsType *string
|
EmailNotificationContentsType *string
|
||||||
LoginButtonColor *string
|
LoginButtonColor *string
|
||||||
@@ -791,6 +792,10 @@ func (s *EmailSettings) SetDefaults() {
|
|||||||
s.EmailBatchingInterval = NewInt(EMAIL_BATCHING_INTERVAL)
|
s.EmailBatchingInterval = NewInt(EMAIL_BATCHING_INTERVAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.EnablePreviewModeBanner == nil {
|
||||||
|
s.EnablePreviewModeBanner = NewBool(true)
|
||||||
|
}
|
||||||
|
|
||||||
if s.EnableSMTPAuth == nil {
|
if s.EnableSMTPAuth == nil {
|
||||||
s.EnableSMTPAuth = new(bool)
|
s.EnableSMTPAuth = new(bool)
|
||||||
if s.ConnectionSecurity == CONN_SECURITY_NONE {
|
if s.ConnectionSecurity == CONN_SECURITY_NONE {
|
||||||
|
|||||||
@@ -16,17 +16,18 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type IncomingWebhook struct {
|
type IncomingWebhook struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
CreateAt int64 `json:"create_at"`
|
CreateAt int64 `json:"create_at"`
|
||||||
UpdateAt int64 `json:"update_at"`
|
UpdateAt int64 `json:"update_at"`
|
||||||
DeleteAt int64 `json:"delete_at"`
|
DeleteAt int64 `json:"delete_at"`
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
ChannelId string `json:"channel_id"`
|
ChannelId string `json:"channel_id"`
|
||||||
TeamId string `json:"team_id"`
|
TeamId string `json:"team_id"`
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
IconURL string `json:"icon_url"`
|
IconURL string `json:"icon_url"`
|
||||||
|
ChannelLocked bool `json:"channel_locked"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type IncomingWebhookRequest struct {
|
type IncomingWebhookRequest struct {
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ func UpgradeDatabaseToVersion410(sqlStore SqlStore) {
|
|||||||
func UpgradeDatabaseToVersion50(sqlStore SqlStore) {
|
func UpgradeDatabaseToVersion50(sqlStore SqlStore) {
|
||||||
// TODO: Uncomment following condition when version 5.0.0 is released
|
// TODO: Uncomment following condition when version 5.0.0 is released
|
||||||
//if shouldPerformUpgrade(sqlStore, VERSION_4_10_0, VERSION_5_0_0) {
|
//if shouldPerformUpgrade(sqlStore, VERSION_4_10_0, VERSION_5_0_0) {
|
||||||
|
|
||||||
sqlStore.CreateColumnIfNotExistsNoDefault("Teams", "SchemeId", "varchar(26)", "varchar(26)")
|
sqlStore.CreateColumnIfNotExistsNoDefault("Teams", "SchemeId", "varchar(26)", "varchar(26)")
|
||||||
sqlStore.CreateColumnIfNotExistsNoDefault("Channels", "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.CreateColumnIfNotExists("Roles", "BuiltIn", "boolean", "boolean", "0")
|
||||||
sqlStore.GetMaster().Exec("UPDATE Roles SET BuiltIn=true")
|
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.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)
|
// 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["EnableSignInWithUsername"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithUsername)
|
||||||
props["RequireEmailVerification"] = strconv.FormatBool(c.EmailSettings.RequireEmailVerification)
|
props["RequireEmailVerification"] = strconv.FormatBool(c.EmailSettings.RequireEmailVerification)
|
||||||
props["EnableEmailBatching"] = strconv.FormatBool(*c.EmailSettings.EnableEmailBatching)
|
props["EnableEmailBatching"] = strconv.FormatBool(*c.EmailSettings.EnableEmailBatching)
|
||||||
|
props["EnablePreviewModeBanner"] = strconv.FormatBool(*c.EmailSettings.EnablePreviewModeBanner)
|
||||||
props["EmailNotificationContentsType"] = *c.EmailSettings.EmailNotificationContentsType
|
props["EmailNotificationContentsType"] = *c.EmailSettings.EmailNotificationContentsType
|
||||||
|
|
||||||
props["EmailLoginButtonColor"] = *c.EmailSettings.LoginButtonColor
|
props["EmailLoginButtonColor"] = *c.EmailSettings.LoginButtonColor
|
||||||
|
|||||||
@@ -182,6 +182,29 @@ func TestIncomingWebhook(t *testing.T) {
|
|||||||
assert.True(t, resp.StatusCode == http.StatusOK)
|
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) {
|
t.Run("DisableWebhooks", func(t *testing.T) {
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = false })
|
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\"}"))
|
resp, err := http.Post(url, "application/json", strings.NewReader("{\"text\":\"this is a test\"}"))
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user