Skip to content

Commit

Permalink
Cherry pick MM-54275 to v8.0 (#24409)
Browse files Browse the repository at this point in the history
Automatic Merge
  • Loading branch information
M-ZubairAhmed committed Aug 31, 2023
1 parent 172c6f7 commit 48cfe92
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ include config.mk
include build/*.mk

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)
Expand Down
16 changes: 15 additions & 1 deletion server/config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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)
Expand Down Expand Up @@ -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 ""
}
13 changes: 13 additions & 0 deletions server/config/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,19 @@ func TestGetClientConfig(t *testing.T) {
"DisableAppBar": "true",
},
},
{
"test key for GiphySdkKey",
&model.Config{
ServiceSettings: model.ServiceSettings{
GiphySdkKey: model.NewString(""),
},
},
"",
nil,
map[string]string{
"GiphySdkKey": model.ServiceSettingsDefaultGiphySdkKeyTest,
},
},
}

for _, testCase := range testCases {
Expand Down
12 changes: 4 additions & 8 deletions server/public/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ const (
ServiceSettingsDefaultListenAndAddress = ":8065"
ServiceSettingsDefaultGfycatAPIKey = "2_KtH_W5"
ServiceSettingsDefaultGfycatAPISecret = "3wLVZPiswc3DnaiaFoLkDvB4X0IV6CpMkj4tf2inJRsBY6-FnkT08zGmppWFgeof"
ServiceSettingsDefaultGiphySdkKey = "yaRojIWaxmKhtSMBaT3uLCAHm0kpMLKw"
ServiceSettingsDefaultGiphySdkKeyTest = "s0glxvzVg9azvPipKxcPLpXV0q1x1fVP"
ServiceSettingsDefaultDeveloperFlags = ""

Expand Down Expand Up @@ -399,6 +398,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
Expand Down Expand Up @@ -742,13 +743,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 {
Expand Down

0 comments on commit 48cfe92

Please sign in to comment.