Move oc_webroot, OC.webroot and OC.getRootPath() to the bundle

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2019-05-02 16:03:58 +02:00
parent e0c62352b7
commit 249a5dbdba
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
11 changed files with 104 additions and 58 deletions

View File

@ -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() {

30
core/js/dist/main.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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
*

View File

@ -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,

View File

@ -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: [{

View File

@ -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,
}

View File

@ -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

34
core/src/OC/webroot.js Normal file
View File

@ -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

View File

@ -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

View File

@ -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,