Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions apps/files_sharing/tests/js/publicAppSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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() {
Expand Down
30 changes: 25 additions & 5 deletions core/js/dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/main.js.map

Large diffs are not rendered by default.

37 changes: 0 additions & 37 deletions core/js/js.js
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down
8 changes: 4 additions & 4 deletions core/js/tests/specHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/js/tests/specs/sharedialoglinkshareview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down
13 changes: 13 additions & 0 deletions core/src/OC/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {isUserAdmin} from './admin'
import L10N from './l10n'
import {
generateUrl,
getRootPath,
filePath,
linkTo,
linkToOCS,
Expand All @@ -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 {
Expand All @@ -65,11 +67,22 @@ export default {
Util,
debug,
generateUrl,
getRootPath,
filePath,
redirect,
reload,
linkTo,
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,
}
22 changes: 17 additions & 5 deletions core/src/OC/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

import _ from 'underscore'

import OC from './index'

/**
Expand All @@ -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
Expand All @@ -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 + '/'
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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') {
Expand Down Expand Up @@ -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 changes: 34 additions & 0 deletions core/src/OC/webroot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* @copyright 2019 Christoph Wurst <[email protected]>
*
* @author 2019 Christoph Wurst <[email protected]>
*
* @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
3 changes: 2 additions & 1 deletion core/src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Template/JSConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function getConfig() {
"_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,
Expand Down