diff --git a/apps/files_sharing/tests/js/publicAppSpec.js b/apps/files_sharing/tests/js/publicAppSpec.js index 9d24a7a7946a71a259b5037c8c83de0dde6767c6..52230b3e2fa74034999b434587ef546ed63e3572 100644 --- a/apps/files_sharing/tests/js/publicAppSpec.js +++ b/apps/files_sharing/tests/js/publicAppSpec.js @@ -21,13 +21,16 @@ describe('OCA.Sharing.PublicApp tests', function() { var App = OCA.Sharing.PublicApp; - var hostStub, protocolStub, webrootStub; + var hostStub, protocolStub; + var originalWebroot; var $preview; beforeEach(function() { + originalWebroot = OC.webroot; + OC.webroot = '/owncloud'; protocolStub = sinon.stub(OC, 'getProtocol').returns('https'); hostStub = sinon.stub(OC, 'getHost').returns('example.com:9876'); - webrootStub = sinon.stub(OC, 'getRootPath').returns('/owncloud'); + $preview = $('<div id="preview"></div>'); $('#testArea').append($preview); $preview.append( @@ -38,9 +41,9 @@ describe('OCA.Sharing.PublicApp tests', function() { }); afterEach(function() { + OC.webroot = originalWebroot; protocolStub.restore(); hostStub.restore(); - webrootStub.restore(); }); describe('File list', function() { diff --git a/core/js/dist/main.js b/core/js/dist/main.js index c4dd8d61cba1a4b0cc007bd36e6adeb07b7b0cfb..e05334ce5853de08241bfdba9bb38cdf6db3ec5f 100644 Binary files a/core/js/dist/main.js and b/core/js/dist/main.js differ diff --git a/core/js/dist/main.js.map b/core/js/dist/main.js.map index 3ac581275356e171194fca3f4e4956c0b6cb0a87..82734ae0cb82659c526fa3abd9b39053f8e8a472 100644 Binary files a/core/js/dist/main.js.map and b/core/js/dist/main.js.map differ diff --git a/core/js/js.js b/core/js/js.js index a098418be1d9d1624e70e750c0a076f6ea35ec87..0959528b31ade3fff970b21220ae179a65b2768a 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1,18 +1,6 @@ -var oc_webroot; var oc_current_user = document.getElementsByTagName('head')[0].getAttribute('data-user'); var oc_requesttoken = document.getElementsByTagName('head')[0].getAttribute('data-requesttoken'); -if (typeof oc_webroot === "undefined") { - oc_webroot = location.pathname; - var pos = oc_webroot.indexOf('/index.php/'); - if (pos !== -1) { - oc_webroot = oc_webroot.substr(0, pos); - } - else { - oc_webroot = oc_webroot.substr(0, oc_webroot.lastIndexOf('/')); - } -} - /** @namespace OCP */ var OCP = Object.assign({}, window.OCP); @@ -29,17 +17,6 @@ Object.assign(window.OC, { PERMISSION_ALL:31, TAG_FAVORITE: '_$!<Favorite>!$_', /* jshint camelcase: false */ - /** - * Relative path to Nextcloud root. - * For example: "/nextcloud" - * - * @type string - * - * @deprecated since 8.2, use OC.getRootPath() instead - * @see OC#getRootPath - */ - webroot:oc_webroot, - /** * Capabilities * @@ -115,20 +92,6 @@ Object.assign(window.OC, { return window.location.port; }, - /** - * Returns the web root path where this Nextcloud instance - * is accessible, with a leading slash. - * For example "/nextcloud". - * - * @return {string} web root path - * - * @since 8.2 - */ - getRootPath: function() { - return OC.webroot; - }, - - /** * Returns the capabilities * diff --git a/core/js/tests/specHelper.js b/core/js/tests/specHelper.js index 970b278089d10f3bb82f8a3d7a90a0063bf44cf6..7dcc321f2965a8f2a24ef287e0c8f9467a2dee34 100644 --- a/core/js/tests/specHelper.js +++ b/core/js/tests/specHelper.js @@ -86,11 +86,11 @@ window.firstDay = 0; // setup dummy webroots /* jshint camelcase: false */ window.oc_debug = true; -// FIXME: oc_webroot is supposed to be only the path!!! -window.oc_webroot = location.href + '/'; +// FIXME: OC.webroot is supposed to be only the path!!! +OC.webroot = location.href + '/'; window.oc_appswebroots = { - "files": window.oc_webroot + '/apps/files/', - "files_sharing": window.oc_webroot + '/apps/files_sharing/' + "files": window.webroot + '/apps/files/', + "files_sharing": window.webroot + '/apps/files_sharing/' }; OC.config = { session_lifetime: 600 * 1000, diff --git a/core/js/tests/specs/sharedialoglinkshareview.js b/core/js/tests/specs/sharedialoglinkshareview.js index 9e6c67dca14a5a93598ec100395366384b8c7661..f2a64a50ff82dbaa82c570b2562c08d4c594c6dd 100644 --- a/core/js/tests/specs/sharedialoglinkshareview.js +++ b/core/js/tests/specs/sharedialoglinkshareview.js @@ -243,7 +243,7 @@ describe('OC.Share.ShareDialogLinkShareView', function () { configModel.isShareWithLinkAllowed.returns(true); // "Enable" Talk - window.oc_appswebroots['spreed'] = window.oc_webroot + '/apps/files/'; + window.oc_appswebroots['spreed'] = OC.getRootPath() + '/apps/files/'; shareModel.set({ linkShares: [{ diff --git a/core/src/OC/index.js b/core/src/OC/index.js index f852ef1d3092385c1c01bb86bb65959c6414730e..ab5552c8e57ea7f0eedfa2d208d8e232d3443999 100644 --- a/core/src/OC/index.js +++ b/core/src/OC/index.js @@ -30,6 +30,7 @@ import {isUserAdmin} from './admin' import L10N from './l10n' import { generateUrl, + getRootPath, filePath, linkTo, linkToOCS, @@ -44,6 +45,7 @@ import search from './search' import Util from './util' import {debug} from './debug' import {redirect, reload} from './navigation' +import webroot from './webroot' /** @namespace OC */ export default { @@ -65,6 +67,7 @@ export default { Util, debug, generateUrl, + getRootPath, filePath, redirect, reload, @@ -72,4 +75,14 @@ export default { linkToOCS, linkToRemote, linkToRemoteBase, + /** + * Relative path to Nextcloud root. + * For example: "/nextcloud" + * + * @type string + * + * @deprecated since 8.2, use OC.getRootPath() instead + * @see OC#getRootPath + */ + webroot, } diff --git a/core/src/OC/routing.js b/core/src/OC/routing.js index e2038e4d03ee82f4857fd42a695ac97effe62b23..0c57f01b9634ee92e50dc36a891c935e05bdf409 100644 --- a/core/src/OC/routing.js +++ b/core/src/OC/routing.js @@ -20,6 +20,7 @@ */ import _ from 'underscore' + import OC from './index' /** @@ -35,7 +36,7 @@ export const linkTo = (app, file) => filePath(app, '', file) * @param {string} service id * @return {string} the url */ -export const linkToRemoteBase = service => OC.getRootPath() + '/remote.php/' + service +export const linkToRemoteBase = service => getRootPath() + '/remote.php/' + service /** * @brief Creates an absolute url for remote use @@ -52,7 +53,7 @@ export const linkToRemote = service => window.location.protocol + '//' + window. */ export const linkToOCS = (service, version) => { version = (version !== 2) ? 1 : 2 - return window.location.protocol + '//' + window.location.host + OC.getRootPath() + '/ocs/v' + version + '.php/' + service + '/' + return window.location.protocol + '//' + window.location.host + getRootPath() + '/ocs/v' + version + '.php/' + service + '/' } /** @@ -90,10 +91,10 @@ export const generateUrl = (url, params, options) => { } if (oc_config.modRewriteWorking === true) { - return OC.getRootPath() + _build(url, params); + return getRootPath() + _build(url, params); } - return OC.getRootPath() + '/index.php' + _build(url, params); + return getRootPath() + '/index.php' + _build(url, params); } /** @@ -105,7 +106,7 @@ export const generateUrl = (url, params, options) => { */ export const filePath = (app, type, file) => { const isCore = OC.coreApps.indexOf(app) !== -1 - let link = OC.getRootPath() + let link = getRootPath() if (file.substring(file.length - 3) === 'php' && !isCore) { link += '/index.php/apps/' + app; if (file !== 'index.php') { @@ -144,3 +145,14 @@ export const filePath = (app, type, file) => { } return link } + +/** + * Returns the web root path where this Nextcloud instance + * is accessible, with a leading slash. + * For example "/nextcloud". + * + * @return {string} web root path + * + * @since 8.2 + */ +export const getRootPath = () => OC.webroot diff --git a/core/src/OC/webroot.js b/core/src/OC/webroot.js new file mode 100644 index 0000000000000000000000000000000000000000..cf9da346f92f0ddd9c37b7fc9aa3e2234738b992 --- /dev/null +++ b/core/src/OC/webroot.js @@ -0,0 +1,34 @@ +/* + * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +let webroot = window._oc_webroot + +if (typeof webroot === 'undefined') { + webroot = location.pathname + var pos = webroot.indexOf('/index.php/') + if (pos !== -1) { + webroot = webroot.substr(0, pos) + } else { + webroot = webroot.substr(0, webroot.lastIndexOf('/')) + } +} + +export default webroot diff --git a/core/src/globals.js b/core/src/globals.js index 01a7f3452ef01799f11b33a258f372ac9e8f170e..bbe650094035b8ff0fe853892ae72ecbc5281d5d 100644 --- a/core/src/globals.js +++ b/core/src/globals.js @@ -108,8 +108,9 @@ window['moment'] = moment window['OC'] = OC setDeprecatedProp('oc_config', OC.config, 'use OC.config instead') -setDeprecatedProp('oc_isadmin', OC.isUserAdmin(), 'use OC.isUserAdmin() instead') setDeprecatedProp('oc_debug', OC.debug, 'use OC.debug instead') +setDeprecatedProp('oc_isadmin', OC.isUserAdmin(), 'use OC.isUserAdmin() instead') +setDeprecatedProp('oc_webroot', OC.webroot, 'use OC.getRootPath() instead') setDeprecatedProp('OCDialogs', OC.dialogs, 'use OC.dialogs instead') window['OCP'] = OCP window['OCA'] = OCA diff --git a/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php index 7400650eade133379424f84e35eba7708ddb2c74..ee049533bbb77974bb5ea716227723f02786953b 100644 --- a/lib/private/Template/JSConfigHelper.php +++ b/lib/private/Template/JSConfigHelper.php @@ -170,7 +170,7 @@ class JSConfigHelper { "_oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', "backendAllowsPasswordConfirmation" => $userBackendAllowsPasswordConfirmation ? 'true' : 'false', "oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', - "oc_webroot" => "\"".\OC::$WEBROOT."\"", + "_oc_webroot" => "\"".\OC::$WEBROOT."\"", "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), 'nc_lastLogin' => $lastConfirmTimestamp,