MM-17609 Add EnableSVGs setting (#11874)

* MM-17609 Add EnableSVGs setting

* MM-17609 Return SVG images in post metadata
Этот коммит содержится в:
Harrison Healey
2019-08-14 13:40:40 -04:00
коммит произвёл GitHub
родитель 9b61506c7d
Коммит 23ef7d9a62
5 изменённых файлов: 28 добавлений и 1 удалений

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

@@ -299,6 +299,7 @@ func (a *App) trackConfig() {
"experimental_ldap_group_sync": *cfg.ServiceSettings.ExperimentalLdapGroupSync, "experimental_ldap_group_sync": *cfg.ServiceSettings.ExperimentalLdapGroupSync,
"disable_bots_when_owner_is_deactivated": *cfg.ServiceSettings.DisableBotsWhenOwnerIsDeactivated, "disable_bots_when_owner_is_deactivated": *cfg.ServiceSettings.DisableBotsWhenOwnerIsDeactivated,
"enable_bot_account_creation": *cfg.ServiceSettings.EnableBotAccountCreation, "enable_bot_account_creation": *cfg.ServiceSettings.EnableBotAccountCreation,
"enable_svgs": *cfg.ServiceSettings.EnableSVGs,
}) })
a.SendDiagnostic(TRACK_CONFIG_TEAM, map[string]interface{}{ a.SendDiagnostic(TRACK_CONFIG_TEAM, map[string]interface{}{

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

@@ -495,7 +495,13 @@ func cacheLinkMetadata(requestURL string, timestamp int64, og *opengraph.OpenGra
} }
func (a *App) parseLinkMetadata(requestURL string, body io.Reader, contentType string) (*opengraph.OpenGraph, *model.PostImage, error) { func (a *App) parseLinkMetadata(requestURL string, body io.Reader, contentType string) (*opengraph.OpenGraph, *model.PostImage, error) {
if strings.HasPrefix(contentType, "image") { if contentType == "image/svg+xml" {
image := &model.PostImage{
Format: "svg",
}
return nil, image, nil
} else if strings.HasPrefix(contentType, "image") {
image, err := parseImages(io.LimitReader(body, MaxMetadataImageSize)) image, err := parseImages(io.LimitReader(body, MaxMetadataImageSize))
return nil, image, err return nil, image, err
} else if strings.HasPrefix(contentType, "text/html") { } else if strings.HasPrefix(contentType, "text/html") {

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

@@ -2013,6 +2013,16 @@ func TestParseLinkMetadata(t *testing.T) {
assert.Nil(t, og) assert.Nil(t, og)
assert.Nil(t, dimensions) assert.Nil(t, dimensions)
}) })
t.Run("svg", func(t *testing.T) {
og, dimensions, err := th.App.parseLinkMetadata("http://example.com/image.svg", nil, "image/svg+xml")
assert.Nil(t, err)
assert.Nil(t, og)
assert.Equal(t, &model.PostImage{
Format: "svg",
}, dimensions)
})
} }
func TestParseImages(t *testing.T) { func TestParseImages(t *testing.T) {

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

@@ -42,6 +42,7 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L
props["EnableTutorial"] = strconv.FormatBool(*c.ServiceSettings.EnableTutorial) props["EnableTutorial"] = strconv.FormatBool(*c.ServiceSettings.EnableTutorial)
props["ExperimentalEnableDefaultChannelLeaveJoinMessages"] = strconv.FormatBool(*c.ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages) props["ExperimentalEnableDefaultChannelLeaveJoinMessages"] = strconv.FormatBool(*c.ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages)
props["ExperimentalGroupUnreadChannels"] = *c.ServiceSettings.ExperimentalGroupUnreadChannels props["ExperimentalGroupUnreadChannels"] = *c.ServiceSettings.ExperimentalGroupUnreadChannels
props["EnableSVGs"] = strconv.FormatBool(*c.ServiceSettings.EnableSVGs)
// This setting is only temporary, so keep using the old setting name for the mobile and web apps // This setting is only temporary, so keep using the old setting name for the mobile and web apps
props["ExperimentalEnablePostMetadata"] = "true" props["ExperimentalEnablePostMetadata"] = "true"

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

@@ -307,6 +307,7 @@ type ServiceSettings struct {
ExperimentalLdapGroupSync *bool ExperimentalLdapGroupSync *bool
DisableBotsWhenOwnerIsDeactivated *bool `restricted:"true"` DisableBotsWhenOwnerIsDeactivated *bool `restricted:"true"`
EnableBotAccountCreation *bool EnableBotAccountCreation *bool
EnableSVGs *bool
} }
func (s *ServiceSettings) SetDefaults(isUpdate bool) { func (s *ServiceSettings) SetDefaults(isUpdate bool) {
@@ -667,6 +668,14 @@ func (s *ServiceSettings) SetDefaults(isUpdate bool) {
if s.EnableBotAccountCreation == nil { if s.EnableBotAccountCreation == nil {
s.EnableBotAccountCreation = NewBool(false) s.EnableBotAccountCreation = NewBool(false)
} }
if s.EnableSVGs == nil {
if isUpdate {
s.EnableSVGs = NewBool(true)
} else {
s.EnableSVGs = NewBool(false)
}
}
} }
type ClusterSettings struct { type ClusterSettings struct {