Changed autodetection of SiteURL (#3764)

* Changed autoconfiguration of SiteURL to be done on every request

* Added SiteURL to system console
Этот коммит содержится в:
Harrison Healey
2016-08-09 09:53:22 -04:00
коммит произвёл enahum
родитель 09d98b486e
Коммит 0afa28de09
11 изменённых файлов: 56 добавлений и 32 удалений

Просмотреть файл

@@ -39,6 +39,7 @@ type Context struct {
Err *model.AppError Err *model.AppError
teamURLValid bool teamURLValid bool
teamURL string teamURL string
siteURL string
T goi18n.TranslateFunc T goi18n.TranslateFunc
Locale string Locale string
TeamId string TeamId string
@@ -141,10 +142,11 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
isTokenFromQueryString = true isTokenFromQueryString = true
} }
// if the site url in the config isn't specified, infer if from this request and write it back to the config if *utils.Cfg.ServiceSettings.SiteURL != "" {
if *utils.Cfg.ServiceSettings.SiteURL == "" { c.SetSiteURL(*utils.Cfg.ServiceSettings.SiteURL)
*utils.Cfg.ServiceSettings.SiteURL = GetProtocol(r) + "://" + r.Host } else {
utils.RegenerateClientConfig() protocol := GetProtocol(r)
c.SetSiteURL(protocol + "://" + r.Host)
} }
w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId) w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId)
@@ -439,6 +441,10 @@ func (c *Context) SetTeamURLFromSession() {
} }
} }
func (c *Context) SetSiteURL(url string) {
c.siteURL = url
}
func (c *Context) GetTeamURLFromTeam(team *model.Team) string { func (c *Context) GetTeamURLFromTeam(team *model.Team) string {
return c.GetSiteURL() + "/" + team.Name return c.GetSiteURL() + "/" + team.Name
} }
@@ -454,7 +460,7 @@ func (c *Context) GetTeamURL() string {
} }
func (c *Context) GetSiteURL() string { func (c *Context) GetSiteURL() string {
return *utils.Cfg.ServiceSettings.SiteURL return c.siteURL
} }
func IsApiCall(r *http.Request) bool { func IsApiCall(r *http.Request) bool {

Просмотреть файл

@@ -458,6 +458,7 @@ func handleWebhookEvents(c *Context, post *model.Post, team *model.Team, channel
Err: nil, Err: nil,
teamURLValid: c.teamURLValid, teamURLValid: c.teamURLValid,
teamURL: c.teamURL, teamURL: c.teamURL,
siteURL: c.siteURL,
T: c.T, T: c.T,
Locale: c.Locale, Locale: c.Locale,
TeamId: hook.TeamId, TeamId: hook.TeamId,

Просмотреть файл

@@ -870,10 +870,6 @@ func (o *Config) IsValid() *AppError {
return NewLocAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "") return NewLocAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "")
} }
if len(o.ServiceSettings.ListenAddress) == 0 {
return NewLocAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "")
}
if o.TeamSettings.MaxUsersPerTeam <= 0 { if o.TeamSettings.MaxUsersPerTeam <= 0 {
return NewLocAppError("Config.IsValid", "model.config.is_valid.max_users.app_error", nil, "") return NewLocAppError("Config.IsValid", "model.config.is_valid.max_users.app_error", nil, "")
} }

Просмотреть файл

@@ -186,7 +186,7 @@ func LoadConfig(fileName string) {
Cfg = &config Cfg = &config
CfgHash = fmt.Sprintf("%x", md5.Sum([]byte(Cfg.ToJson()))) CfgHash = fmt.Sprintf("%x", md5.Sum([]byte(Cfg.ToJson())))
RegenerateClientConfig() ClientCfg = getClientConfig(Cfg)
// Actions that need to run every time the config is loaded // Actions that need to run every time the config is loaded
if ldapI := einterfaces.GetLdapInterface(); ldapI != nil { if ldapI := einterfaces.GetLdapInterface(); ldapI != nil {
@@ -199,10 +199,6 @@ func LoadConfig(fileName string) {
} }
} }
func RegenerateClientConfig() {
ClientCfg = getClientConfig(Cfg)
}
func getClientConfig(c *model.Config) map[string]string { func getClientConfig(c *model.Config) map[string]string {
props := make(map[string]string) props := make(map[string]string)

Просмотреть файл

@@ -32,7 +32,7 @@ const MAX_WEBSOCKET_FAILS = 7;
export function initialize() { export function initialize() {
if (window.WebSocket) { if (window.WebSocket) {
let connUrl = window.mm_config.SiteURL; let connUrl = Utils.getSiteURL();
// replace the protocol with a websocket one // replace the protocol with a websocket one
if (connUrl.startsWith('https:')) { if (connUrl.startsWith('https:')) {

Просмотреть файл

@@ -28,6 +28,7 @@ export default class ConfigurationSettings extends AdminSettings {
} }
getConfigFromState(config) { getConfigFromState(config) {
config.ServiceSettings.SiteURL = this.state.siteURL;
config.ServiceSettings.ListenAddress = this.state.listenAddress; config.ServiceSettings.ListenAddress = this.state.listenAddress;
config.ServiceSettings.WebserverMode = this.state.webserverMode; config.ServiceSettings.WebserverMode = this.state.webserverMode;
@@ -36,6 +37,7 @@ export default class ConfigurationSettings extends AdminSettings {
getStateFromConfig(config) { getStateFromConfig(config) {
return { return {
siteURL: config.ServiceSettings.SiteURL,
listenAddress: config.ServiceSettings.ListenAddress, listenAddress: config.ServiceSettings.ListenAddress,
webserverMode: config.ServiceSettings.WebserverMode webserverMode: config.ServiceSettings.WebserverMode
}; };
@@ -55,6 +57,24 @@ export default class ConfigurationSettings extends AdminSettings {
renderSettings() { renderSettings() {
return ( return (
<SettingsGroup> <SettingsGroup>
<TextSetting
id='siteURL'
label={
<FormattedMessage
id='admin.service.siteURL'
defaultMessage='Site URL:'
/>
}
placeholder={Utils.localizeMessage('admin.service.siteURLExample', 'Ex "https://mattermost.example.com:1234"')}
helpText={
<FormattedMessage
id='admin.service.siteURLDescription'
defaultMessage='The URL, including port number and protocol, from which users will access Mattermost. Leave blank to automatically configure based on incoming traffic.'
/>
}
value={this.state.siteURL}
onChange={this.handleChange}
/>
<TextSetting <TextSetting
id='listenAddress' id='listenAddress'
label={ label={

Просмотреть файл

@@ -105,7 +105,7 @@ export default class TeamUrl extends React.Component {
nameDivClass += ' has-error'; nameDivClass += ' has-error';
} }
const title = `${window.mm_config.SiteURL}/`; const title = `${Utils.getSiteURL()}/`;
const urlTooltip = ( const urlTooltip = (
<Tooltip id='urlTooltip'>{title}</Tooltip> <Tooltip id='urlTooltip'>{title}</Tooltip>
); );

Просмотреть файл

@@ -97,7 +97,7 @@ export default class InstalledIncomingWebhook extends React.Component {
id='installed_integrations.url' id='installed_integrations.url'
defaultMessage='URL: {url}' defaultMessage='URL: {url}'
values={{ values={{
url: window.mm_config.SiteURL + '/hooks/' + incomingWebhook.id url: Utils.getSiteURL() + '/hooks/' + incomingWebhook.id
}} }}
/> />
</span> </span>

Просмотреть файл

@@ -640,6 +640,9 @@
"admin.service.sessionCache": "Session Cache (minutes):", "admin.service.sessionCache": "Session Cache (minutes):",
"admin.service.sessionCacheDesc": "The number of minutes to cache a session in memory.", "admin.service.sessionCacheDesc": "The number of minutes to cache a session in memory.",
"admin.service.sessionDaysEx": "Ex \"30\"", "admin.service.sessionDaysEx": "Ex \"30\"",
"admin.service.siteURL": "Site URL:",
"admin.service.siteURLDescription": "The URL, including port number and protocol, from which users will access Mattermost. Leave blank to automatically configure based on incoming traffic.",
"admin.service.siteURLExample": "Ex \"https://mattermost.example.com:1234\"",
"admin.service.ssoSessionDays": "Session length SSO (days):", "admin.service.ssoSessionDays": "Session length SSO (days):",
"admin.service.ssoSessionDaysDesc": "The number of days from the last time a user entered their credentials to the expiry of the user's session. If the authentication method is SAML or GitLab, the user may automatically be logged back in to Mattermost if they are already logged in to SAML or GitLab. After changing this setting, the setting will take effect after the next time the user enters their credentials.", "admin.service.ssoSessionDaysDesc": "The number of days from the last time a user entered their credentials to the expiry of the user's session. If the authentication method is SAML or GitLab, the user may automatically be logged back in to Mattermost if they are already logged in to SAML or GitLab. After changing this setting, the setting will take effect after the next time the user enters their credentials.",
"admin.service.testingDescription": "When true, /loadtest slash command is enabled to load test accounts, data and text formatting. Changing this requires a server restart before taking effect.", "admin.service.testingDescription": "When true, /loadtest slash command is enabled to load test accounts, data and text formatting. Changing this requires a server restart before taking effect.",

Просмотреть файл

@@ -60,13 +60,7 @@ class TeamStoreClass extends EventEmitter {
} }
getCurrentId() { getCurrentId() {
var team = this.get(this.currentTeamId); return this.currentTeamId;
if (team) {
return team.id;
}
return null;
} }
getCurrent() { getCurrent() {
@@ -80,10 +74,7 @@ class TeamStoreClass extends EventEmitter {
} }
getCurrentTeamUrl() { getCurrentTeamUrl() {
if (this.getCurrent()) { return this.getTeamUrl(this.currentTeamId);
return window.mm_config.SiteURL + '/' + this.getCurrent().name;
}
return '';
} }
getCurrentTeamRelativeUrl() { getCurrentTeamRelativeUrl() {
@@ -97,7 +88,10 @@ class TeamStoreClass extends EventEmitter {
const current = this.getCurrent(); const current = this.getCurrent();
if (current) { if (current) {
return window.mm_config.SiteURL + '/signup_user_complete/?id=' + current.invite_id; // can't call Utils.getSiteURL here because that introduces a circular dependency
const origin = window.mm_config.SiteURL || window.location.origin;
return origin + '/signup_user_complete/?id=' + current.invite_id;
} }
return ''; return '';
@@ -105,11 +99,15 @@ class TeamStoreClass extends EventEmitter {
getTeamUrl(id) { getTeamUrl(id) {
const team = this.get(id); const team = this.get(id);
if (team) {
return window.mm_config.SiteURL + '/' + team.name; if (!team) {
return '';
} }
return ''; // can't call Utils.getSiteURL here because that introduces a circular dependency
const origin = window.mm_config.SiteURL || window.location.origin;
return origin + '/' + team.name;
} }
saveTeam(team) { saveTeam(team) {

Просмотреть файл

@@ -1338,3 +1338,7 @@ export function isValidPassword(password) {
return errorMsg; return errorMsg;
} }
export function getSiteURL() {
return global.mm_config.SiteURL || window.location.origin;
}