diff options
43 files changed, 971 insertions, 141 deletions
diff --git a/.gitignore b/.gitignore index 93bacf9b07e..9d8c40b34a1 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ /apps/files_external/3rdparty/irodsphp/prods/test /apps/files_external/3rdparty/irodsphp/prods/tutorials /apps/files_external/3rdparty/irodsphp/prods/test* +/apps/files_external/tests/config.*.php diff --git a/apps/files/css/mobile.css b/apps/files/css/mobile.css index 780b7ac8443..4881f7c70e4 100644 --- a/apps/files/css/mobile.css +++ b/apps/files/css/mobile.css @@ -24,7 +24,7 @@ table td { } /* and accordingly fix left margin of file list summary on mobile */ .summary .info { - margin-left: 55px; + margin-left: 105px; } /* remove shift for multiselect bar to account for missing navigation */ diff --git a/apps/files/index.php b/apps/files/index.php index 02076226c1a..64b49c3bf1f 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -93,7 +93,7 @@ function sortNavigationItems($item1, $item2) { 'id' => 'favorites', 'appname' => 'files', 'script' => 'simplelist.php', - 'order' => 50, + 'order' => 5, 'name' => $l->t('Favorites') ) ); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index d8b8916752d..09cb3d3287d 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1308,9 +1308,9 @@ } _.each(fileNames, function(fileName) { var $tr = self.findFileEl(fileName); - var $td = $tr.children('td.filename'); - var oldBackgroundImage = $td.css('background-image'); - $td.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')'); + var $thumbEl = $tr.find('.thumbnail'); + var oldBackgroundImage = $thumbEl.css('background-image'); + $thumbEl.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')'); // TODO: improve performance by sending all file names in a single call $.post( OC.filePath('files', 'ajax', 'move.php'), @@ -1352,7 +1352,7 @@ } else { OC.dialogs.alert(t('files', 'Error moving file'), t('files', 'Error')); } - $td.css('background-image', oldBackgroundImage); + $thumbEl.css('background-image', oldBackgroundImage); } ); }); @@ -1413,13 +1413,14 @@ try { var newName = input.val(); + var $thumbEl = tr.find('.thumbnail'); input.tipsy('hide'); form.remove(); if (newName !== oldname) { checkInput(); // mark as loading (temp element) - td.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')'); + $thumbEl.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')'); tr.attr('data-file', newName); var basename = newName; if (newName.indexOf('.') > 0 && tr.data('type') !== 'dir') { @@ -1842,7 +1843,7 @@ var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads); if (currentUploads === 1) { var img = OC.imagePath('core', 'loading.gif'); - data.context.find('td.filename').attr('style','background-image:url('+img+')'); + data.context.find('.thumbnail').css('background-image', 'url(' + img + ')'); uploadText.text(translatedText); uploadText.show(); } else { @@ -1881,7 +1882,7 @@ var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads); if (currentUploads === 0) { var img = OC.imagePath('core', 'filetypes/folder'); - data.context.find('td.filename').attr('style','background-image:url('+img+')'); + data.context.find('.thumbnail').css('background-image', 'url(' + img + ')'); uploadText.text(translatedText); uploadText.hide(); } else { @@ -1966,7 +1967,7 @@ //cleanup uploading to a dir var uploadText = $('tr .uploadtext'); var img = OC.imagePath('core', 'filetypes/folder'); - uploadText.parents('td.filename').attr('style','background-image:url('+img+')'); + uploadText.parents('td.filename').find('.thumbnail').css('background-image', 'url(' + img + ')'); uploadText.fadeOut(); uploadText.attr('currentUploads', 0); } @@ -1980,7 +1981,7 @@ //cleanup uploading to a dir var uploadText = $('tr .uploadtext'); var img = OC.imagePath('core', 'filetypes/folder'); - uploadText.parents('td.filename').attr('style','background-image:url('+img+')'); + uploadText.parents('td.filename').find('.thumbnail').css('background-image', 'url(' + img + ')'); uploadText.fadeOut(); uploadText.attr('currentUploads', 0); } diff --git a/apps/files/js/files.js b/apps/files/js/files.js index b11ef03eab2..314b8bf39c6 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -369,19 +369,22 @@ var createDragShadow = function(event) { var dir = FileList.getCurrentDirectory(); $(selectedFiles).each(function(i,elem) { + // TODO: refactor this with the table row creation code var newtr = $('<tr/>') .attr('data-dir', dir) .attr('data-file', elem.name) .attr('data-origin', elem.origin); - newtr.append($('<td/>').addClass('filename').text(elem.name)); - newtr.append($('<td/>').addClass('size').text(OC.Util.humanFileSize(elem.size))); + newtr.append($('<td class="filename" />').text(elem.name).css('background-size', 32)); + newtr.append($('<td class="size" />').text(OC.Util.humanFileSize(elem.size))); tbody.append(newtr); if (elem.type === 'dir') { - newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')'); + newtr.find('td.filename') + .css('background-image', 'url(' + OC.imagePath('core', 'filetypes/folder.png') + ')'); } else { var path = dir + '/' + elem.name; OCA.Files.App.files.lazyLoadPreview(path, elem.mime, function(previewpath) { - newtr.find('td.filename').attr('style','background-image:url('+previewpath+')'); + newtr.find('td.filename') + .css('background-image', 'url(' + previewpath + ')'); }, null, null, elem.etag); } }); diff --git a/apps/files/templates/list.php b/apps/files/templates/list.php index a90ababf2bb..8ecec066a51 100644 --- a/apps/files/templates/list.php +++ b/apps/files/templates/list.php @@ -50,7 +50,11 @@ <input type="hidden" name="permissions" value="" id="permissions"> </div> -<div id="emptycontent" class="hidden"><?php p($l->t('Nothing in here. Upload something!'))?></div> +<div id="emptycontent" class="hidden"> + <div class="icon-folder"></div> + <h2><?php p($l->t('No files yet')); ?></h2> + <p><?php p($l->t('Upload some content or sync with your devices!')); ?></p> +</div> <table id="filestable" data-allow-public-upload="<?php p($_['publicUploadEnabled'])?>" data-preview-x="36" data-preview-y="36"> <thead> diff --git a/apps/files/templates/simplelist.php b/apps/files/templates/simplelist.php index c00febce653..d806a220ac0 100644 --- a/apps/files/templates/simplelist.php +++ b/apps/files/templates/simplelist.php @@ -3,7 +3,11 @@ </div> <div id='notification'></div> -<div id="emptycontent" class="hidden"></div> +<div id="emptycontent" class="hidden"> + <div class="icon-starred"></div> + <h2><?php p($l->t('No favorites')); ?></h2> + <p><?php p($l->t('Files and folders you mark as favorite will show up here')); ?></p> +</div> <input type="hidden" name="dir" value="" id="dir"> diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index 3ca41fbae7d..6c83f214c39 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -661,6 +661,23 @@ describe('OCA.Files.FileList tests', function() { expect(fileList.$fileList.find('input.filename').length).toEqual(0); expect(fileList.$fileList.find('form').length).toEqual(0); }); + it('Restores thumbnail when rename was cancelled', function() { + doRename(); + + expect(OC.TestUtil.getImageUrl(fileList.findFileEl('Tu_after_three.txt').find('.thumbnail'))) + .toEqual(OC.imagePath('core', 'loading.gif')); + + fakeServer.requests[0].respond(200, {'Content-Type': 'application/json'}, JSON.stringify({ + status: 'error', + data: { + message: 'Something went wrong' + } + })); + + expect(fileList.findFileEl('One.txt').length).toEqual(1); + expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail'))) + .toEqual(OC.imagePath('core', 'filetypes/file.svg')); + }); }); describe('Moving files', function() { beforeEach(function() { @@ -755,6 +772,31 @@ describe('OCA.Files.FileList tests', function() { expect(notificationStub.calledOnce).toEqual(true); expect(notificationStub.getCall(0).args[0]).toEqual('Error while moving file'); }); + it('Restores thumbnail if a file could not be moved', function() { + var request; + fileList.move('One.txt', '/somedir'); + + expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail'))) + .toEqual(OC.imagePath('core', 'loading.gif')); + + expect(fakeServer.requests.length).toEqual(1); + request = fakeServer.requests[0]; + + fakeServer.requests[0].respond(200, {'Content-Type': 'application/json'}, JSON.stringify({ + status: 'error', + data: { + message: 'Error while moving file', + } + })); + + expect(fileList.findFileEl('One.txt').length).toEqual(1); + + expect(notificationStub.calledOnce).toEqual(true); + expect(notificationStub.getCall(0).args[0]).toEqual('Error while moving file'); + + expect(OC.TestUtil.getImageUrl(fileList.findFileEl('One.txt').find('.thumbnail'))) + .toEqual(OC.imagePath('core', 'filetypes/file.svg')); + }); }); describe('List rendering', function() { it('renders a list of files using add()', function() { diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 5742b8f47e2..f09b29a522b 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -1,25 +1,25 @@ <?php /** -* ownCloud -* -* @author Michael Gapczynski -* @copyright 2012 Michael Gapczynski mtgap@owncloud.com -* @copyright 2014 Vincent Petry <pvince81@owncloud.com> -* @copyright 2014 Robin McCorkell <rmccorkell@karoshi.org.uk> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library 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 library. If not, see <http://www.gnu.org/licenses/>. -*/ + * ownCloud + * + * @author Michael Gapczynski + * @copyright 2012 Michael Gapczynski mtgap@owncloud.com + * @copyright 2014 Vincent Petry <pvince81@owncloud.com> + * @copyright 2014 Robin McCorkell <rmccorkell@karoshi.org.uk> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library 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 library. If not, see <http://www.gnu.org/licenses/>. + */ /** * Class to configure mount.json globally and for users @@ -64,16 +64,17 @@ class OC_Mount_Config { } /** - * Get details on each of the external storage backends, used for the mount config UI - * If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded - * If the configuration parameter should be secret, add a '*' to the beginning of the value - * If the configuration parameter is a boolean, add a '!' to the beginning of the value - * If the configuration parameter is optional, add a '&' to the beginning of the value - * If the configuration parameter is hidden, add a '#' to the beginning of the value - * @return array - */ + * Get details on each of the external storage backends, used for the mount config UI + * If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded + * If the configuration parameter should be secret, add a '*' to the beginning of the value + * If the configuration parameter is a boolean, add a '!' to the beginning of the value + * If the configuration parameter is optional, add a '&' to the beginning of the value + * If the configuration parameter is hidden, add a '#' to the beginning of the value + * + * @return array + */ public static function getBackends() { - $sortFunc = function($a, $b) { + $sortFunc = function ($a, $b) { return strcasecmp($a['backend'], $b['backend']); }; @@ -100,10 +101,13 @@ class OC_Mount_Config { /** * Hook that mounts the given user's visible mount points + * * @param array $data */ public static function initMountPointsHook($data) { + self::addStorageIdToConfig(null); if ($data['user']) { + self::addStorageIdToConfig($data['user']); $user = \OC::$server->getUserManager()->get($data['user']); if (!$user) { \OC_Log::write( @@ -161,8 +165,9 @@ class OC_Mount_Config { } // Override if priority greater - if ( (!isset($mountPoints[$mountPoint])) - || ($options['priority'] >= $mountPoints[$mountPoint]['priority']) ) { + if ((!isset($mountPoints[$mountPoint])) + || ($options['priority'] >= $mountPoints[$mountPoint]['priority']) + ) { $options['priority_type'] = self::MOUNT_TYPE_GLOBAL; $options['backend'] = $backends[$options['class']]['backend']; $mountPoints[$mountPoint] = $options; @@ -184,8 +189,9 @@ class OC_Mount_Config { } // Override if priority greater - if ( (!isset($mountPoints[$mountPoint])) - || ($options['priority'] >= $mountPoints[$mountPoint]['priority']) ) { + if ((!isset($mountPoints[$mountPoint])) + || ($options['priority'] >= $mountPoints[$mountPoint]['priority']) + ) { $options['priority_type'] = self::MOUNT_TYPE_GLOBAL; $options['backend'] = $backends[$options['class']]['backend']; $mountPoints[$mountPoint] = $options; @@ -208,9 +214,10 @@ class OC_Mount_Config { } // Override if priority greater or if priority type different - if ( (!isset($mountPoints[$mountPoint])) + if ((!isset($mountPoints[$mountPoint])) || ($options['priority'] >= $mountPoints[$mountPoint]['priority']) - || ($mountPoints[$mountPoint]['priority_type'] !== self::MOUNT_TYPE_GROUP) ) { + || ($mountPoints[$mountPoint]['priority_type'] !== self::MOUNT_TYPE_GROUP) + ) { $options['priority_type'] = self::MOUNT_TYPE_GROUP; $options['backend'] = $backends[$options['class']]['backend']; $mountPoints[$mountPoint] = $options; @@ -235,9 +242,10 @@ class OC_Mount_Config { } // Override if priority greater or if priority type different - if ( (!isset($mountPoints[$mountPoint])) + if ((!isset($mountPoints[$mountPoint])) || ($options['priority'] >= $mountPoints[$mountPoint]['priority']) - || ($mountPoints[$mountPoint]['priority_type'] !== self::MOUNT_TYPE_USER) ) { + || ($mountPoints[$mountPoint]['priority_type'] !== self::MOUNT_TYPE_USER) + ) { $options['priority_type'] = self::MOUNT_TYPE_USER; $options['backend'] = $backends[$options['class']]['backend']; $mountPoints[$mountPoint] = $options; @@ -281,22 +289,23 @@ class OC_Mount_Config { /** - * Get details on each of the external storage backends, used for the mount config UI - * Some backends are not available as a personal backend, f.e. Local and such that have - * been disabled by the admin. - * - * If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded - * If the configuration parameter should be secret, add a '*' to the beginning of the value - * If the configuration parameter is a boolean, add a '!' to the beginning of the value - * If the configuration parameter is optional, add a '&' to the beginning of the value - * If the configuration parameter is hidden, add a '#' to the beginning of the value - * @return array - */ + * Get details on each of the external storage backends, used for the mount config UI + * Some backends are not available as a personal backend, f.e. Local and such that have + * been disabled by the admin. + * + * If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded + * If the configuration parameter should be secret, add a '*' to the beginning of the value + * If the configuration parameter is a boolean, add a '!' to the beginning of the value + * If the configuration parameter is optional, add a '&' to the beginning of the value + * If the configuration parameter is hidden, add a '#' to the beginning of the value + * + * @return array + */ public static function getPersonalBackends() { // Check whether the user has permissions to add personal storage backends // return an empty array if this is not the case - if(OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') { + if (OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') { return array(); } @@ -316,10 +325,11 @@ class OC_Mount_Config { } /** - * Get the system mount points - * The returned array is not in the same format as getUserMountPoints() - * @return array - */ + * Get the system mount points + * The returned array is not in the same format as getUserMountPoints() + * + * @return array + */ public static function getSystemMountPoints() { $mountPoints = self::readData(); $backends = self::getBackends(); @@ -329,7 +339,7 @@ class OC_Mount_Config { foreach ($mounts as $mountPoint => $mount) { // Update old classes to new namespace if (strpos($mount['class'], 'OC_Filestorage_') !== false) { - $mount['class'] = '\OC\Files\Storage\\'.substr($mount['class'], 15); + $mount['class'] = '\OC\Files\Storage\\' . substr($mount['class'], 15); } $mount['options'] = self::decryptPasswords($mount['options']); if (!isset($mount['priority'])) { @@ -364,7 +374,7 @@ class OC_Mount_Config { foreach ($mounts as $mountPoint => $mount) { // Update old classes to new namespace if (strpos($mount['class'], 'OC_Filestorage_') !== false) { - $mount['class'] = '\OC\Files\Storage\\'.substr($mount['class'], 15); + $mount['class'] = '\OC\Files\Storage\\' . substr($mount['class'], 15); } $mount['options'] = self::decryptPasswords($mount['options']); if (!isset($mount['priority'])) { @@ -397,10 +407,11 @@ class OC_Mount_Config { } /** - * Get the personal mount points of the current user - * The returned array is not in the same format as getUserMountPoints() - * @return array - */ + * Get the personal mount points of the current user + * The returned array is not in the same format as getUserMountPoints() + * + * @return array + */ public static function getPersonalMountPoints() { $mountPoints = self::readData(OCP\User::getUser()); $backEnds = self::getBackends(); @@ -410,7 +421,7 @@ class OC_Mount_Config { foreach ($mountPoints[self::MOUNT_TYPE_USER][$uid] as $mountPoint => $mount) { // Update old classes to new namespace if (strpos($mount['class'], 'OC_Filestorage_') !== false) { - $mount['class'] = '\OC\Files\Storage\\'.substr($mount['class'], 15); + $mount['class'] = '\OC\Files\Storage\\' . substr($mount['class'], 15); } $mount['options'] = self::decryptPasswords($mount['options']); $personal[] = array( @@ -428,6 +439,7 @@ class OC_Mount_Config { /** * Test connecting using the given backend configuration + * * @param string $class backend class name * @param array $options backend configuration options * @return bool true if the connection succeeded, false otherwise @@ -452,16 +464,17 @@ class OC_Mount_Config { } /** - * Add a mount point to the filesystem - * @param string $mountPoint Mount point - * @param string $class Backend class - * @param array $classOptions Backend parameters for the class - * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER - * @param string $applicable User or group to apply mount to - * @param bool $isPersonal Personal or system mount point i.e. is this being called from the personal or admin page - * @param int|null $priority Mount point priority, null for default - * @return boolean - */ + * Add a mount point to the filesystem + * + * @param string $mountPoint Mount point + * @param string $class Backend class + * @param array $classOptions Backend parameters for the class + * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER + * @param string $applicable User or group to apply mount to + * @param bool $isPersonal Personal or system mount point i.e. is this being called from the personal or admin page + * @param int|null $priority Mount point priority, null for default + * @return boolean + */ public static function addMountPoint($mountPoint, $class, $classOptions, @@ -488,22 +501,22 @@ class OC_Mount_Config { if ($applicable != OCP\User::getUser() || !isset($allowed_backends[$class])) { return false; } - $mountPoint = '/'.$applicable.'/files/'.ltrim($mountPoint, '/'); + $mountPoint = '/' . $applicable . '/files/' . ltrim($mountPoint, '/'); } else { - $mountPoint = '/$user/files/'.ltrim($mountPoint, '/'); + $mountPoint = '/$user/files/' . ltrim($mountPoint, '/'); } $mount = array($applicable => array( $mountPoint => array( 'class' => $class, 'options' => self::encryptPasswords($classOptions)) - ) + ) ); - if (! $isPersonal && !is_null($priority)) { + if (!$isPersonal && !is_null($priority)) { $mount[$applicable][$mountPoint]['priority'] = $priority; } - $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL); + $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : null); // who else loves multi-dimensional array ? $isNew = !isset($mountPoints[$mountType]) || !isset($mountPoints[$mountType][$applicable]) || @@ -521,7 +534,7 @@ class OC_Mount_Config { } } - self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints); + self::writeData($isPersonal ? OCP\User::getUser() : null, $mountPoints); $result = self::getBackendStatus($class, $classOptions, $isPersonal); if ($result && $isNew) { @@ -539,13 +552,13 @@ class OC_Mount_Config { } /** - * - * @param string $mountPoint Mount point - * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER - * @param string $applicable User or group to remove mount from - * @param bool $isPersonal Personal or system mount point - * @return bool - */ + * + * @param string $mountPoint Mount point + * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER + * @param string $applicable User or group to remove mount from + * @param bool $isPersonal Personal or system mount point + * @return bool + */ public static function removeMountPoint($mountPoint, $mountType, $applicable, $isPersonal = false) { // Verify that the mount point applies for the current user $relMountPoints = $mountPoint; @@ -553,12 +566,12 @@ class OC_Mount_Config { if ($applicable != OCP\User::getUser()) { return false; } - $mountPoint = '/'.$applicable.'/files/'.ltrim($mountPoint, '/'); + $mountPoint = '/' . $applicable . '/files/' . ltrim($mountPoint, '/'); } else { - $mountPoint = '/$user/files/'.ltrim($mountPoint, '/'); + $mountPoint = '/$user/files/' . ltrim($mountPoint, '/'); } $mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint); - $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL); + $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : null); // Remove mount point unset($mountPoints[$mountType][$applicable][$mountPoint]); // Unset parent arrays if empty @@ -568,7 +581,7 @@ class OC_Mount_Config { unset($mountPoints[$mountType]); } } - self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints); + self::writeData($isPersonal ? OCP\User::getUser() : null, $mountPoints); \OC_Hook::emit( \OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_delete_mount, @@ -604,17 +617,18 @@ class OC_Mount_Config { } /** - * Read the mount points in the config file into an array - * @param string|null $user If not null, personal for $user, otherwise system - * @return array - */ - private static function readData($user = NULL) { + * Read the mount points in the config file into an array + * + * @param string|null $user If not null, personal for $user, otherwise system + * @return array + */ + private static function readData($user = null) { $parser = new \OC\ArrayParser(); if (isset($user)) { - $phpFile = OC_User::getHome($user).'/mount.php'; - $jsonFile = OC_User::getHome($user).'/mount.json'; + $phpFile = OC_User::getHome($user) . '/mount.php'; + $jsonFile = OC_User::getHome($user) . '/mount.json'; } else { - $phpFile = OC::$SERVERROOT.'/config/mount.php'; + $phpFile = OC::$SERVERROOT . '/config/mount.php'; $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/'); $jsonFile = \OC_Config::getValue('mount_file', $datadir . '/mount.json'); } @@ -633,17 +647,27 @@ class OC_Mount_Config { } /** - * Write the mount points to the config file - * @param string|null $user If not null, personal for $user, otherwise system - * @param array $data Mount points - */ + * Write the mount points to the config file + * + * @param string|null $user If not null, personal for $user, otherwise system + * @param array $data Mount points + */ private static function writeData($user, $data) { if (isset($user)) { - $file = OC_User::getHome($user).'/mount.json'; + $file = OC_User::getHome($user) . '/mount.json'; } else { $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/'); $file = \OC_Config::getValue('mount_file', $datadir . '/mount.json'); } + + foreach ($data as &$applicables) { + foreach ($applicables as &$mountPoints) { + foreach ($mountPoints as &$options) { + self::addStorageId($options); + } + } + } + $content = json_encode($data, JSON_PRETTY_PRINT); @file_put_contents($file, $content); @chmod($file, 0640); @@ -678,7 +702,7 @@ class OC_Mount_Config { return ''; } - private static function addDependency(&$dependencies, $module, $backend, $message=null) { + private static function addDependency(&$dependencies, $module, $backend, $message = null) { if (!isset($dependencies[$module])) { $dependencies[$module] = array(); } @@ -708,7 +732,7 @@ class OC_Mount_Config { $backends = ''; for ($i = 0; $i < $dependencyGroupCount; $i++) { if ($i > 0 && $i === $dependencyGroupCount - 1) { - $backends .= ' '.$l->t('and').' '; + $backends .= ' ' . $l->t('and') . ' '; } elseif ($i > 0) { $backends .= ', '; } @@ -722,6 +746,7 @@ class OC_Mount_Config { /** * Returns a dependency missing message + * * @param OC_L10N $l * @param string $module * @param string $backend @@ -740,6 +765,7 @@ class OC_Mount_Config { /** * Encrypt passwords in the given config options + * * @param array $options mount options * @return array updated options */ @@ -755,6 +781,7 @@ class OC_Mount_Config { /** * Decrypt passwords in the given config options + * * @param array $options mount options * @return array updated options */ @@ -769,6 +796,7 @@ class OC_Mount_Config { /** * Encrypt a single password + * * @param string $password plain text password * @return string encrypted password */ @@ -781,6 +809,7 @@ class OC_Mount_Config { /** * Decrypts a single password + * * @param string $encryptedPassword encrypted password * @return string plain text password */ @@ -795,6 +824,7 @@ class OC_Mount_Config { /** * Merges mount points + * * @param array $data Existing mount points * @param array $mountPoint New mount point * @param string $mountType @@ -808,7 +838,8 @@ class OC_Mount_Config { // Merge priorities if (isset($data[$mountType][$applicable][$mountPath]) && isset($data[$mountType][$applicable][$mountPath]['priority']) - && !isset($mountPoint[$applicable][$mountPath]['priority'])) { + && !isset($mountPoint[$applicable][$mountPath]['priority']) + ) { $mountPoint[$applicable][$mountPath]['priority'] = $data[$mountType][$applicable][$mountPath]['priority']; } @@ -850,4 +881,32 @@ class OC_Mount_Config { ); return hash('md5', $data); } + + private static function addStorageIdToConfig($user) { + $config = self::readData($user); + + $needUpdate = false; + foreach ($config as &$applicables) { + foreach ($applicables as &$mountPoints) { + foreach ($mountPoints as &$options) { + $needUpdate |= !isset($options['storage_id']); + } + } + } + + if ($needUpdate) { + self::writeData($user, $config); + } + } + + private static function addStorageId(&$options) { + if (isset($options['storage_id'])) { + return false; + } + $class = $options['class']; + /** @var \OC\Files\Storage\Storage $storage */ + $storage = new $class($options['options']); + $options['storage_id'] = $storage->getCache()->getNumericStorageId(); + return true; + } } diff --git a/apps/files_external/templates/list.php b/apps/files_external/templates/list.php index 4e06bc7024c..09923fe3879 100644 --- a/apps/files_external/templates/list.php +++ b/apps/files_external/templates/list.php @@ -4,7 +4,11 @@ </div> <div id='notification'></div> -<div id="emptycontent" class="hidden"><?php p($l->t( 'You don\'t have any external storages' )); ?></div> +<div id="emptycontent" class="hidden"> + <div class="icon-external"></div> + <h2><?php p($l->t('No external storages')); ?></h2> + <p><?php p($l->t('You can configure external storages in the personal settings')); ?></p> +</div> <input type="hidden" name="dir" value="" id="dir"> diff --git a/apps/files_external/tests/amazons3.php b/apps/files_external/tests/backends/amazons3.php index fbb8744bd8d..fbb8744bd8d 100644 --- a/apps/files_external/tests/amazons3.php +++ b/apps/files_external/tests/backends/amazons3.php diff --git a/apps/files_external/tests/dropbox.php b/apps/files_external/tests/backends/dropbox.php index 3f25d5a31e8..3f25d5a31e8 100644 --- a/apps/files_external/tests/dropbox.php +++ b/apps/files_external/tests/backends/dropbox.php diff --git a/apps/files_external/tests/ftp.php b/apps/files_external/tests/backends/ftp.php index 842b7f43fa8..842b7f43fa8 100644 --- a/apps/files_external/tests/ftp.php +++ b/apps/files_external/tests/backends/ftp.php diff --git a/apps/files_external/tests/google.php b/apps/files_external/tests/backends/google.php index 79023fac9e1..79023fac9e1 100644 --- a/apps/files_external/tests/google.php +++ b/apps/files_external/tests/backends/google.php diff --git a/apps/files_external/tests/owncloud.php b/apps/files_external/tests/backends/owncloud.php index ab9101cfe5f..ab9101cfe5f 100644 --- a/apps/files_external/tests/owncloud.php +++ b/apps/files_external/tests/backends/owncloud.php diff --git a/apps/files_external/tests/sftp.php b/apps/files_external/tests/backends/sftp.php index 703b37d93f1..703b37d93f1 100644 --- a/apps/files_external/tests/sftp.php +++ b/apps/files_external/tests/backends/sftp.php diff --git a/apps/files_external/tests/smb.php b/apps/files_external/tests/backends/smb.php index 9e5ab2b331f..9e5ab2b331f 100644 --- a/apps/files_external/tests/smb.php +++ b/apps/files_external/tests/backends/smb.php diff --git a/apps/files_external/tests/swift.php b/apps/files_external/tests/backends/swift.php index d2c884a8b4c..d2c884a8b4c 100644 --- a/apps/files_external/tests/swift.php +++ b/apps/files_external/tests/backends/swift.php diff --git a/apps/files_external/tests/webdav.php b/apps/files_external/tests/backends/webdav.php index 5f53568b91a..c390612810d 100644 --- a/apps/files_external/tests/webdav.php +++ b/apps/files_external/tests/backends/webdav.php @@ -16,15 +16,15 @@ class DAV extends Storage { parent::setUp(); $id = $this->getUniqueID(); - $this->config = include('files_external/tests/config.php'); - if ( ! is_array($this->config) or ! isset($this->config['webdav']) or ! $this->config['webdav']['run']) { + $config = include('files_external/tests/config.webdav.php'); + if ( ! is_array($config) or !$config['run']) { $this->markTestSkipped('WebDAV backend not configured'); } - if (isset($this->config['webdav']['wait'])) { - $this->waitDelay = $this->config['webdav']['wait']; + if (isset($config['wait'])) { + $this->waitDelay = $config['wait']; } - $this->config['webdav']['root'] .= '/' . $id; //make sure we have an new empty folder to work in - $this->instance = new \OC\Files\Storage\DAV($this->config['webdav']); + $config['root'] .= '/' . $id; //make sure we have an new empty folder to work in + $this->instance = new \OC\Files\Storage\DAV($config); $this->instance->mkdir('/'); } diff --git a/apps/files_external/tests/env/start-webdav-ownCloud.sh b/apps/files_external/tests/env/start-webdav-ownCloud.sh new file mode 100755 index 00000000000..c7267cff341 --- /dev/null +++ b/apps/files_external/tests/env/start-webdav-ownCloud.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# +# ownCloud +# +# This script start a docker container to test the files_external tests +# against. It will also change the files_external config to use the docker +# container as testing environment. This is reverted in the stop step. +# +# If the environment variable RUN_DOCKER_MYSQL is set the ownCloud will +# be set up using MySQL instead of SQLite. +# +# Set environment variable DEBUG to print config file +# +# @author Morris Jobke +# @copyright 2014 Morris Jobke <hey@morrisjobke.de> +# + +if ! command -v docker >/dev/null 2>&1; then + echo "No docker executable found - skipped docker setup" + exit 0; +fi + +echo "Docker executable found - setup docker" + +echo "Fetch recent morrisjobke/owncloud docker image" +docker pull morrisjobke/owncloud + +# retrieve current folder to place the config in the parent folder +thisFolder=`echo $0 | replace "env/start-webdav-ownCloud.sh" ""` + +if [ -n "$RUN_DOCKER_MYSQL" ]; then + echo "Fetch recent mysql docker image" + docker pull mysql + + echo "Setup MySQL ..." + # user/password will be read by ENV variables in owncloud container (they are generated by docker) + databaseContainer=`docker run -e MYSQL_ROOT_PASSWORD=mysupersecretpassword -d mysql` + containerName=`docker inspect $databaseContainer | grep Name | grep _ | cut -d \" -f 4 | cut -d / -f 2` + + parameter="--link $containerName:db" +fi + +container=`docker run -P $parameter -d -e ADMINLOGIN=test -e ADMINPWD=test morrisjobke/owncloud` + +# TODO find a way to determine the successful initialization inside the docker container +echo "Waiting 30 seconds for ownCloud initialization ... " +sleep 30 + +# get mapped port on host for internal port 80 - output is IP:PORT - we need to extract the port with 'cut' +port=`docker port $container 80 | cut -f 2 -d :` + + +cat > $thisFolder/config.webdav.php <<DELIM +<?php + +return array( + 'run'=>true, + 'host'=>'localhost:$port/owncloud/remote.php/webdav/', + 'user'=>'test', + 'password'=>'test', + 'root'=>'', + // wait delay in seconds after write operations + // (only in tests) + // set to higher value for lighttpd webdav + 'wait'=> 0 +); + +DELIM + +echo "ownCloud container: $container" + +# put container IDs into a file to drop them after the test run (keep in mind that multiple tests run in parallel on the same host) +echo $container >> $thisFolder/dockerContainerOwnCloud.$EXECUTOR_NUMBER.webdav + +if [ -n "$databaseContainer" ]; then + echo "Database container: $databaseContainer" + echo $databaseContainer >> $thisFolder/dockerContainerOwnCloud.$EXECUTOR_NUMBER.webdav +fi + +if [ -n "$DEBUG" ]; then + echo $thisFolder/config.webdav.php +fi diff --git a/apps/files_external/tests/env/stop-webdav-ownCloud.sh b/apps/files_external/tests/env/stop-webdav-ownCloud.sh new file mode 100755 index 00000000000..2f06eadcf7c --- /dev/null +++ b/apps/files_external/tests/env/stop-webdav-ownCloud.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# +# ownCloud +# +# This script stops the docker container the files_external tests were run +# against. It will also revert the config changes done in start step. +# +# @author Morris Jobke +# @copyright 2014 Morris Jobke <hey@morrisjobke.de> +# + +if ! command -v docker >/dev/null 2>&1; then + echo "No docker executable found - skipped docker stop" + exit 0; +fi + +echo "Docker executable found - stop and remove docker containers" + +# retrieve current folder to remove the config from the parent folder +thisFolder=`echo $0 | replace "env/stop-webdav-ownCloud.sh" ""` + +echo "DEBUG" + +netstat -tlpen + +echo "CONFIG:" + +cat $thisFolder/config.webdav.php +cat $thisFolder/dockerContainerOwnCloud.$EXECUTOR_NUMBER.webdav + +# stopping and removing docker containers +for container in `cat $thisFolder/dockerContainerOwnCloud.$EXECUTOR_NUMBER.webdav`; do + echo "Stopping and removing docker container $container" + # kills running container and removes it + docker rm -f $container +done; + +# cleanup +rm $thisFolder/config.webdav.php +rm $thisFolder/dockerContainerOwnCloud.$EXECUTOR_NUMBER.webdav + diff --git a/apps/files_sharing/js/app.js b/apps/files_sharing/js/app.js index ff6997ab12f..3168e930829 100644 --- a/apps/files_sharing/js/app.js +++ b/apps/files_sharing/js/app.js @@ -39,7 +39,9 @@ OCA.Sharing.App = { this._extendFileList(this._inFileList); this._inFileList.appName = t('files_sharing', 'Shared with you'); - this._inFileList.$el.find('#emptycontent').text(t('files_sharing', 'No files have been shared with you yet.')); + this._inFileList.$el.find('#emptycontent').html('<div class="icon-share"></div>' + + '<h2>' + t('files_sharing', 'Nothing shared with you yet') + '</h2>' + + '<p>' + t('files_sharing', 'Files and folders others share with you will show up here') + '</p>'); return this._inFileList; }, @@ -59,7 +61,9 @@ OCA.Sharing.App = { this._extendFileList(this._outFileList); this._outFileList.appName = t('files_sharing', 'Shared with others'); - this._outFileList.$el.find('#emptycontent').text(t('files_sharing', 'You haven\'t shared any files yet.')); + this._outFileList.$el.find('#emptycontent').html('<div class="icon-share"></div>' + + '<h2>' + t('files_sharing', 'Nothing shared yet') + '</h2>' + + '<p>' + t('files_sharing', 'Files and folders you share will show up here') + '</p>'); return this._outFileList; }, @@ -79,7 +83,9 @@ OCA.Sharing.App = { this._extendFileList(this._linkFileList); this._linkFileList.appName = t('files_sharing', 'Shared by link'); - this._linkFileList.$el.find('#emptycontent').text(t('files_sharing', 'You haven\'t shared any files by link yet.')); + this._linkFileList.$el.find('#emptycontent').html('<div class="icon-public"></div>' + + '<h2>' + t('files_sharing', 'No shared links') + '</h2>' + + '<p>' + t('files_sharing', 'Files and folders you share by link will show up here') + '</p>'); return this._linkFileList; }, diff --git a/apps/files_trashbin/templates/index.php b/apps/files_trashbin/templates/index.php index fc18e88c41e..82bc360a9f5 100644 --- a/apps/files_trashbin/templates/index.php +++ b/apps/files_trashbin/templates/index.php @@ -4,7 +4,11 @@ </div> <div id='notification'></div> -<div id="emptycontent" class="hidden"><?php p($l->t('Nothing in here. Your trash bin is empty!'))?></div> +<div id="emptycontent" class="hidden"> + <div class="icon-delete"></div> + <h2><?php p($l->t('No deleted files')); ?></h2> + <p><?php p($l->t('You will be able to recover deleted files from here')); ?></p> +</div> <input type="hidden" name="dir" value="" id="dir"> diff --git a/autotest-external.sh b/autotest-external.sh new file mode 100755 index 00000000000..761477a4c97 --- /dev/null +++ b/autotest-external.sh @@ -0,0 +1,308 @@ +#!/bin/bash +# +# ownCloud +# +# @author Thomas Müller +# @author Morris Jobke +# @copyright 2012, 2013 Thomas Müller thomas.mueller@tmit.eu +# @copyright 2014 Morris Jobke hey@morrisjobke.de +# + +#$EXECUTOR_NUMBER is set by Jenkins and allows us to run autotest in parallel +DATABASENAME=oc_autotest$EXECUTOR_NUMBER +DATABASEUSER=oc_autotest$EXECUTOR_NUMBER +ADMINLOGIN=admin$EXECUTOR_NUMBER +BASEDIR=$PWD + +DBCONFIGS="sqlite mysql pgsql oci" +PHPUNIT=$(which phpunit) + +function print_syntax { + echo -e "Syntax: ./autotest-external.sh [dbconfigname] [startfile]\n" >&2 + echo -e "\t\"dbconfigname\" can be one of: $DBCONFIGS" >&2 + echo -e "\t\"startfile\" is the name of a start file inside the env/ folder in the files_external tests" >&2 + echo -e "\nExample: ./autotest.sh sqlite webdav-ownCloud" >&2 + echo "will run the external suite from \"apps/files_external/tests/env/start-webdav-ownCloud.sh\"" >&2 + echo -e "\nIf no arguments are specified, all available external backends will be run with all database configs" >&2 +} + +if ! [ -x "$PHPUNIT" ]; then + echo "phpunit executable not found, please install phpunit version >= 3.7" >&2 + exit 3 +fi + +PHPUNIT_VERSION=$("$PHPUNIT" --version | cut -d" " -f2) +PHPUNIT_MAJOR_VERSION=$(echo $PHPUNIT_VERSION | cut -d"." -f1) +PHPUNIT_MINOR_VERSION=$(echo $PHPUNIT_VERSION | cut -d"." -f2) + +if ! [ $PHPUNIT_MAJOR_VERSION -gt 3 -o \( $PHPUNIT_MAJOR_VERSION -eq 3 -a $PHPUNIT_MINOR_VERSION -ge 7 \) ]; then + echo "phpunit version >= 3.7 required. Version found: $PHPUNIT_VERSION" >&2 + exit 4 +fi + +if ! [ \( -w config -a ! -f config/config.php \) -o \( -f config/config.php -a -w config/config.php \) ]; then + echo "Please enable write permissions on config and config/config.php" >&2 + exit 1 +fi + +if [ "$1" ]; then + FOUND=0 + for DBCONFIG in $DBCONFIGS; do + if [ "$1" = $DBCONFIG ]; then + FOUND=1 + break + fi + done + if [ $FOUND = 0 ]; then + echo -e "Unknown database config name \"$1\"\n" >&2 + print_syntax + exit 2 + fi +fi + +# Back up existing (dev) config if one exists +if [ -f config/config.php ]; then + mv config/config.php config/config-autotest-backup.php +fi + +function restore_config { + # Restore existing config + if [ -f config/config-autotest-backup.php ]; then + mv config/config-autotest-backup.php config/config.php + fi +} + +# restore config on exit, even when killed +trap restore_config SIGINT SIGTERM + +# use tmpfs for datadir - should speedup unit test execution +if [ -d /dev/shm ]; then + DATADIR=/dev/shm/data-autotest$EXECUTOR_NUMBER +else + DATADIR=$BASEDIR/data-autotest +fi + +echo "Using database $DATABASENAME" + +# create autoconfig for sqlite, mysql and postgresql +cat > ./tests/autoconfig-sqlite.php <<DELIM +<?php +\$AUTOCONFIG = array ( + 'installed' => false, + 'dbtype' => 'sqlite', + 'dbtableprefix' => 'oc_', + 'adminlogin' => '$ADMINLOGIN', + 'adminpass' => 'admin', + 'directory' => '$DATADIR', +); +DELIM + +cat > ./tests/autoconfig-mysql.php <<DELIM +<?php +\$AUTOCONFIG = array ( + 'installed' => false, + 'dbtype' => 'mysql', + 'dbtableprefix' => 'oc_', + 'adminlogin' => '$ADMINLOGIN', + 'adminpass' => 'admin', + 'directory' => '$DATADIR', + 'dbuser' => '$DATABASEUSER', + 'dbname' => '$DATABASENAME', + 'dbhost' => 'localhost', + 'dbpass' => 'owncloud', +); +DELIM + +cat > ./tests/autoconfig-pgsql.php <<DELIM +<?php +\$AUTOCONFIG = array ( + 'installed' => false, + 'dbtype' => 'pgsql', + 'dbtableprefix' => 'oc_', + 'adminlogin' => '$ADMINLOGIN', + 'adminpass' => 'admin', + 'directory' => '$DATADIR', + 'dbuser' => '$DATABASEUSER', + 'dbname' => '$DATABASENAME', + 'dbhost' => 'localhost', + 'dbpass' => 'owncloud', +); +DELIM + +cat > ./tests/autoconfig-oci.php <<DELIM +<?php +\$AUTOCONFIG = array ( + 'installed' => false, + 'dbtype' => 'oci', + 'dbtableprefix' => 'oc_', + 'adminlogin' => '$ADMINLOGIN', + 'adminpass' => 'admin', + 'directory' => '$DATADIR', + 'dbuser' => '$DATABASENAME', + 'dbname' => 'XE', + 'dbhost' => 'localhost', + 'dbpass' => 'owncloud', +); +DELIM + +function execute_tests { + echo "Setup environment for $1 testing ..." + # back to root folder + cd "$BASEDIR" + + # revert changes to tests/data + git checkout tests/data + + # reset data directory + rm -rf "$DATADIR" + mkdir "$DATADIR" + + # remove the old config file + #rm -rf config/config.php + cp tests/preseed-config.php config/config.php + + # drop database + if [ "$1" == "mysql" ] ; then + mysql -u $DATABASEUSER -powncloud -e "DROP DATABASE IF EXISTS $DATABASENAME" || true + fi + if [ "$1" == "pgsql" ] ; then + dropdb -U $DATABASEUSER $DATABASENAME || true + fi + if [ "$1" == "oci" ] ; then + echo "drop the database" + sqlplus -s -l / as sysdba <<EOF + drop user $DATABASENAME cascade; +EOF + + echo "create the database" + sqlplus -s -l / as sysdba <<EOF + create user $DATABASENAME identified by owncloud; + alter user $DATABASENAME default tablespace users + temporary tablespace temp + quota unlimited on users; + grant create session + , create table + , create procedure + , create sequence + , create trigger + , create view + , create synonym + , alter session + to $DATABASENAME; + exit; +EOF + fi + + # copy autoconfig + cp "$BASEDIR/tests/autoconfig-$1.php" "$BASEDIR/config/autoconfig.php" + + # trigger installation + echo "INDEX" + php -f index.php | grep -i -C9999 error && echo "Error during setup" && exit 101 + echo "END INDEX" + + #test execution + echo "Testing with $1 ..." + + if [ -n "$2" ]; then + echo "Run only $2 ..." + fi + + cd tests + rm -rf "coverage-external-html-$1" + mkdir "coverage-external-html-$1" + # just enable files_external + php ../occ app:enable files_external + if [ -z "$NOCOVERAGE" ]; then + #"$PHPUNIT" --configuration phpunit-autotest-external.xml --log-junit "autotest-external-results-$1.xml" --coverage-clover "autotest-external-clover-$1.xml" --coverage-html "coverage-external-html-$1" + RESULT=$? + else + echo "No coverage" + #"$PHPUNIT" --configuration phpunit-autotest-external.xml --log-junit "autotest-external-results-$1.xml" + RESULT=$? + fi + + FILES_EXTERNAL_BACKEND_PATH=../apps/files_external/tests/backends + FILES_EXTERNAL_BACKEND_ENV_PATH=../apps/files_external/tests/env + + for startFile in `ls -1 $FILES_EXTERNAL_BACKEND_ENV_PATH | grep start`; do + name=`echo $startFile | replace "start-" "" | replace ".sh" ""` + + if [ -n "$2" -a "$2" != "$name" ]; then + echo "skip: $startFile" + continue; + fi + + echo "start: $startFile" + echo "name: $name" + + # execute start file + ./$FILES_EXTERNAL_BACKEND_ENV_PATH/$startFile + + # getting backend to test from filename + # it's the part between the dots startSomething.TestToRun.sh + testToRun=`echo $startFile | cut -d '-' -f 2` + + # run the specific test + if [ -z "$NOCOVERAGE" ]; then + rm -rf "coverage-external-html-$1-$name" + mkdir "coverage-external-html-$1-$name" + "$PHPUNIT" --configuration phpunit-autotest-external.xml --log-junit "autotest-external-results-$1-$name.xml" --coverage-clover "autotest-external-clover-$1-$name.xml" --coverage-html "coverage-external-html-$1-$name" "$FILES_EXTERNAL_BACKEND_PATH/$testToRun.php" + RESULT=$? + else + echo "No coverage" + "$PHPUNIT" --configuration phpunit-autotest-external.xml --log-junit "autotest-external-results-$1-$name.xml" "$FILES_EXTERNAL_BACKEND_PATH/$testToRun.php" + RESULT=$? + fi + + # calculate stop file + stopFile=`echo "$startFile" | replace start stop` + echo "stop: $stopFile" + if [ -f $FILES_EXTERNAL_BACKEND_ENV_PATH/$stopFile ]; then + # execute stop file if existant + ./$FILES_EXTERNAL_BACKEND_ENV_PATH/$stopFile + fi + done; +} + +# +# start test execution +# +if [ -z "$1" ] + then + # run all known database configs + for DBCONFIG in $DBCONFIGS; do + execute_tests $DBCONFIG "$2" + done +else + execute_tests "$1" "$2" +fi + +cd "$BASEDIR" + +restore_config +# +# NOTES on mysql: +# - CREATE DATABASE oc_autotest; +# - CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY 'owncloud'; +# - grant all on oc_autotest.* to 'oc_autotest'@'localhost'; +# +# - for parallel executor support with EXECUTOR_NUMBER=0: +# - CREATE DATABASE oc_autotest0; +# - CREATE USER 'oc_autotest0'@'localhost' IDENTIFIED BY 'owncloud'; +# - grant all on oc_autotest0.* to 'oc_autotest0'@'localhost'; +# +# NOTES on pgsql: +# - su - postgres +# - createuser -P oc_autotest (enter password and enable superuser) +# - to enable dropdb I decided to add following line to pg_hba.conf (this is not the safest way but I don't care for the testing machine): +# local all all trust +# +# - for parallel executor support with EXECUTOR_NUMBER=0: +# - createuser -P oc_autotest0 (enter password and enable superuser) +# +# NOTES on oci: +# - it's a pure nightmare to install Oracle on a Linux-System +# - DON'T TRY THIS AT HOME! +# - if you really need it: we feel sorry for you +# diff --git a/core/css/icons.css b/core/css/icons.css index 095c29b3121..ecf6b17995d 100644 --- a/core/css/icons.css +++ b/core/css/icons.css @@ -68,6 +68,10 @@ background-image: url('../img/actions/download.svg'); } +.icon-external { + background-image: url('../img/actions/external.svg'); +} + .icon-history { background-image: url('../img/actions/history.svg'); } diff --git a/core/css/styles.css b/core/css/styles.css index 856ba68def8..12408c2d76c 100644 --- a/core/css/styles.css +++ b/core/css/styles.css @@ -328,6 +328,20 @@ input[type="submit"].enabled { top: 30%; width: 100%; } +#emptycontent h2 { + font-size: 22px; + margin-bottom: 10px; +} +#emptycontent [class^="icon-"], +#emptycontent [class*=" icon-"] { + background-size: 64px; + height: 64px; + width: 64px; + margin: 0 auto 15px; + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; + filter: alpha(opacity=50); + opacity: .5; +} /* LOG IN & INSTALLATION ------------------------------------------------------------ */ diff --git a/core/img/actions/external.png b/core/img/actions/external.png Binary files differnew file mode 100644 index 00000000000..af03dbf3e05 --- /dev/null +++ b/core/img/actions/external.png diff --git a/core/img/actions/external.svg b/core/img/actions/external.svg new file mode 100644 index 00000000000..80eba5b9960 --- /dev/null +++ b/core/img/actions/external.svg @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> + <path d="m7.4515 1.6186 2.3806 2.2573-3.5709 3.386 2.3806 2.2573 3.5709-3.386 2.3806 2.2573v-6.7725h-7.1422zm-4.7612 1.1286c-0.65945 0-1.1903 0.5034-1.1903 1.1286v9.029c0 0.6253 0.53085 1.1286 1.1903 1.1286h9.522c0.6594 0 1.1903-0.5034 1.1903-1.1286v-3.386l-1.19-1.1287v4.5146h-9.5217v-9.029h4.761l-1.1905-1.1287h-3.5707z"/> +</svg> diff --git a/lib/base.php b/lib/base.php index 1dd259b0914..ae87ecff394 100644 --- a/lib/base.php +++ b/lib/base.php @@ -766,6 +766,7 @@ class OC { // For guests: Load only authentication, filesystem and logging OC_App::loadApps(array('authentication')); OC_App::loadApps(array('filesystem', 'logging')); + \OC_User::tryBasicAuthLogin(); } } diff --git a/lib/private/api.php b/lib/private/api.php index 66b763fdc3e..35a09c5cd1b 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -47,6 +47,7 @@ class OC_API { */ protected static $actions = array(); private static $logoutRequired = false; + private static $isLoggedIn = false; /** * registers an api call @@ -269,7 +270,10 @@ class OC_API { * http basic auth * @return string|false (username, or false on failure) */ - private static function loginUser(){ + private static function loginUser() { + if(self::$isLoggedIn === true) { + return \OC_User::getUser(); + } // reuse existing login $loggedIn = OC_User::isLoggedIn(); @@ -279,6 +283,7 @@ class OC_API { // initialize the user's filesystem \OC_Util::setUpFS(\OC_User::getUser()); + self::$isLoggedIn = true; return OC_User::getUser(); } @@ -296,6 +301,7 @@ class OC_API { // initialize the user's filesystem \OC_Util::setUpFS(\OC_User::getUser()); + self::$isLoggedIn = true; return $authUser; } diff --git a/lib/private/app/infoparser.php b/lib/private/app/infoparser.php index 0bfbf6bd139..0603a7a7b7f 100644 --- a/lib/private/app/infoparser.php +++ b/lib/private/app/infoparser.php @@ -41,8 +41,9 @@ class InfoParser { return null; } + libxml_use_internal_errors(true); $loadEntities = libxml_disable_entity_loader(false); - $xml = @simplexml_load_file($file); + $xml = simplexml_load_file($file); libxml_disable_entity_loader($loadEntities); if ($xml == false) { return null; diff --git a/lib/private/appframework/core/api.php b/lib/private/appframework/core/api.php index f68c677d106..2f01015bb15 100644 --- a/lib/private/appframework/core/api.php +++ b/lib/private/appframework/core/api.php @@ -32,6 +32,7 @@ use OCP\AppFramework\IApi; * * Should you find yourself in need for more methods, simply inherit from this * class and add your methods + * @deprecated */ class API implements IApi{ @@ -58,6 +59,7 @@ class API implements IApi{ /** * Adds a new javascript file + * @deprecated include javascript and css in template files * @param string $scriptName the name of the javascript in js/ without the suffix * @param string $appName the name of the app, defaults to the current one */ @@ -71,6 +73,7 @@ class API implements IApi{ /** * Adds a new css file + * @deprecated include javascript and css in template files * @param string $styleName the name of the css file in css/without the suffix * @param string $appName the name of the app, defaults to the current one */ @@ -83,6 +86,7 @@ class API implements IApi{ /** + * @deprecated include javascript and css in template files * shorthand for addScript for files in the 3rdparty directory * @param string $name the name of the file without the suffix */ @@ -92,6 +96,7 @@ class API implements IApi{ /** + * @deprecated include javascript and css in template files * shorthand for addStyle for files in the 3rdparty directory * @param string $name the name of the file without the suffix */ @@ -101,7 +106,10 @@ class API implements IApi{ /** + * @deprecated communication between apps should happen over built in + * callbacks or interfaces (check the contacts and calendar managers) * Checks if an app is enabled + * also use \OC::$server->getAppManager()->isEnabledForUser($appName) * @param string $appName the name of an app * @return bool true if app is enabled */ @@ -120,6 +128,7 @@ class API implements IApi{ } /** + * @deprecated register hooks directly for class that build in hook interfaces * connects a function to a hook * @param string $signalClass class name of emitter * @param string $signalName name of signal @@ -134,6 +143,7 @@ class API implements IApi{ } /** + * @deprecated implement the emitter interface instead * Emits a signal. To get data from the slot use references! * @param string $signalClass class name of emitter * @param string $signalName name of signal @@ -146,6 +156,7 @@ class API implements IApi{ /** * clear hooks + * @deprecated clear hooks directly for class that build in hook interfaces * @param string $signalClass * @param string $signalName */ diff --git a/lib/private/appframework/dependencyinjection/dicontainer.php b/lib/private/appframework/dependencyinjection/dicontainer.php index 98525ed3202..dc57ef4c167 100644 --- a/lib/private/appframework/dependencyinjection/dicontainer.php +++ b/lib/private/appframework/dependencyinjection/dicontainer.php @@ -155,6 +155,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{ /** + * @deprecated implements only deprecated methods * @return IApi */ function getCoreApi() @@ -187,6 +188,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{ } /** + * @deprecated use IUserSession->isLoggedIn() * @return boolean */ function isLoggedIn() { @@ -194,6 +196,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{ } /** + * @deprecated use IGroupManager->isAdmin($userId) * @return boolean */ function isAdminUser() { @@ -206,6 +209,7 @@ class DIContainer extends SimpleContainer implements IAppContainer{ } /** + * @deprecated use the ILogger instead * @param string $message * @param string $level * @return mixed diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index be7bf972693..8dcf14fc1d2 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -170,7 +170,14 @@ class Manager extends PublicEmitter implements IGroupManager { * @return \OC\Group\Group[] */ public function getUserGroups($user) { - $uid = $user->getUID(); + return $this->getUserIdGroups($user->getUID()); + } + + /** + * @param string $uid the user id + * @return \OC\Group\Group[] + */ + public function getUserIdGroups($uid) { if (isset($this->cachedUserGroups[$uid])) { return $this->cachedUserGroups[$uid]; } @@ -184,7 +191,26 @@ class Manager extends PublicEmitter implements IGroupManager { $this->cachedUserGroups[$uid] = $groups; return $this->cachedUserGroups[$uid]; } - + + /** + * Checks if a userId is in the admin group + * @param string $userId + * @return bool if admin + */ + public function isAdmin($userId) { + return $this->isInGroup($userId, 'admin'); + } + + /** + * Checks if a userId is in a group + * @param string $userId + * @param group $group + * @return bool if in group + */ + public function isInGroup($userId, $group) { + return array_key_exists($group, $this->getUserIdGroups($userId)); + } + /** * get a list of group ids for a user * @param \OC\User\User $user diff --git a/lib/private/user.php b/lib/private/user.php index ff45e9e26a6..9a2ea3ef74f 100644 --- a/lib/private/user.php +++ b/lib/private/user.php @@ -320,6 +320,15 @@ class OC_User { } /** + * Tries to login the user with HTTP Basic Authentication + */ + public static function tryBasicAuthLogin() { + if(!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_USER'])) { + \OC_User::login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); + } + } + + /** * Check if the user is logged in, considers also the HTTP basic credentials * @return bool */ @@ -328,11 +337,6 @@ class OC_User { return self::userExists(\OC::$server->getSession()->get('user_id')); } - // Check whether the user has authenticated using Basic Authentication - if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { - return \OC_User::login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); - } - return false; } diff --git a/lib/private/user/session.php b/lib/private/user/session.php index 277aa1a047e..53662d00952 100644 --- a/lib/private/user/session.php +++ b/lib/private/user/session.php @@ -138,6 +138,15 @@ class Session implements IUserSession, Emitter { } /** + * Checks wether the user is logged in + * + * @return bool if logged in + */ + public function isLoggedIn() { + return $this->getUser() !== null; + } + + /** * set the login name * * @param string|null $loginName for the logged in user diff --git a/lib/public/appframework/iapi.php b/lib/public/appframework/iapi.php index ecbc0fd1900..96199d90b92 100644 --- a/lib/public/appframework/iapi.php +++ b/lib/public/appframework/iapi.php @@ -30,6 +30,7 @@ namespace OCP\AppFramework; /** * A few very basic and frequently used API functions are combined in here + * @deprecated */ interface IApi { @@ -44,6 +45,7 @@ interface IApi { /** * Adds a new javascript file + * @deprecated include javascript and css in template files * @param string $scriptName the name of the javascript in js/ without the suffix * @param string $appName the name of the app, defaults to the current one * @return void @@ -53,6 +55,7 @@ interface IApi { /** * Adds a new css file + * @deprecated include javascript and css in template files * @param string $styleName the name of the css file in css/without the suffix * @param string $appName the name of the app, defaults to the current one * @return void @@ -61,6 +64,7 @@ interface IApi { /** + * @deprecated include javascript and css in template files * shorthand for addScript for files in the 3rdparty directory * @param string $name the name of the file without the suffix * @return void @@ -69,6 +73,7 @@ interface IApi { /** + * @deprecated include javascript and css in template files * shorthand for addStyle for files in the 3rdparty directory * @param string $name the name of the file without the suffix * @return void @@ -78,6 +83,10 @@ interface IApi { /** * Checks if an app is enabled + * @deprecated communication between apps should happen over built in + * callbacks or interfaces (check the contacts and calendar managers) + * Checks if an app is enabled + * also use \OC::$server->getAppManager()->isEnabledForUser($appName) * @param string $appName the name of an app * @return bool true if app is enabled */ diff --git a/lib/public/appframework/iappcontainer.php b/lib/public/appframework/iappcontainer.php index a0b0c06881a..cb75bf4026c 100644 --- a/lib/public/appframework/iappcontainer.php +++ b/lib/public/appframework/iappcontainer.php @@ -31,7 +31,7 @@ use OCP\IContainer; * * This container interface provides short cuts for app developers to access predefined app service. */ -interface IAppContainer extends IContainer{ +interface IAppContainer extends IContainer { /** * used to return the appname of the set application @@ -40,6 +40,7 @@ interface IAppContainer extends IContainer{ function getAppName(); /** + * @deprecated implements only deprecated methods * @return IApi */ function getCoreApi(); @@ -56,16 +57,21 @@ interface IAppContainer extends IContainer{ function registerMiddleWare($middleWare); /** + * @deprecated use IUserSession->isLoggedIn() * @return boolean */ function isLoggedIn(); /** + * @deprecated use IGroupManager->isAdmin($userId) * @return boolean + * @deprecated use the groupmanager instead to find out if the user is in + * the admin group */ function isAdminUser(); /** + * @deprecated use the ILogger instead * @param string $message * @param string $level * @return mixed diff --git a/lib/public/igroupmanager.php b/lib/public/igroupmanager.php index dc69044c490..8f468574c6b 100644 --- a/lib/public/igroupmanager.php +++ b/lib/public/igroupmanager.php @@ -80,4 +80,19 @@ interface IGroupManager { * @return array an array of display names (value) and user ids (key) */ public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0); + + /** + * Checks if a userId is in the admin group + * @param string $userId + * @return bool if admin + */ + public function isAdmin($userId); + + /** + * Checks if a userId is in a group + * @param string $userId + * @param group $group + * @return bool if in group + */ + public function isInGroup($userId, $group); } diff --git a/lib/public/iusersession.php b/lib/public/iusersession.php index db4abe150d2..4c5b4d1ba51 100644 --- a/lib/public/iusersession.php +++ b/lib/public/iusersession.php @@ -3,7 +3,9 @@ * ownCloud * * @author Bart Visscher + * @author Bernhard Posselt * @copyright 2013 Bart Visscher bartv@thisnet.nl + * @copyright 2014 Bernhard Posselt <dev@bernhard-posselt.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -62,4 +64,11 @@ interface IUserSession { * @return \OCP\IUser */ public function getUser(); + + /** + * Checks wether the user is logged in + * + * @return bool if logged in + */ + public function isLoggedIn(); } diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php index f72ea8e912f..e3462caf806 100644 --- a/tests/lib/group/manager.php +++ b/tests/lib/group/manager.php @@ -304,6 +304,78 @@ class Manager extends \Test\TestCase { $this->assertEquals('group1', $group1->getGID()); } + public function testInGroup() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->once()) + ->method('getUserGroups') + ->with('user1') + ->will($this->returnValue(array('group1', 'admin', 'group2'))); + $backend->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $userBackend = $this->getMock('\OC_User_Backend'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $this->assertTrue($manager->isInGroup('user1', 'group1')); + } + + public function testIsAdmin() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->once()) + ->method('getUserGroups') + ->with('user1') + ->will($this->returnValue(array('group1', 'admin', 'group2'))); + $backend->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $userBackend = $this->getMock('\OC_User_Backend'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $this->assertTrue($manager->isAdmin('user1')); + } + + public function testNotAdmin() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->once()) + ->method('getUserGroups') + ->with('user1') + ->will($this->returnValue(array('group1', 'group2'))); + $backend->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $userBackend = $this->getMock('\OC_User_Backend'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $this->assertFalse($manager->isAdmin('user1')); + } + public function testGetUserGroupsMultipleBackends() { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 diff --git a/tests/lib/user/session.php b/tests/lib/user/session.php index aa1ea5841c0..4dc7f29c5b8 100644 --- a/tests/lib/user/session.php +++ b/tests/lib/user/session.php @@ -34,6 +34,46 @@ class Session extends \Test\TestCase { $this->assertEquals('foo', $user->getUID()); } + public function testIsLoggedIn() { + $session = $this->getMock('\OC\Session\Memory', array(), array('')); + $session->expects($this->once()) + ->method('get') + ->with('user_id') + ->will($this->returnValue('foo')); + + $backend = $this->getMock('OC_User_Dummy'); + $backend->expects($this->once()) + ->method('userExists') + ->with('foo') + ->will($this->returnValue(true)); + + $manager = new \OC\User\Manager(); + $manager->registerBackend($backend); + + $userSession = new \OC\User\Session($manager, $session); + $isLoggedIn = $userSession->isLoggedIn(); + $this->assertTrue($isLoggedIn); + } + + public function testNotLoggedIn() { + $session = $this->getMock('\OC\Session\Memory', array(), array('')); + $session->expects($this->once()) + ->method('get') + ->with('user_id') + ->will($this->returnValue(null)); + + $backend = $this->getMock('OC_User_Dummy'); + $backend->expects($this->never()) + ->method('userExists'); + + $manager = new \OC\User\Manager(); + $manager->registerBackend($backend); + + $userSession = new \OC\User\Session($manager, $session); + $isLoggedIn = $userSession->isLoggedIn(); + $this->assertFalse($isLoggedIn); + } + public function testSetUser() { $session = $this->getMock('\OC\Session\Memory', array(), array('')); $session->expects($this->once()) diff --git a/tests/phpunit-autotest-external.xml b/tests/phpunit-autotest-external.xml new file mode 100644 index 00000000000..b9402bfa572 --- /dev/null +++ b/tests/phpunit-autotest-external.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="utf-8" ?> +<phpunit bootstrap="bootstrap.php" + strict="true" + verbose="true" + timeoutForSmallTests="900" + timeoutForMediumTests="900" + timeoutForLargeTests="900" +> + <testsuite name='ownCloud files external'> + <directory suffix=".php">../apps/files_external/tests</directory> + <!-- exclude backends as they are called separately --> + <exclude>../apps/files_external/tests/backends/</exclude> + </testsuite> + <!-- filters for code coverage --> + <filter> + <!-- whitelist processUncoveredFilesFromWhitelist="true" --> + <whitelist> + <file>../lib/private/files/storage/dav.php</file> + <directory suffix=".php">../apps/files_external</directory> + <exclude> + <directory suffix=".php">../apps/files_external/l10n</directory> + <directory suffix=".php">../apps/files_external/3rdparty</directory> + <directory suffix=".php">../apps/files_external/tests</directory> + </exclude> + </whitelist> + </filter> + <!--<listeners> + <listener class="StartSessionListener" file="startsessionlistener.php" /> + <listener class="TestCleanupListener" file="testcleanuplistener.php"> + <arguments> + <string>detail</string> + </arguments> + </listener> + </listeners>--> +</phpunit> + |