aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-07-13 17:41:20 +0200
committerLukas Reschke <lukas@owncloud.com>2015-11-22 16:05:50 +0100
commitf20232d4bd3e78c4ea980aa03849c3f9bcf5b893 (patch)
treec23d4511baaf4df2d1c397326334d40f8455243a /apps/files_sharing
parentfa2be0750c50de45a2fd101eb23fa858c0e0771b (diff)
downloadnextcloud-server-f20232d4bd3e78c4ea980aa03849c3f9bcf5b893.tar.gz
nextcloud-server-f20232d4bd3e78c4ea980aa03849c3f9bcf5b893.zip
Make public link share page work with Webdav and add operations
The public page now uses the public.php/webdav endpoint. Also enabled more file operations like rename, move, delete and create folder from the public page, which are now all possible thanks to the public.php/webdav endpoint.
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/ajax/list.php96
-rw-r--r--apps/files_sharing/js/public.js16
-rw-r--r--apps/files_sharing/tests/js/publicAppSpec.js20
3 files changed, 32 insertions, 100 deletions
diff --git a/apps/files_sharing/ajax/list.php b/apps/files_sharing/ajax/list.php
deleted file mode 100644
index c7f0bde5d4a..00000000000
--- a/apps/files_sharing/ajax/list.php
+++ /dev/null
@@ -1,96 +0,0 @@
-<?php
-/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <rullzer@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-OCP\JSON::checkAppEnabled('files_sharing');
-
-if(!isset($_GET['t'])){
- \OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST);
- \OCP\Util::writeLog('core-preview', 'No token parameter was passed', \OCP\Util::DEBUG);
- exit;
-}
-
-$token = $_GET['t'];
-
-$password = null;
-if (isset($_POST['password'])) {
- $password = $_POST['password'];
-}
-
-$relativePath = null;
-if (isset($_GET['dir'])) {
- $relativePath = $_GET['dir'];
-}
-
-$sortAttribute = isset( $_GET['sort'] ) ? $_GET['sort'] : 'name';
-$sortDirection = isset( $_GET['sortdirection'] ) ? ($_GET['sortdirection'] === 'desc') : false;
-
-$data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password);
-
-$linkItem = $data['linkItem'];
-// Load the files
-$dir = $data['realPath'];
-
-$dir = \OC\Files\Filesystem::normalizePath($dir);
-if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
- \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND);
- \OCP\JSON::error(array('success' => false));
- exit();
-}
-
-$data = array();
-
-// make filelist
-$files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
-
-$formattedFiles = array();
-foreach ($files as $file) {
- $entry = \OCA\Files\Helper::formatFileInfo($file);
- // for now
- unset($entry['directory']);
- // do not disclose share owner
- unset($entry['shareOwner']);
- // do not disclose if something is a remote shares
- unset($entry['mountType']);
- unset($entry['icon']);
- $entry['permissions'] = \OCP\Constants::PERMISSION_READ;
- $formattedFiles[] = $entry;
-}
-
-$data['directory'] = $relativePath;
-$data['files'] = $formattedFiles;
-$data['dirToken'] = $linkItem['token'];
-
-$permissions = $linkItem['permissions'];
-
-// if globally disabled
-if (\OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_public_upload', 'yes') === 'no') {
- // only allow reading
- $permissions = \OCP\Constants::PERMISSION_READ;
-}
-
-$data['permissions'] = $permissions;
-
-OCP\JSON::success(array('data' => $data));
diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js
index 246b639f652..82691129926 100644
--- a/apps/files_sharing/js/public.js
+++ b/apps/files_sharing/js/public.js
@@ -48,8 +48,20 @@ OCA.Sharing.PublicApp = {
this._initialized = true;
this.initialDir = $('#dir').val();
+ var token = $('#sharingToken').val();
+
// file list mode ?
if ($el.find('#filestable').length) {
+ var filesClient = new OC.Files.Client({
+ host: OC.getHost(),
+ port: OC.getPort(),
+ userName: token,
+ // note: password not be required, the endpoint
+ // will recognize previous validation from the session
+ root: OC.getRootPath() + '/public.php/webdav',
+ useHTTPS: OC.getProtocol() === 'https'
+ });
+
this.fileList = new OCA.Files.FileList(
$el,
{
@@ -58,7 +70,8 @@ OCA.Sharing.PublicApp = {
dragOptions: dragOptions,
folderDropOptions: folderDropOptions,
fileActions: fileActions,
- detailsViewEnabled: false
+ detailsViewEnabled: false,
+ filesClient: filesClient
}
);
this.files = OCA.Files.Files;
@@ -88,7 +101,6 @@ OCA.Sharing.PublicApp = {
// dynamically load image previews
- var token = $('#sharingToken').val();
var bottomMargin = 350;
var previewWidth = Math.ceil($(window).width() * window.devicePixelRatio);
var previewHeight = Math.ceil(($(window).height() - bottomMargin) * window.devicePixelRatio);
diff --git a/apps/files_sharing/tests/js/publicAppSpec.js b/apps/files_sharing/tests/js/publicAppSpec.js
index d496b78acfa..8a644232e6c 100644
--- a/apps/files_sharing/tests/js/publicAppSpec.js
+++ b/apps/files_sharing/tests/js/publicAppSpec.js
@@ -21,11 +21,14 @@
describe('OCA.Sharing.PublicApp tests', function() {
var App = OCA.Sharing.PublicApp;
+ var hostStub, portStub, protocolStub, webrootStub;
var $preview;
- var fileListIn;
- var fileListOut;
beforeEach(function() {
+ protocolStub = sinon.stub(OC, 'getProtocol').returns('https');
+ hostStub = sinon.stub(OC, 'getHost').returns('example.com');
+ portStub = sinon.stub(OC, 'getPort').returns(8080);
+ webrootStub = sinon.stub(OC, 'getRootPath').returns('/owncloud');
$preview = $('<div id="preview"></div>');
$('#testArea').append($preview);
$preview.append(
@@ -35,6 +38,13 @@ describe('OCA.Sharing.PublicApp tests', function() {
);
});
+ afterEach(function() {
+ protocolStub.restore();
+ hostStub.restore();
+ portStub.restore();
+ webrootStub.restore();
+ });
+
describe('File list', function() {
// TODO: this should be moved to a separate file once the PublicFileList is extracted from public.js
beforeEach(function() {
@@ -78,6 +88,12 @@ describe('OCA.Sharing.PublicApp tests', function() {
App._initialized = false;
});
+ it('Uses public webdav endpoint', function() {
+ expect(fakeServer.requests.length).toEqual(1);
+ expect(fakeServer.requests[0].method).toEqual('PROPFIND');
+ expect(fakeServer.requests[0].url).toEqual('https://sh4tok@example.com:8080/owncloud/public.php/webdav/subdir');
+ });
+
describe('Download Url', function() {
var fileList;