From c4a3118e9f885e92bb9b7d882898e9a51fc3be69 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Tue, 2 Aug 2016 16:37:09 -0400 Subject: PLT-3408 Add SiteURL to config.json (#3692) * PLT-3408 Changed serverside code to get the service's URL from config.json * PLT-3408 Changed most clientside code to use the SiteURL config setting instead of window.location * PLT-3408 Changed default SiteURL to be autodetected --- api/context.go | 16 +++---- api/post.go | 1 - config/config.json | 1 + i18n/en.json | 4 ++ mattermost.go | 21 ++------- model/config.go | 17 +++++++ utils/config.go | 7 ++- webapp/actions/websocket_actions.jsx | 22 +++++++-- webapp/components/change_url_modal.jsx | 5 +- webapp/components/channel_header.jsx | 2 +- webapp/components/channel_info_modal.jsx | 3 +- .../components/create_team/components/team_url.jsx | 2 +- webapp/components/file_attachment.jsx | 2 +- .../components/installed_incoming_webhook.jsx | 2 +- webapp/components/login/login_controller.jsx | 2 +- webapp/components/more_channels.jsx | 2 +- webapp/components/more_direct_channels.jsx | 2 +- webapp/components/navbar_dropdown.jsx | 4 +- webapp/components/needs_team.jsx | 2 +- webapp/components/new_channel_flow.jsx | 3 +- webapp/components/popover_list_members.jsx | 3 +- webapp/components/removed_from_channel_modal.jsx | 4 +- webapp/components/search_results_item.jsx | 3 +- webapp/routes/route_team.jsx | 3 +- webapp/stores/team_store.jsx | 18 +++---- webapp/utils/utils.jsx | 55 +--------------------- 26 files changed, 89 insertions(+), 117 deletions(-) diff --git a/api/context.go b/api/context.go index b26778711..6976feb8f 100644 --- a/api/context.go +++ b/api/context.go @@ -39,7 +39,6 @@ type Context struct { Err *model.AppError teamURLValid bool teamURL string - siteURL string T goi18n.TranslateFunc Locale string TeamId string @@ -139,8 +138,11 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { isTokenFromQueryString = true } - protocol := GetProtocol(r) - c.SetSiteURL(protocol + "://" + r.Host) + // 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 == "" { + *utils.Cfg.ServiceSettings.SiteURL = GetProtocol(r) + "://" + r.Host + utils.RegenerateClientConfig() + } w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId) w.Header().Set(model.HEADER_VERSION_ID, fmt.Sprintf("%v.%v", model.CurrentVersion, utils.CfgLastModified)) @@ -180,7 +182,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { c.Path = r.URL.Path } else { splitURL := strings.Split(r.URL.Path, "/") - c.setTeamURL(protocol+"://"+r.Host+"/"+splitURL[1], true) + c.setTeamURL(c.GetSiteURL()+"/"+splitURL[1], true) c.Path = "/" + strings.Join(splitURL[2:], "/") } @@ -431,10 +433,6 @@ func (c *Context) SetTeamURLFromSession() { } } -func (c *Context) SetSiteURL(url string) { - c.siteURL = url -} - func (c *Context) GetTeamURLFromTeam(team *model.Team) string { return c.GetSiteURL() + "/" + team.Name } @@ -450,7 +448,7 @@ func (c *Context) GetTeamURL() string { } func (c *Context) GetSiteURL() string { - return c.siteURL + return *utils.Cfg.ServiceSettings.SiteURL } func IsApiCall(r *http.Request) bool { diff --git a/api/post.go b/api/post.go index c363ff076..223e8ee15 100644 --- a/api/post.go +++ b/api/post.go @@ -457,7 +457,6 @@ func handleWebhookEvents(c *Context, post *model.Post, team *model.Team, channel Err: nil, teamURLValid: c.teamURLValid, teamURL: c.teamURL, - siteURL: c.siteURL, T: c.T, Locale: c.Locale, TeamId: hook.TeamId, diff --git a/config/config.json b/config/config.json index 417f2ca2c..fdb8fd755 100644 --- a/config/config.json +++ b/config/config.json @@ -1,5 +1,6 @@ { "ServiceSettings": { + "SiteURL": "", "ListenAddress": ":8065", "MaximumLoginAttempts": 10, "SegmentDeveloperKey": "", diff --git a/i18n/en.json b/i18n/en.json index 425bffd5f..34c435b82 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -2815,6 +2815,10 @@ "id": "model.config.is_valid.saml_username_attribute.app_error", "translation": "Invalid Username attribute. Must be set." }, + { + "id": "model.config.is_valid.site_url.app_error", + "translation": "Site URL must be a valid URL and start with http:// or https://" + }, { "id": "model.config.is_valid.sitename_length.app_error", "translation": "Site name must be less than or equal to {{.MaxLength}} characters." diff --git a/mattermost.go b/mattermost.go index 68f7f26da..1b93fe8df 100644 --- a/mattermost.go +++ b/mattermost.go @@ -70,7 +70,6 @@ var flagEmail string var flagPassword string var flagTeamName string var flagChannelName string -var flagSiteURL string var flagConfirmBackup string var flagRole string var flagRunCmds bool @@ -290,7 +289,6 @@ func parseCmds() { flag.StringVar(&flagPassword, "password", "", "") flag.StringVar(&flagTeamName, "team_name", "", "") flag.StringVar(&flagChannelName, "channel_name", "", "") - flag.StringVar(&flagSiteURL, "site_url", "", "") flag.StringVar(&flagConfirmBackup, "confirm_backup", "", "") flag.StringVar(&flagFromAuth, "from_auth", "", "") flag.StringVar(&flagToAuth, "to_auth", "", "") @@ -863,16 +861,8 @@ func cmdInviteUser() { os.Exit(1) } - if len(flagSiteURL) == 0 { - fmt.Fprintln(os.Stderr, "flag needs an argument: -site_url") - flag.Usage() - os.Exit(1) - } - - // basic validation of the URL format - if _, err := url.ParseRequestURI(flagSiteURL); err != nil { - fmt.Fprintln(os.Stderr, "-site_url flag is invalid. It should look like http://example.com") - flag.Usage() + if len(*utils.Cfg.ServiceSettings.SiteURL) == 0 { + fmt.Fprintln(os.Stderr, "SiteURL must be specified in config.json") os.Exit(1) } @@ -894,7 +884,6 @@ func cmdInviteUser() { invites := []string{flagEmail} c := getMockContext() - c.SetSiteURL(strings.TrimSuffix(flagSiteURL, "/")) api.InviteMembers(c, team, user, invites) os.Exit(0) @@ -1590,8 +1579,6 @@ FLAGS: -team_name="name" The team name used in other commands - -site_url="url" The site URL used in other commands - -role="system_admin" The role used in other commands valid values are "" - The empty role is basic user @@ -1611,9 +1598,9 @@ COMMANDS: platform -create_user -team_name="name" -email="user@example.com" -password="mypassword" -username="user" -invite_user Invites a user to a team by email. It requires the -team_name - , -email and -site_url flags. + and -email flags. Example: - platform -invite_user -team_name="name" -email="user@example.com" -site_url="https://mattermost.example.com" + platform -invite_user -team_name="name" -email="user@example.com" -leave_team Removes a user from a team. It requires the -team_name and -email. diff --git a/model/config.go b/model/config.go index 85b71cb2a..b239c83ca 100644 --- a/model/config.go +++ b/model/config.go @@ -6,6 +6,7 @@ package model import ( "encoding/json" "io" + "net/url" ) const ( @@ -50,6 +51,7 @@ const ( ) type ServiceSettings struct { + SiteURL *string ListenAddress string MaximumLoginAttempts int SegmentDeveloperKey string @@ -363,6 +365,11 @@ func (o *Config) SetDefaults() { o.EmailSettings.PasswordResetSalt = NewRandomString(32) } + if o.ServiceSettings.SiteURL == nil { + o.ServiceSettings.SiteURL = new(string) + *o.ServiceSettings.SiteURL = "" + } + if o.ServiceSettings.EnableDeveloper == nil { o.ServiceSettings.EnableDeveloper = new(bool) *o.ServiceSettings.EnableDeveloper = false @@ -832,6 +839,16 @@ func (o *Config) IsValid() *AppError { return NewLocAppError("Config.IsValid", "model.config.is_valid.login_attempts.app_error", nil, "") } + if len(*o.ServiceSettings.SiteURL) != 0 { + if _, err := url.ParseRequestURI(*o.ServiceSettings.SiteURL); err != nil { + return NewLocAppError("Config.IsValid", "model.config.is_valid.site_url.app_error", nil, "") + } + } + + if len(o.ServiceSettings.ListenAddress) == 0 { + 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, "") } diff --git a/utils/config.go b/utils/config.go index 194aba5f4..868e96b51 100644 --- a/utils/config.go +++ b/utils/config.go @@ -185,7 +185,7 @@ func LoadConfig(fileName string) { } Cfg = &config - ClientCfg = getClientConfig(Cfg) + RegenerateClientConfig() // Actions that need to run every time the config is loaded if ldapI := einterfaces.GetLdapInterface(); ldapI != nil { @@ -198,6 +198,10 @@ func LoadConfig(fileName string) { } } +func RegenerateClientConfig() { + ClientCfg = getClientConfig(Cfg) +} + func getClientConfig(c *model.Config) map[string]string { props := make(map[string]string) @@ -208,6 +212,7 @@ func getClientConfig(c *model.Config) map[string]string { props["BuildHashEnterprise"] = model.BuildHashEnterprise props["BuildEnterpriseReady"] = model.BuildEnterpriseReady + props["SiteURL"] = *c.ServiceSettings.SiteURL props["SiteName"] = c.TeamSettings.SiteName props["EnableTeamCreation"] = strconv.FormatBool(c.TeamSettings.EnableTeamCreation) props["EnableUserCreation"] = strconv.FormatBool(c.TeamSettings.EnableUserCreation) diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx index 61503c68a..e93b2d25b 100644 --- a/webapp/actions/websocket_actions.jsx +++ b/webapp/actions/websocket_actions.jsx @@ -32,12 +32,26 @@ const MAX_WEBSOCKET_FAILS = 7; export function initialize() { if (window.WebSocket) { - let protocol = 'ws://'; - if (window.location.protocol === 'https:') { - protocol = 'wss://'; + let connUrl = window.mm_config.SiteURL; + + // replace the protocol with a websocket one + if (connUrl.startsWith('https:')) { + connUrl = connUrl.replace(/^https:/, 'wss:'); + } else { + connUrl = connUrl.replace(/^http:/, 'ws:'); + } + + // append a port number if one isn't already specified + if (!(/:\d+$/).test(connUrl)) { + if (connUrl.startsWith('wss:')) { + connUrl += ':' + global.window.mm_config.WebsocketSecurePort; + } else { + connUrl += ':' + global.window.mm_config.WebsocketPort; + } } - const connUrl = protocol + location.host + ((/:\d+/).test(location.host) ? '' : Utils.getWebsocketPort(protocol)) + Client.getUsersRoute() + '/websocket'; + // append the websocket api path + connUrl += Client.getUsersRoute() + '/websocket'; WebSocketClient.setEventCallback(handleEvent); WebSocketClient.setReconnectCallback(handleReconnect); diff --git a/webapp/components/change_url_modal.jsx b/webapp/components/change_url_modal.jsx index 9a526a9ee..2219ff317 100644 --- a/webapp/components/change_url_modal.jsx +++ b/webapp/components/change_url_modal.jsx @@ -4,6 +4,7 @@ import ReactDOM from 'react-dom'; import Constants from 'utils/constants.jsx'; import {Modal, Tooltip, OverlayTrigger} from 'react-bootstrap'; +import TeamStore from 'stores/team_store.jsx'; import * as Utils from 'utils/utils.jsx'; import {FormattedMessage} from 'react-intl'; @@ -130,8 +131,8 @@ export default class ChangeUrlModal extends React.Component { serverError =

{this.props.serverError}

; } - const fullTeamUrl = Utils.getTeamURLFromAddressBar(); - const teamURL = Utils.getShortenedTeamURL(); + const fullTeamUrl = TeamStore.getCurrentTeamUrl(); + const teamURL = Utils.getShortenedTeamURL(TeamStore.getCurrentTeamUrl()); const urlTooltip = ( {fullTeamUrl} ); diff --git a/webapp/components/channel_header.jsx b/webapp/components/channel_header.jsx index 573949a5e..f26105c7a 100644 --- a/webapp/components/channel_header.jsx +++ b/webapp/components/channel_header.jsx @@ -123,7 +123,7 @@ export default class ChannelHeader extends React.Component { }); const townsquare = ChannelStore.getByName('town-square'); - browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + townsquare.name); + browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + townsquare.name); }, (err) => { AsyncClient.dispatchError(err, 'handleLeave'); diff --git a/webapp/components/channel_info_modal.jsx b/webapp/components/channel_info_modal.jsx index b0e2c63fa..7e0ff3873 100644 --- a/webapp/components/channel_info_modal.jsx +++ b/webapp/components/channel_info_modal.jsx @@ -5,6 +5,7 @@ import * as Utils from 'utils/utils.jsx'; import {FormattedMessage} from 'react-intl'; import {Modal} from 'react-bootstrap'; +import TeamStore from 'stores/team_store.jsx'; import * as TextFormatting from 'utils/text_formatting.jsx'; import React from 'react'; @@ -44,7 +45,7 @@ export default class ChannelInfoModal extends React.Component { channelIcon = (); } - const channelURL = Utils.getTeamURLFromAddressBar() + '/channels/' + channel.name; + const channelURL = TeamStore.getCurrentTeamUrl() + '/channels/' + channel.name; let channelPurpose = null; if (channel.purpose) { diff --git a/webapp/components/create_team/components/team_url.jsx b/webapp/components/create_team/components/team_url.jsx index 0fe047ccd..bcbe0a1a1 100644 --- a/webapp/components/create_team/components/team_url.jsx +++ b/webapp/components/create_team/components/team_url.jsx @@ -105,7 +105,7 @@ export default class TeamUrl extends React.Component { nameDivClass += ' has-error'; } - const title = `${Utils.getWindowLocationOrigin()}/`; + const title = `${window.mm_config.SiteURL}/`; const urlTooltip = ( {title} ); diff --git a/webapp/components/file_attachment.jsx b/webapp/components/file_attachment.jsx index f9c361afc..cba9d8288 100644 --- a/webapp/components/file_attachment.jsx +++ b/webapp/components/file_attachment.jsx @@ -102,7 +102,7 @@ class FileAttachment extends React.Component { getFileInfoFromName(name) { var fileInfo = utils.splitFileLocation(name); - fileInfo.path = utils.getWindowLocationOrigin() + Client.getFilesRoute() + '/get' + fileInfo.path; + fileInfo.path = Client.getFilesRoute() + '/get' + fileInfo.path; return fileInfo; } diff --git a/webapp/components/integrations/components/installed_incoming_webhook.jsx b/webapp/components/integrations/components/installed_incoming_webhook.jsx index 2cf3f24b8..008000012 100644 --- a/webapp/components/integrations/components/installed_incoming_webhook.jsx +++ b/webapp/components/integrations/components/installed_incoming_webhook.jsx @@ -97,7 +97,7 @@ export default class InstalledIncomingWebhook extends React.Component { id='installed_integrations.url' defaultMessage='URL: {url}' values={{ - url: Utils.getWindowLocationOrigin() + '/hooks/' + incomingWebhook.id + url: window.mm_config.SiteURL + '/hooks/' + incomingWebhook.id }} /> diff --git a/webapp/components/login/login_controller.jsx b/webapp/components/login/login_controller.jsx index 52f36bb2a..69981cfd6 100644 --- a/webapp/components/login/login_controller.jsx +++ b/webapp/components/login/login_controller.jsx @@ -277,7 +277,7 @@ export default class LoginController extends React.Component { } createLoginOptions() { - const extraParam = Utils.getUrlParameter('extra'); + const extraParam = this.props.location.query.extra; let extraBox = ''; if (extraParam) { if (extraParam === Constants.SIGNIN_CHANGE) { diff --git a/webapp/components/more_channels.jsx b/webapp/components/more_channels.jsx index b7ffff712..724cd2f60 100644 --- a/webapp/components/more_channels.jsx +++ b/webapp/components/more_channels.jsx @@ -74,7 +74,7 @@ export default class MoreChannels extends React.Component { channel, () => { $(ReactDOM.findDOMNode(this.refs.modal)).modal('hide'); - browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name); + browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + channel.name); this.setState({joiningChannel: ''}); }, (err) => { diff --git a/webapp/components/more_direct_channels.jsx b/webapp/components/more_direct_channels.jsx index c74df5d1d..24718387e 100644 --- a/webapp/components/more_direct_channels.jsx +++ b/webapp/components/more_direct_channels.jsx @@ -87,7 +87,7 @@ export default class MoreDirectChannels extends React.Component { Utils.openDirectChannelToUser( teammate, (channel) => { - browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name); + browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/' + channel.name); this.setState({loadingDMChannel: -1}); this.handleHide(); }, diff --git a/webapp/components/navbar_dropdown.jsx b/webapp/components/navbar_dropdown.jsx index 81bd31269..f82bd564e 100644 --- a/webapp/components/navbar_dropdown.jsx +++ b/webapp/components/navbar_dropdown.jsx @@ -88,7 +88,7 @@ export default class NavbarDropdown extends React.Component { return (
  • - + - + { - browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name); + browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + channel.name); if (channelAlreadyExisted) { this.closePopover(); } diff --git a/webapp/components/removed_from_channel_modal.jsx b/webapp/components/removed_from_channel_modal.jsx index 3bdceadf7..228132803 100644 --- a/webapp/components/removed_from_channel_modal.jsx +++ b/webapp/components/removed_from_channel_modal.jsx @@ -4,10 +4,10 @@ import $ from 'jquery'; import ReactDOM from 'react-dom'; import ChannelStore from 'stores/channel_store.jsx'; +import TeamStore from 'stores/team_store.jsx'; import UserStore from 'stores/user_store.jsx'; import BrowserStore from 'stores/browser_store.jsx'; -import * as Utils from 'utils/utils.jsx'; import {FormattedMessage} from 'react-intl'; import {browserHistory} from 'react-router/es6'; @@ -36,7 +36,7 @@ export default class RemovedFromChannelModal extends React.Component { var townSquare = ChannelStore.getByName('town-square'); setTimeout( () => { - browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + townSquare.name); + browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + townSquare.name); }, 1); diff --git a/webapp/components/search_results_item.jsx b/webapp/components/search_results_item.jsx index 217cd5568..fb8b23a7f 100644 --- a/webapp/components/search_results_item.jsx +++ b/webapp/components/search_results_item.jsx @@ -4,6 +4,7 @@ import $ from 'jquery'; import UserProfile from './user_profile.jsx'; +import TeamStore from 'stores/team_store.jsx'; import UserStore from 'stores/user_store.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; @@ -151,7 +152,7 @@ export default class SearchResultsItem extends React.Component { this.hideSidebar(); } this.shrinkSidebar(); - browserHistory.push('/' + window.location.pathname.split('/')[1] + '/pl/' + post.id); + browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/pl/' + post.id); } } className='search-item__jump' diff --git a/webapp/routes/route_team.jsx b/webapp/routes/route_team.jsx index 27817710f..15217bfd2 100644 --- a/webapp/routes/route_team.jsx +++ b/webapp/routes/route_team.jsx @@ -12,7 +12,6 @@ import Constants from 'utils/constants.jsx'; const ActionTypes = Constants.ActionTypes; import * as AsyncClient from 'utils/async_client.jsx'; import Client from 'client/web_client.jsx'; -import * as Utils from 'utils/utils.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import emojiRoute from 'routes/route_emoji.jsx'; @@ -57,7 +56,7 @@ function doChannelChange(state, replace, callback) { function preNeedsTeam(nextState, replace, callback) { // First check to make sure you're in the current team // for the current url. - var teamName = Utils.getTeamNameFromUrl(); + const teamName = nextState.params.team; var team = TeamStore.getByName(teamName); const oldTeamId = TeamStore.getCurrentId(); diff --git a/webapp/stores/team_store.jsx b/webapp/stores/team_store.jsx index f4383589a..a482fa3a1 100644 --- a/webapp/stores/team_store.jsx +++ b/webapp/stores/team_store.jsx @@ -11,12 +11,6 @@ const ActionTypes = Constants.ActionTypes; const CHANGE_EVENT = 'change'; var Utils; -function getWindowLocationOrigin() { - if (!Utils) { - Utils = require('utils/utils.jsx'); //eslint-disable-line global-require - } - return Utils.getWindowLocationOrigin(); -} class TeamStoreClass extends EventEmitter { constructor() { @@ -87,23 +81,23 @@ class TeamStoreClass extends EventEmitter { getCurrentTeamUrl() { if (this.getCurrent()) { - return getWindowLocationOrigin() + '/' + this.getCurrent().name; + return window.mm_config.SiteURL + '/' + this.getCurrent().name; } - return null; + return ''; } getCurrentTeamRelativeUrl() { if (this.getCurrent()) { return '/' + this.getCurrent().name; } - return null; + return ''; } getCurrentInviteLink() { const current = this.getCurrent(); if (current) { - return getWindowLocationOrigin() + '/signup_user_complete/?id=' + current.invite_id; + return window.mm_config.SiteURL + '/signup_user_complete/?id=' + current.invite_id; } return ''; @@ -112,10 +106,10 @@ class TeamStoreClass extends EventEmitter { getTeamUrl(id) { const team = this.get(id); if (team) { - return getWindowLocationOrigin() + '/' + team.name; + return window.mm_config.SiteURL + '/' + team.name; } - return null; + return ''; } saveTeam(team) { diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx index c4cee3235..4b3c8518c 100644 --- a/webapp/utils/utils.jsx +++ b/webapp/utils/utils.jsx @@ -99,20 +99,6 @@ export function isSystemAdmin(roles) { return false; } -export function getDomainWithOutSub() { - var parts = window.location.host.split('.'); - - if (parts.length === 1) { - if (parts[0].indexOf('dockerhost') > -1) { - return 'dockerhost:8065'; - } - - return 'localhost:8065'; - } - - return parts[1] + '.' + parts[2]; -} - export function getCookie(name) { var value = '; ' + document.cookie; var parts = value.split('; ' + name + '='); @@ -171,18 +157,6 @@ export function ding() { } } -export function getUrlParameter(sParam) { - var sPageURL = window.location.search.substring(1); - var sURLVariables = sPageURL.split('&'); - for (var i = 0; i < sURLVariables.length; i++) { - var sParameterName = sURLVariables[i].split('='); - if (sParameterName[0] === sParam) { - return sParameterName[1]; - } - } - return null; -} - export function getDateForUnixTicks(ticks) { return new Date(ticks); } @@ -1015,18 +989,6 @@ export function displayUsernameForUser(user) { return username; } -//IE10 does not set window.location.origin automatically so this must be called instead when using it -export function getWindowLocationOrigin() { - var windowLocationOrigin = window.location.origin; - if (!windowLocationOrigin) { - windowLocationOrigin = window.location.protocol + '//' + window.location.hostname; - if (window.location.port) { - windowLocationOrigin += ':' + window.location.port; - } - } - return windowLocationOrigin; -} - // Converts a file size in bytes into a human-readable string of the form '123MB'. export function fileSizeToString(bytes) { // it's unlikely that we'll have files bigger than this @@ -1045,7 +1007,7 @@ export function fileSizeToString(bytes) { // Converts a filename (like those attached to Post objects) to a url that can be used to retrieve attachments from the server. export function getFileUrl(filename) { - return getWindowLocationOrigin() + Client.getFilesRoute() + '/get' + filename; + return Client.getFilesRoute() + '/get' + filename; } // Gets the name of a file (including extension) from a given url or file path. @@ -1151,20 +1113,7 @@ export function importSlack(file, success, error) { Client.importSlack(formData, success, error); } -export function getTeamURLFromAddressBar() { - return window.location.origin + '/' + window.location.pathname.split('/')[1]; -} - -export function getTeamNameFromUrl() { - return window.location.pathname.split('/')[1]; -} - -export function getTeamURLNoOriginFromAddressBar() { - return '/' + window.location.pathname.split('/')[1]; -} - -export function getShortenedTeamURL() { - const teamURL = getTeamURLFromAddressBar(); +export function getShortenedTeamURL(teamURL = '') { if (teamURL.length > 35) { return teamURL.substring(0, 10) + '...' + teamURL.substring(teamURL.length - 12, teamURL.length) + '/'; } -- cgit v1.2.3-1-g7c22