From fb325cc339eb8d8efb60dbadc48fd38897201c6f Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Thu, 20 Apr 2017 11:25:45 -0400 Subject: [PATCH] PLT-5900 Removed automatic configuration of Site URL (#6135) --- Makefile | 1 + api/context.go | 7 +-- config/config.json | 2 +- .../admin_console/admin_settings.jsx | 8 ++++ .../admin_console/configuration_settings.jsx | 14 +++++- webapp/components/error_bar.jsx | 47 ++++++++++++++++++- webapp/i18n/en.json | 4 ++ webapp/stores/error_store.jsx | 4 +- 8 files changed, 76 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index af430264244..e6e9b85237d 100644 --- a/Makefile +++ b/Makefile @@ -323,6 +323,7 @@ package: build build-client @# Disable developer settings sed -i'' -e 's|"ConsoleLevel": "DEBUG"|"ConsoleLevel": "INFO"|g' $(DIST_PATH)/config/config.json + sed -i'' -e 's|"SiteURL": "http://localhost:8065"|"SiteURL": ""|g' $(DIST_PATH)/config/config.json @# Reset email sending to original configuration sed -i'' -e 's|"SendEmailNotifications": true,|"SendEmailNotifications": false,|g' $(DIST_PATH)/config/config.json diff --git a/api/context.go b/api/context.go index 1305f192aec..0f4c11826de 100644 --- a/api/context.go +++ b/api/context.go @@ -142,12 +142,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { isTokenFromQueryString = true } - if utils.GetSiteURL() == "" { - protocol := app.GetProtocol(r) - c.SetSiteURL(protocol + "://" + r.Host) - } else { - c.SetSiteURL(utils.GetSiteURL()) - } + c.SetSiteURL(utils.GetSiteURL()) w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId) w.Header().Set(model.HEADER_VERSION_ID, fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, model.BuildNumber, utils.CfgHash, utils.IsLicensed)) diff --git a/config/config.json b/config/config.json index 18594f60dd1..afbe0790b5b 100644 --- a/config/config.json +++ b/config/config.json @@ -1,6 +1,6 @@ { "ServiceSettings": { - "SiteURL": "", + "SiteURL": "http://localhost:8065", "ListenAddress": ":8065", "ConnectionSecurity": "", "TLSCertFile": "", diff --git a/webapp/components/admin_console/admin_settings.jsx b/webapp/components/admin_console/admin_settings.jsx index b9883d7d8dc..f00e77e7ca8 100644 --- a/webapp/components/admin_console/admin_settings.jsx +++ b/webapp/components/admin_console/admin_settings.jsx @@ -69,6 +69,10 @@ export default class AdminSettings extends React.Component { if (callback) { callback(); } + + if (this.handleSaved) { + this.handleSaved(config); + } }, (err) => { this.setState({ @@ -79,6 +83,10 @@ export default class AdminSettings extends React.Component { if (callback) { callback(); } + + if (this.handleSaved) { + this.handleSaved(config); + } } ); } diff --git a/webapp/components/admin_console/configuration_settings.jsx b/webapp/components/admin_console/configuration_settings.jsx index a5e5abe8724..84bac275e1e 100644 --- a/webapp/components/admin_console/configuration_settings.jsx +++ b/webapp/components/admin_console/configuration_settings.jsx @@ -3,6 +3,8 @@ import React from 'react'; +import ErrorStore from 'stores/error_store.jsx'; + import * as Utils from 'utils/utils.jsx'; import AdminSettings from './admin_settings.jsx'; @@ -21,6 +23,8 @@ export default class ConfigurationSettings extends AdminSettings { this.getConfigFromState = this.getConfigFromState.bind(this); + this.handleSaved = this.handleSaved.bind(this); + this.renderSettings = this.renderSettings.bind(this); } @@ -62,6 +66,14 @@ export default class ConfigurationSettings extends AdminSettings { }; } + handleSaved(newConfig) { + const lastError = ErrorStore.getLastError(); + + if (lastError && lastError.message === 'error_bar.site_url' && newConfig.ServiceSettings.SiteURL) { + ErrorStore.clearLastError(true); + } + } + renderTitle() { return (

@@ -96,7 +108,7 @@ export default class ConfigurationSettings extends AdminSettings { helpText={ } value={this.state.siteURL} diff --git a/webapp/components/error_bar.jsx b/webapp/components/error_bar.jsx index edb929f20d7..108f5e0884d 100644 --- a/webapp/components/error_bar.jsx +++ b/webapp/components/error_bar.jsx @@ -13,11 +13,13 @@ const StatTypes = Constants.StatTypes; import React from 'react'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; +import {Link} from 'react-router'; const EXPIRING_ERROR = 'error_bar.expiring'; const EXPIRED_ERROR = 'error_bar.expired'; const PAST_GRACE_ERROR = 'error_bar.past_grace'; const RENEWAL_LINK = 'https://licensing.mattermost.com/renew'; +const SITE_URL_ERROR = 'error_bar.site_url'; const BAR_DEVELOPER_TYPE = 'developer'; const BAR_CRITICAL_TYPE = 'critical'; @@ -38,7 +40,11 @@ export default class ErrorBar extends React.Component { isSystemAdmin = Utils.isSystemAdmin(user.roles); } - if (!ErrorStore.getIgnoreNotification() && global.window.mm_config.SendEmailNotifications === 'false') { + const errorIgnored = ErrorStore.getIgnoreNotification(); + + if (!errorIgnored && isSystemAdmin && global.mm_config.SiteURL === '') { + ErrorStore.storeLastError({notification: true, message: SITE_URL_ERROR}); + } else if (!errorIgnored && global.window.mm_config.SendEmailNotifications === 'false') { ErrorStore.storeLastError({notification: true, message: Utils.localizeMessage('error_bar.preview_mode', 'Preview Mode: Email notifications have not been configured')}); } else if (isLicensePastGracePeriod()) { if (isSystemAdmin) { @@ -157,6 +163,45 @@ export default class ErrorBar extends React.Component { defaultMessage='Enterprise license is expired and some features may be disabled. Please contact your System Administrator for details.' /> ); + } else if (message === SITE_URL_ERROR) { + let id; + let defaultMessage; + if (global.mm_config.EnableSignUpWithGitLab === 'true') { + id = 'error_bar.site_url_gitlab'; + defaultMessage = '{docsLink} is now a required setting. Please configure it in the System Console or in gitlab.rb if you\'re using GitLab Mattermost.'; + } else { + id = 'error_bar.site_url'; + defaultMessage = '{docsLink} is now a required setting. Please configure it in {link}.'; + } + + message = ( + + + + ), + link: ( + + + + ) + }} + /> + ); } return ( diff --git a/webapp/i18n/en.json b/webapp/i18n/en.json index d24bbe11b13..e8c93f11cd3 100644 --- a/webapp/i18n/en.json +++ b/webapp/i18n/en.json @@ -1291,6 +1291,10 @@ "error_bar.expiring": "Enterprise license expires on {date}. Please renew.", "error_bar.past_grace": "Enterprise license is expired and some features may be disabled. Please contact your System Administrator for details.", "error_bar.preview_mode": "Preview Mode: Email notifications have not been configured", + "error_bar.site_url": "{docsLink} is now a required setting. Please configure it in {link}.", + "error_bar.site_url.docsLink": "Site URL", + "error_bar.site_url.link": "the System Console", + "error_bar.site_url_gitlab": "{docsLink} is now a required setting. Please configure it in the System Console or in gitlab.rb if you're using GitLab Mattermost.", "file_attachment.download": "Download", "file_info_preview.size": "Size ", "file_info_preview.type": "File type ", diff --git a/webapp/stores/error_store.jsx b/webapp/stores/error_store.jsx index e37de40ac7f..3b0bb023fca 100644 --- a/webapp/stores/error_store.jsx +++ b/webapp/stores/error_store.jsx @@ -62,11 +62,11 @@ class ErrorStoreClass extends EventEmitter { BrowserStore.setGlobalItem('last_error_conn', count); } - clearLastError() { + clearLastError(force) { var lastError = this.getLastError(); // preview message can only be cleared by clearNotificationError - if (lastError && lastError.notification) { + if (!force && lastError && lastError.notification) { return; }