diff --git a/server/Makefile b/server/Makefile index c23e790fb9..3b42a98275 100644 --- a/server/Makefile +++ b/server/Makefile @@ -213,6 +213,7 @@ include build/*.mk include public/Makefile LDFLAGS += -X "github.com/mattermost/mattermost/server/public/model.MockCWS=$(MM_ENABLE_CWS_MOCK)" +LDFLAGS += -X "github.com/mattermost/mattermost/server/public/model.MattermostGiphySdkKey=$(MM_GIPHY_SDK_KEY)" RUN_IN_BACKGROUND ?= ifeq ($(RUN_SERVER_IN_BACKGROUND),true) diff --git a/server/config/client.go b/server/config/client.go index ff7e599fee..9f5c40a5b3 100644 --- a/server/config/client.go +++ b/server/config/client.go @@ -81,7 +81,7 @@ func GenerateClientConfig(c *model.Config, telemetryID string, license *model.Li props["EnableGifPicker"] = strconv.FormatBool(*c.ServiceSettings.EnableGifPicker) props["GfycatApiKey"] = *c.ServiceSettings.GfycatAPIKey props["GfycatApiSecret"] = *c.ServiceSettings.GfycatAPISecret - props["GiphySdkKey"] = *c.ServiceSettings.GiphySdkKey + props["GiphySdkKey"] = getGiphySdkKey(c.ServiceSettings) props["MaxFileSize"] = strconv.FormatInt(*c.FileSettings.MaxFileSize, 10) props["MaxNotificationsPerChannel"] = strconv.FormatInt(*c.TeamSettings.MaxNotificationsPerChannel, 10) @@ -378,3 +378,17 @@ func GenerateLimitedClientConfig(c *model.Config, telemetryID string, license *m return props } + +func getGiphySdkKey(ss model.ServiceSettings) string { + if model.GetServiceEnvironment() == model.ServiceEnvironmentProduction { + if *ss.GiphySdkKey != "" { + return *ss.GiphySdkKey + } + + return model.MattermostGiphySdkKey + } else if model.GetServiceEnvironment() == model.ServiceEnvironmentDev || model.GetServiceEnvironment() == model.ServiceEnvironmentTest { + return model.ServiceSettingsDefaultGiphySdkKeyTest + } + + return "" +} diff --git a/server/config/client_test.go b/server/config/client_test.go index 89cb88e02b..0ccbae9413 100644 --- a/server/config/client_test.go +++ b/server/config/client_test.go @@ -293,6 +293,19 @@ func TestGetClientConfig(t *testing.T) { "EnableJoinLeaveMessageByDefault": "false", }, }, + { + "test key for GiphySdkKey", + &model.Config{ + ServiceSettings: model.ServiceSettings{ + GiphySdkKey: model.NewString(""), + }, + }, + "", + nil, + map[string]string{ + "GiphySdkKey": model.ServiceSettingsDefaultGiphySdkKeyTest, + }, + }, } for _, testCase := range testCases { diff --git a/server/public/model/config.go b/server/public/model/config.go index 19ac0889b9..a94208e6b0 100644 --- a/server/public/model/config.go +++ b/server/public/model/config.go @@ -111,7 +111,6 @@ const ( ServiceSettingsDefaultListenAndAddress = ":8065" ServiceSettingsDefaultGfycatAPIKey = "2_KtH_W5" ServiceSettingsDefaultGfycatAPISecret = "3wLVZPiswc3DnaiaFoLkDvB4X0IV6CpMkj4tf2inJRsBY6-FnkT08zGmppWFgeof" - ServiceSettingsDefaultGiphySdkKey = "yaRojIWaxmKhtSMBaT3uLCAHm0kpMLKw" ServiceSettingsDefaultGiphySdkKeyTest = "s0glxvzVg9azvPipKxcPLpXV0q1x1fVP" ServiceSettingsDefaultDeveloperFlags = "" @@ -400,6 +399,8 @@ type ServiceSettings struct { AllowSyncedDrafts *bool `access:"site_posts"` } +var MattermostGiphySdkKey string + func (s *ServiceSettings) SetDefaults(isUpdate bool) { if s.EnableEmailInvitations == nil { // If the site URL is also not present then assume this is a clean install @@ -743,13 +744,8 @@ func (s *ServiceSettings) SetDefaults(isUpdate bool) { s.GfycatAPISecret = NewString(ServiceSettingsDefaultGfycatAPISecret) } - if s.GiphySdkKey == nil { - switch GetServiceEnvironment() { - case ServiceEnvironmentProduction: - s.GiphySdkKey = NewString(ServiceSettingsDefaultGiphySdkKey) - case ServiceEnvironmentTest, ServiceEnvironmentDev: - s.GiphySdkKey = NewString(ServiceSettingsDefaultGiphySdkKeyTest) - } + if s.GiphySdkKey == nil || *s.GiphySdkKey == "" { + s.GiphySdkKey = NewString("") } if s.ExperimentalEnableAuthenticationTransfer == nil {