github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/config/client.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package config 5 6 import ( 7 "fmt" 8 "strconv" 9 "strings" 10 11 "github.com/mattermost/mattermost-server/v5/model" 12 ) 13 14 // GenerateClientConfig renders the given configuration for a client. 15 func GenerateClientConfig(c *model.Config, diagnosticID string, license *model.License) map[string]string { 16 props := GenerateLimitedClientConfig(c, diagnosticID, license) 17 18 props["SiteURL"] = strings.TrimRight(*c.ServiceSettings.SiteURL, "/") 19 props["EnableUserDeactivation"] = strconv.FormatBool(*c.TeamSettings.EnableUserDeactivation) 20 props["RestrictDirectMessage"] = *c.TeamSettings.RestrictDirectMessage 21 props["EnableXToLeaveChannelsFromLHS"] = strconv.FormatBool(*c.TeamSettings.EnableXToLeaveChannelsFromLHS) 22 props["TeammateNameDisplay"] = *c.TeamSettings.TeammateNameDisplay 23 props["LockTeammateNameDisplay"] = strconv.FormatBool(*c.TeamSettings.LockTeammateNameDisplay) 24 props["ExperimentalPrimaryTeam"] = *c.TeamSettings.ExperimentalPrimaryTeam 25 props["ExperimentalViewArchivedChannels"] = strconv.FormatBool(*c.TeamSettings.ExperimentalViewArchivedChannels) 26 27 props["EnableBotAccountCreation"] = strconv.FormatBool(*c.ServiceSettings.EnableBotAccountCreation) 28 props["EnableOAuthServiceProvider"] = strconv.FormatBool(*c.ServiceSettings.EnableOAuthServiceProvider) 29 props["GoogleDeveloperKey"] = *c.ServiceSettings.GoogleDeveloperKey 30 props["EnableIncomingWebhooks"] = strconv.FormatBool(*c.ServiceSettings.EnableIncomingWebhooks) 31 props["EnableOutgoingWebhooks"] = strconv.FormatBool(*c.ServiceSettings.EnableOutgoingWebhooks) 32 props["EnableCommands"] = strconv.FormatBool(*c.ServiceSettings.EnableCommands) 33 props["EnablePostUsernameOverride"] = strconv.FormatBool(*c.ServiceSettings.EnablePostUsernameOverride) 34 props["EnablePostIconOverride"] = strconv.FormatBool(*c.ServiceSettings.EnablePostIconOverride) 35 props["EnableUserAccessTokens"] = strconv.FormatBool(*c.ServiceSettings.EnableUserAccessTokens) 36 props["EnableLinkPreviews"] = strconv.FormatBool(*c.ServiceSettings.EnableLinkPreviews) 37 props["EnableTesting"] = strconv.FormatBool(*c.ServiceSettings.EnableTesting) 38 props["EnableDeveloper"] = strconv.FormatBool(*c.ServiceSettings.EnableDeveloper) 39 props["PostEditTimeLimit"] = fmt.Sprintf("%v", *c.ServiceSettings.PostEditTimeLimit) 40 props["MinimumHashtagLength"] = fmt.Sprintf("%v", *c.ServiceSettings.MinimumHashtagLength) 41 props["CloseUnusedDirectMessages"] = strconv.FormatBool(*c.ServiceSettings.CloseUnusedDirectMessages) 42 props["EnablePreviewFeatures"] = strconv.FormatBool(*c.ServiceSettings.EnablePreviewFeatures) 43 props["EnableTutorial"] = strconv.FormatBool(*c.ServiceSettings.EnableTutorial) 44 props["ExperimentalEnableDefaultChannelLeaveJoinMessages"] = strconv.FormatBool(*c.ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages) 45 props["ExperimentalGroupUnreadChannels"] = *c.ServiceSettings.ExperimentalGroupUnreadChannels 46 props["EnableSVGs"] = strconv.FormatBool(*c.ServiceSettings.EnableSVGs) 47 props["EnableMarketplace"] = strconv.FormatBool(*c.PluginSettings.EnableMarketplace) 48 props["EnableLatex"] = strconv.FormatBool(*c.ServiceSettings.EnableLatex) 49 props["ExtendSessionLengthWithActivity"] = strconv.FormatBool(*c.ServiceSettings.ExtendSessionLengthWithActivity) 50 51 // This setting is only temporary, so keep using the old setting name for the mobile and web apps 52 props["ExperimentalEnablePostMetadata"] = "true" 53 props["ExperimentalEnableClickToReply"] = strconv.FormatBool(*c.ExperimentalSettings.EnableClickToReply) 54 55 if *c.ServiceSettings.ExperimentalChannelOrganization || *c.ServiceSettings.ExperimentalGroupUnreadChannels != model.GROUP_UNREAD_CHANNELS_DISABLED { 56 props["ExperimentalChannelOrganization"] = strconv.FormatBool(true) 57 } else { 58 props["ExperimentalChannelOrganization"] = strconv.FormatBool(false) 59 } 60 61 props["ExperimentalChannelSidebarOrganization"] = *c.ServiceSettings.ExperimentalChannelSidebarOrganization 62 props["ExperimentalEnableAutomaticReplies"] = strconv.FormatBool(*c.TeamSettings.ExperimentalEnableAutomaticReplies) 63 props["ExperimentalTimezone"] = strconv.FormatBool(*c.DisplaySettings.ExperimentalTimezone) 64 65 props["ExperimentalDataPrefetch"] = strconv.FormatBool(*c.ServiceSettings.ExperimentalDataPrefetch) 66 67 props["SendEmailNotifications"] = strconv.FormatBool(*c.EmailSettings.SendEmailNotifications) 68 props["SendPushNotifications"] = strconv.FormatBool(*c.EmailSettings.SendPushNotifications) 69 props["RequireEmailVerification"] = strconv.FormatBool(*c.EmailSettings.RequireEmailVerification) 70 props["EnableEmailBatching"] = strconv.FormatBool(*c.EmailSettings.EnableEmailBatching) 71 props["EnablePreviewModeBanner"] = strconv.FormatBool(*c.EmailSettings.EnablePreviewModeBanner) 72 props["EmailNotificationContentsType"] = *c.EmailSettings.EmailNotificationContentsType 73 74 props["ShowEmailAddress"] = strconv.FormatBool(*c.PrivacySettings.ShowEmailAddress) 75 props["ShowFullName"] = strconv.FormatBool(*c.PrivacySettings.ShowFullName) 76 77 props["EnableFileAttachments"] = strconv.FormatBool(*c.FileSettings.EnableFileAttachments) 78 props["EnablePublicLink"] = strconv.FormatBool(*c.FileSettings.EnablePublicLink) 79 80 props["AvailableLocales"] = *c.LocalizationSettings.AvailableLocales 81 props["SQLDriverName"] = *c.SqlSettings.DriverName 82 83 props["EnableEmojiPicker"] = strconv.FormatBool(*c.ServiceSettings.EnableEmojiPicker) 84 props["EnableGifPicker"] = strconv.FormatBool(*c.ServiceSettings.EnableGifPicker) 85 props["GfycatApiKey"] = *c.ServiceSettings.GfycatApiKey 86 props["GfycatApiSecret"] = *c.ServiceSettings.GfycatApiSecret 87 props["MaxFileSize"] = strconv.FormatInt(*c.FileSettings.MaxFileSize, 10) 88 89 props["MaxNotificationsPerChannel"] = strconv.FormatInt(*c.TeamSettings.MaxNotificationsPerChannel, 10) 90 props["EnableConfirmNotificationsToChannel"] = strconv.FormatBool(*c.TeamSettings.EnableConfirmNotificationsToChannel) 91 props["TimeBetweenUserTypingUpdatesMilliseconds"] = strconv.FormatInt(*c.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds, 10) 92 props["EnableUserTypingMessages"] = strconv.FormatBool(*c.ServiceSettings.EnableUserTypingMessages) 93 props["EnableChannelViewedMessages"] = strconv.FormatBool(*c.ServiceSettings.EnableChannelViewedMessages) 94 95 props["RunJobs"] = strconv.FormatBool(*c.JobSettings.RunJobs) 96 97 props["EnableEmailInvitations"] = strconv.FormatBool(*c.ServiceSettings.EnableEmailInvitations) 98 99 // Set default values for all options that require a license. 100 props["ExperimentalHideTownSquareinLHS"] = "false" 101 props["ExperimentalTownSquareIsReadOnly"] = "false" 102 props["ExperimentalEnableAuthenticationTransfer"] = "true" 103 props["LdapNicknameAttributeSet"] = "false" 104 props["LdapFirstNameAttributeSet"] = "false" 105 props["LdapLastNameAttributeSet"] = "false" 106 props["LdapPictureAttributeSet"] = "false" 107 props["LdapPositionAttributeSet"] = "false" 108 props["EnableCompliance"] = "false" 109 props["EnableMobileFileDownload"] = "true" 110 props["EnableMobileFileUpload"] = "true" 111 props["SamlFirstNameAttributeSet"] = "false" 112 props["SamlLastNameAttributeSet"] = "false" 113 props["SamlNicknameAttributeSet"] = "false" 114 props["SamlPositionAttributeSet"] = "false" 115 props["EnableCluster"] = "false" 116 props["EnableMetrics"] = "false" 117 props["EnableBanner"] = "false" 118 props["BannerText"] = "" 119 props["BannerColor"] = "" 120 props["BannerTextColor"] = "" 121 props["AllowBannerDismissal"] = "false" 122 props["EnableThemeSelection"] = "true" 123 props["DefaultTheme"] = "" 124 props["AllowCustomThemes"] = "true" 125 props["AllowedThemes"] = "" 126 props["DataRetentionEnableMessageDeletion"] = "false" 127 props["DataRetentionMessageRetentionDays"] = "0" 128 props["DataRetentionEnableFileDeletion"] = "false" 129 props["DataRetentionFileRetentionDays"] = "0" 130 props["CustomUrlSchemes"] = strings.Join(c.DisplaySettings.CustomUrlSchemes, ",") 131 props["IsDefaultMarketplace"] = strconv.FormatBool(*c.PluginSettings.MarketplaceUrl == model.PLUGIN_SETTINGS_DEFAULT_MARKETPLACE_URL) 132 133 if license != nil { 134 props["ExperimentalHideTownSquareinLHS"] = strconv.FormatBool(*c.TeamSettings.ExperimentalHideTownSquareinLHS) 135 props["ExperimentalTownSquareIsReadOnly"] = strconv.FormatBool(*c.TeamSettings.ExperimentalTownSquareIsReadOnly) 136 props["ExperimentalEnableAuthenticationTransfer"] = strconv.FormatBool(*c.ServiceSettings.ExperimentalEnableAuthenticationTransfer) 137 138 if *license.Features.LDAP { 139 props["LdapNicknameAttributeSet"] = strconv.FormatBool(*c.LdapSettings.NicknameAttribute != "") 140 props["LdapFirstNameAttributeSet"] = strconv.FormatBool(*c.LdapSettings.FirstNameAttribute != "") 141 props["LdapLastNameAttributeSet"] = strconv.FormatBool(*c.LdapSettings.LastNameAttribute != "") 142 props["LdapPictureAttributeSet"] = strconv.FormatBool(*c.LdapSettings.PictureAttribute != "") 143 props["LdapPositionAttributeSet"] = strconv.FormatBool(*c.LdapSettings.PositionAttribute != "") 144 } 145 146 if *license.Features.Compliance { 147 props["EnableCompliance"] = strconv.FormatBool(*c.ComplianceSettings.Enable) 148 props["EnableMobileFileDownload"] = strconv.FormatBool(*c.FileSettings.EnableMobileDownload) 149 props["EnableMobileFileUpload"] = strconv.FormatBool(*c.FileSettings.EnableMobileUpload) 150 } 151 152 if *license.Features.SAML { 153 props["SamlFirstNameAttributeSet"] = strconv.FormatBool(*c.SamlSettings.FirstNameAttribute != "") 154 props["SamlLastNameAttributeSet"] = strconv.FormatBool(*c.SamlSettings.LastNameAttribute != "") 155 props["SamlNicknameAttributeSet"] = strconv.FormatBool(*c.SamlSettings.NicknameAttribute != "") 156 props["SamlPositionAttributeSet"] = strconv.FormatBool(*c.SamlSettings.PositionAttribute != "") 157 158 // do this under the correct licensed feature 159 props["ExperimentalClientSideCertEnable"] = strconv.FormatBool(*c.ExperimentalSettings.ClientSideCertEnable) 160 props["ExperimentalClientSideCertCheck"] = *c.ExperimentalSettings.ClientSideCertCheck 161 } 162 163 if *license.Features.Cluster { 164 props["EnableCluster"] = strconv.FormatBool(*c.ClusterSettings.Enable) 165 } 166 167 if *license.Features.Cluster { 168 props["EnableMetrics"] = strconv.FormatBool(*c.MetricsSettings.Enable) 169 } 170 171 if *license.Features.Announcement { 172 props["EnableBanner"] = strconv.FormatBool(*c.AnnouncementSettings.EnableBanner) 173 props["BannerText"] = *c.AnnouncementSettings.BannerText 174 props["BannerColor"] = *c.AnnouncementSettings.BannerColor 175 props["BannerTextColor"] = *c.AnnouncementSettings.BannerTextColor 176 props["AllowBannerDismissal"] = strconv.FormatBool(*c.AnnouncementSettings.AllowBannerDismissal) 177 } 178 179 if *license.Features.ThemeManagement { 180 props["EnableThemeSelection"] = strconv.FormatBool(*c.ThemeSettings.EnableThemeSelection) 181 props["DefaultTheme"] = *c.ThemeSettings.DefaultTheme 182 props["AllowCustomThemes"] = strconv.FormatBool(*c.ThemeSettings.AllowCustomThemes) 183 props["AllowedThemes"] = strings.Join(c.ThemeSettings.AllowedThemes, ",") 184 } 185 186 if *license.Features.DataRetention { 187 props["DataRetentionEnableMessageDeletion"] = strconv.FormatBool(*c.DataRetentionSettings.EnableMessageDeletion) 188 props["DataRetentionMessageRetentionDays"] = strconv.FormatInt(int64(*c.DataRetentionSettings.MessageRetentionDays), 10) 189 props["DataRetentionEnableFileDeletion"] = strconv.FormatBool(*c.DataRetentionSettings.EnableFileDeletion) 190 props["DataRetentionFileRetentionDays"] = strconv.FormatInt(int64(*c.DataRetentionSettings.FileRetentionDays), 10) 191 } 192 } 193 194 return props 195 } 196 197 // GenerateLimitedClientConfig renders the given configuration for an untrusted client. 198 func GenerateLimitedClientConfig(c *model.Config, diagnosticID string, license *model.License) map[string]string { 199 props := make(map[string]string) 200 201 props["Version"] = model.CurrentVersion 202 props["BuildNumber"] = model.BuildNumber 203 props["BuildDate"] = model.BuildDate 204 props["BuildHash"] = model.BuildHash 205 props["BuildHashEnterprise"] = model.BuildHashEnterprise 206 props["BuildEnterpriseReady"] = model.BuildEnterpriseReady 207 208 props["EnableBotAccountCreation"] = strconv.FormatBool(*c.ServiceSettings.EnableBotAccountCreation) 209 210 props["SiteName"] = *c.TeamSettings.SiteName 211 props["WebsocketURL"] = strings.TrimRight(*c.ServiceSettings.WebsocketURL, "/") 212 props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort) 213 props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort) 214 props["EnableUserCreation"] = strconv.FormatBool(*c.TeamSettings.EnableUserCreation) 215 props["EnableOpenServer"] = strconv.FormatBool(*c.TeamSettings.EnableOpenServer) 216 217 props["AndroidLatestVersion"] = c.ClientRequirements.AndroidLatestVersion 218 props["AndroidMinVersion"] = c.ClientRequirements.AndroidMinVersion 219 props["DesktopLatestVersion"] = c.ClientRequirements.DesktopLatestVersion 220 props["DesktopMinVersion"] = c.ClientRequirements.DesktopMinVersion 221 props["IosLatestVersion"] = c.ClientRequirements.IosLatestVersion 222 props["IosMinVersion"] = c.ClientRequirements.IosMinVersion 223 224 props["EnableDiagnostics"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics) 225 226 props["EnableSignUpWithEmail"] = strconv.FormatBool(*c.EmailSettings.EnableSignUpWithEmail) 227 props["EnableSignInWithEmail"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithEmail) 228 props["EnableSignInWithUsername"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithUsername) 229 230 props["EmailLoginButtonColor"] = *c.EmailSettings.LoginButtonColor 231 props["EmailLoginButtonBorderColor"] = *c.EmailSettings.LoginButtonBorderColor 232 props["EmailLoginButtonTextColor"] = *c.EmailSettings.LoginButtonTextColor 233 234 props["EnableSignUpWithGitLab"] = strconv.FormatBool(*c.GitLabSettings.Enable) 235 236 props["TermsOfServiceLink"] = *c.SupportSettings.TermsOfServiceLink 237 props["PrivacyPolicyLink"] = *c.SupportSettings.PrivacyPolicyLink 238 props["AboutLink"] = *c.SupportSettings.AboutLink 239 props["HelpLink"] = *c.SupportSettings.HelpLink 240 props["ReportAProblemLink"] = *c.SupportSettings.ReportAProblemLink 241 props["SupportEmail"] = *c.SupportSettings.SupportEmail 242 props["EnableAskCommunityLink"] = strconv.FormatBool(*c.SupportSettings.EnableAskCommunityLink) 243 244 props["DefaultClientLocale"] = *c.LocalizationSettings.DefaultClientLocale 245 246 props["EnableCustomEmoji"] = strconv.FormatBool(*c.ServiceSettings.EnableCustomEmoji) 247 props["AppDownloadLink"] = *c.NativeAppSettings.AppDownloadLink 248 props["AndroidAppDownloadLink"] = *c.NativeAppSettings.AndroidAppDownloadLink 249 props["IosAppDownloadLink"] = *c.NativeAppSettings.IosAppDownloadLink 250 251 props["DiagnosticId"] = diagnosticID 252 props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics) 253 254 props["HasImageProxy"] = strconv.FormatBool(*c.ImageProxySettings.Enable) 255 256 props["PluginsEnabled"] = strconv.FormatBool(*c.PluginSettings.Enable) 257 258 props["PasswordMinimumLength"] = fmt.Sprintf("%v", *c.PasswordSettings.MinimumLength) 259 props["PasswordRequireLowercase"] = strconv.FormatBool(*c.PasswordSettings.Lowercase) 260 props["PasswordRequireUppercase"] = strconv.FormatBool(*c.PasswordSettings.Uppercase) 261 props["PasswordRequireNumber"] = strconv.FormatBool(*c.PasswordSettings.Number) 262 props["PasswordRequireSymbol"] = strconv.FormatBool(*c.PasswordSettings.Symbol) 263 264 // Set default values for all options that require a license. 265 props["EnableCustomBrand"] = "false" 266 props["CustomBrandText"] = "" 267 props["CustomDescriptionText"] = "" 268 props["EnableLdap"] = "false" 269 props["LdapLoginFieldName"] = "" 270 props["LdapLoginButtonColor"] = "" 271 props["LdapLoginButtonBorderColor"] = "" 272 props["LdapLoginButtonTextColor"] = "" 273 props["EnableSaml"] = "false" 274 props["SamlLoginButtonText"] = "" 275 props["SamlLoginButtonColor"] = "" 276 props["SamlLoginButtonBorderColor"] = "" 277 props["SamlLoginButtonTextColor"] = "" 278 props["EnableSignUpWithGoogle"] = "false" 279 props["EnableSignUpWithOffice365"] = "false" 280 props["EnableCustomBrand"] = strconv.FormatBool(*c.TeamSettings.EnableCustomBrand) 281 props["CustomBrandText"] = *c.TeamSettings.CustomBrandText 282 props["CustomDescriptionText"] = *c.TeamSettings.CustomDescriptionText 283 props["EnableMultifactorAuthentication"] = strconv.FormatBool(*c.ServiceSettings.EnableMultifactorAuthentication) 284 props["EnforceMultifactorAuthentication"] = "false" 285 props["EnableGuestAccounts"] = strconv.FormatBool(*c.GuestAccountsSettings.Enable) 286 props["GuestAccountsEnforceMultifactorAuthentication"] = strconv.FormatBool(*c.GuestAccountsSettings.EnforceMultifactorAuthentication) 287 288 if license != nil { 289 if *license.Features.LDAP { 290 props["EnableLdap"] = strconv.FormatBool(*c.LdapSettings.Enable) 291 props["LdapLoginFieldName"] = *c.LdapSettings.LoginFieldName 292 props["LdapLoginButtonColor"] = *c.LdapSettings.LoginButtonColor 293 props["LdapLoginButtonBorderColor"] = *c.LdapSettings.LoginButtonBorderColor 294 props["LdapLoginButtonTextColor"] = *c.LdapSettings.LoginButtonTextColor 295 } 296 297 if *license.Features.SAML { 298 props["EnableSaml"] = strconv.FormatBool(*c.SamlSettings.Enable) 299 props["SamlLoginButtonText"] = *c.SamlSettings.LoginButtonText 300 props["SamlLoginButtonColor"] = *c.SamlSettings.LoginButtonColor 301 props["SamlLoginButtonBorderColor"] = *c.SamlSettings.LoginButtonBorderColor 302 props["SamlLoginButtonTextColor"] = *c.SamlSettings.LoginButtonTextColor 303 } 304 305 if *license.Features.GoogleOAuth { 306 props["EnableSignUpWithGoogle"] = strconv.FormatBool(*c.GoogleSettings.Enable) 307 } 308 309 if *license.Features.Office365OAuth { 310 props["EnableSignUpWithOffice365"] = strconv.FormatBool(*c.Office365Settings.Enable) 311 } 312 313 if *license.Features.CustomTermsOfService { 314 props["EnableCustomTermsOfService"] = strconv.FormatBool(*c.SupportSettings.CustomTermsOfServiceEnabled) 315 props["CustomTermsOfServiceReAcceptancePeriod"] = strconv.FormatInt(int64(*c.SupportSettings.CustomTermsOfServiceReAcceptancePeriod), 10) 316 } 317 318 if *license.Features.MFA { 319 props["EnforceMultifactorAuthentication"] = strconv.FormatBool(*c.ServiceSettings.EnforceMultifactorAuthentication) 320 } 321 } 322 323 return props 324 }