diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-23 09:38:01 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-23 09:38:01 +0100 |
commit | 79bbda994bb8dd2231f68f57785237f79f86f6c7 (patch) | |
tree | 65585aed0d21cc679cdf7e2509efd6fa3d33b458 /apps/files_sharing | |
parent | 2f89eef334bd445a7e046d845d5d5d1b3e4b6b8c (diff) | |
parent | 418fefc93c3332c77ec617ef108138efb6a34544 (diff) | |
download | nextcloud-server-79bbda994bb8dd2231f68f57785237f79f86f6c7.tar.gz nextcloud-server-79bbda994bb8dd2231f68f57785237f79f86f6c7.zip |
Merge pull request #16902 from owncloud/jsocclient
Web UI uses Webdav instead of ajax/* calls
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/ajax/list.php | 96 | ||||
-rw-r--r-- | apps/files_sharing/js/app.js | 2 | ||||
-rw-r--r-- | apps/files_sharing/js/public.js | 16 | ||||
-rw-r--r-- | apps/files_sharing/js/share.js | 22 | ||||
-rw-r--r-- | apps/files_sharing/js/sharedfilelist.js | 4 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/publicAppSpec.js | 18 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/sharedfilelistSpec.js | 26 |
7 files changed, 62 insertions, 122 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/app.js b/apps/files_sharing/js/app.js index 3168e930829..af198208de2 100644 --- a/apps/files_sharing/js/app.js +++ b/apps/files_sharing/js/app.js @@ -142,7 +142,7 @@ OCA.Sharing.App = { // folder in the files app instead of opening it directly fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) { OCA.Files.App.setActiveView('files', {silent: true}); - OCA.Files.App.fileList.changeDirectory(context.$file.attr('data-path') + '/' + filename, true, true); + OCA.Files.App.fileList.changeDirectory(OC.joinPaths(context.$file.attr('data-path'), filename), true, true); }); fileActions.setDefault('dir', 'Open'); return fileActions; 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/js/share.js b/apps/files_sharing/js/share.js index 63225a0d8ec..3d105f283d8 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -50,7 +50,7 @@ if (fileData.shareOwner) { tr.attr('data-share-owner', fileData.shareOwner); // user should always be able to rename a mount point - if (fileData.isShareMountPoint) { + if (fileData.mountType === 'shared-root') { tr.attr('data-permissions', fileData.permissions | OC.PERMISSION_UPDATE); } } @@ -68,6 +68,26 @@ return fileInfo; }; + var NS_OC = 'http://owncloud.org/ns'; + + var oldGetWebdavProperties = fileList._getWebdavProperties; + fileList._getWebdavProperties = function() { + var props = oldGetWebdavProperties.apply(this, arguments); + props.push('{' + NS_OC + '}owner-display-name'); + return props; + }; + + fileList.filesClient.addFileInfoParser(function(response) { + var data = {}; + var props = response.propStat[0].properties; + var permissionsProp = props['{' + NS_OC + '}permissions']; + + if (permissionsProp && permissionsProp.indexOf('S') >= 0) { + data.shareOwner = props['{' + NS_OC + '}owner-display-name']; + } + return data; + }); + // use delegate to catch the case with multiple file lists fileList.$el.on('fileActionsReady', function(ev){ var fileList = ev.fileList; diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index 68bfd63ec89..a799d4a94c2 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -231,6 +231,7 @@ files = _.chain(files) // convert share data to file data .map(function(share) { + // TODO: use OC.Files.FileInfo var file = { id: share.file_source, icon: OC.MimeType.getIconUrl(share.mimetype), @@ -242,9 +243,6 @@ } else { file.type = 'file'; - if (share.isPreviewAvailable) { - file.isPreviewAvailable = true; - } } file.share = { id: share.id, diff --git a/apps/files_sharing/tests/js/publicAppSpec.js b/apps/files_sharing/tests/js/publicAppSpec.js index d496b78acfa..1ea5f7ed1bc 100644 --- a/apps/files_sharing/tests/js/publicAppSpec.js +++ b/apps/files_sharing/tests/js/publicAppSpec.js @@ -21,11 +21,13 @@ describe('OCA.Sharing.PublicApp tests', function() { var App = OCA.Sharing.PublicApp; + var hostStub, 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'); + webrootStub = sinon.stub(OC, 'getRootPath').returns('/owncloud'); $preview = $('<div id="preview"></div>'); $('#testArea').append($preview); $preview.append( @@ -35,6 +37,12 @@ describe('OCA.Sharing.PublicApp tests', function() { ); }); + afterEach(function() { + protocolStub.restore(); + hostStub.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 +86,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/owncloud/public.php/webdav/subdir'); + }); + describe('Download Url', function() { var fileList; diff --git a/apps/files_sharing/tests/js/sharedfilelistSpec.js b/apps/files_sharing/tests/js/sharedfilelistSpec.js index b4b6ac4954a..fdc9de49c17 100644 --- a/apps/files_sharing/tests/js/sharedfilelistSpec.js +++ b/apps/files_sharing/tests/js/sharedfilelistSpec.js @@ -166,8 +166,7 @@ describe('OCA.Sharing.FileList tests', function() { expect($tr.attr('data-share-id')).toEqual('7'); expect($tr.find('a.name').attr('href')).toEqual( OC.webroot + - '/index.php/apps/files/ajax/download.php' + - '?dir=%2Flocal%20path&files=local%20name.txt' + '/remote.php/webdav/local%20path/local%20name.txt' ); expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); @@ -185,8 +184,7 @@ describe('OCA.Sharing.FileList tests', function() { expect($tr.attr('data-share-id')).toEqual('8'); expect($tr.find('a.name').attr('href')).toEqual( OC.webroot + - '/index.php/apps/files/ajax/download.php' + - '?dir=%2F&files=b.txt' + '/remote.php/webdav/b.txt' ); expect($tr.find('.nametext').text().trim()).toEqual('b.txt'); }); @@ -338,8 +336,7 @@ describe('OCA.Sharing.FileList tests', function() { expect($tr.attr('data-share-id')).toEqual('7'); expect($tr.find('a.name').attr('href')).toEqual( OC.webroot + - '/index.php/apps/files/ajax/download.php' + - '?dir=%2Flocal%20path&files=local%20name.txt' + '/remote.php/webdav/local%20path/local%20name.txt' ); expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); }); @@ -429,9 +426,8 @@ describe('OCA.Sharing.FileList tests', function() { expect($tr.attr('data-share-owner')).not.toBeDefined(); expect($tr.attr('data-share-id')).toEqual('7'); expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + - '/index.php/apps/files/ajax/download.php' + - '?dir=%2Flocal%20path&files=local%20name.txt'); + OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt' + ); expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); }); @@ -498,9 +494,7 @@ describe('OCA.Sharing.FileList tests', function() { expect($tr.attr('data-share-owner')).not.toBeDefined(); expect($tr.attr('data-share-id')).toEqual('7,8,9'); expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + - '/index.php/apps/files/ajax/download.php' + - '?dir=%2Flocal%20path&files=local%20name.txt' + OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt' ); expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); }); @@ -592,9 +586,8 @@ describe('OCA.Sharing.FileList tests', function() { expect($tr.attr('data-share-owner')).not.toBeDefined(); expect($tr.attr('data-share-id')).toEqual('7'); expect($tr.find('a.name').attr('href')).toEqual( - OC.webroot + - '/index.php/apps/files/ajax/download.php' + - '?dir=%2Flocal%20path&files=local%20name.txt'); + OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt' + ); expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); }); @@ -634,8 +627,7 @@ describe('OCA.Sharing.FileList tests', function() { expect($tr.attr('data-share-id')).toEqual('7'); expect($tr.find('a.name').attr('href')).toEqual( OC.webroot + - '/index.php/apps/files/ajax/download.php' + - '?dir=%2Flocal%20path&files=local%20name.txt'); + '/remote.php/webdav/local%20path/local%20name.txt'); expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); }); |