Skip to content

Commit

Permalink
MM-17609 Add EnableSVGs setting (#11874)
Browse files Browse the repository at this point in the history
* MM-17609 Add EnableSVGs setting

* MM-17609 Return SVG images in post metadata
  • Loading branch information
hmhealey committed Aug 15, 2019
1 parent 09eb7e5 commit 2c5a87b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func (a *App) trackConfig() {
"enable_email_invitations": *cfg.ServiceSettings.EnableEmailInvitations,
"experimental_channel_organization": *cfg.ServiceSettings.ExperimentalChannelOrganization,
"experimental_ldap_group_sync": *cfg.ServiceSettings.ExperimentalLdapGroupSync,
"enable_svgs": *cfg.ServiceSettings.EnableSVGs,
})

a.SendDiagnostic(TRACK_CONFIG_TEAM, map[string]interface{}{
Expand Down
8 changes: 7 additions & 1 deletion app/post_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,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) {
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))
return nil, image, err
} else if strings.HasPrefix(contentType, "text/html") {
Expand Down
10 changes: 10 additions & 0 deletions app/post_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,16 @@ func TestParseLinkMetadata(t *testing.T) {
assert.Nil(t, og)
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) {
Expand Down
3 changes: 2 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"ExperimentalEnableHardenedMode": false,
"DisableLegacyMFA": false,
"EnableEmailInvitations": false,
"ExperimentalLdapGroupSync": false
"ExperimentalLdapGroupSync": false,
"EnableSVGs": false
},
"TeamSettings": {
"SiteName": "Mattermost",
Expand Down
5 changes: 5 additions & 0 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ type ServiceSettings struct {
DisableLegacyMFA *bool
EnableEmailInvitations *bool
ExperimentalLdapGroupSync *bool
EnableSVGs *bool
}

func (s *ServiceSettings) SetDefaults() {
Expand Down Expand Up @@ -583,6 +584,10 @@ func (s *ServiceSettings) SetDefaults() {
if s.ExperimentalLdapGroupSync == nil {
s.ExperimentalLdapGroupSync = NewBool(false)
}

if s.EnableSVGs == nil {
s.EnableSVGs = NewBool(true)
}
}

type ClusterSettings struct {
Expand Down
1 change: 1 addition & 0 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L
props["EnableTutorial"] = strconv.FormatBool(*c.ServiceSettings.EnableTutorial)
props["ExperimentalEnableDefaultChannelLeaveJoinMessages"] = strconv.FormatBool(*c.ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages)
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
props["ExperimentalEnablePostMetadata"] = strconv.FormatBool(!*c.ExperimentalSettings.DisablePostMetadata)
Expand Down

0 comments on commit 2c5a87b

Please sign in to comment.