diff options
author | Björn Schießle <schiessle@owncloud.com> | 2014-08-19 10:21:21 +0200 |
---|---|---|
committer | Björn Schießle <schiessle@owncloud.com> | 2014-08-19 10:21:21 +0200 |
commit | 19610157d30462038d99ff4ce23422c224594067 (patch) | |
tree | dbd9d9ed32fa91c98e19a2d72e365ca453e8b4a3 | |
parent | 312ed5330781cff8bcd420077deeb96e5d39f245 (diff) | |
parent | 594078e22f0227f8dafe3726b67ade21187e5836 (diff) | |
download | nextcloud-server-19610157d30462038d99ff4ce23422c224594067.tar.gz nextcloud-server-19610157d30462038d99ff4ce23422c224594067.zip |
Merge pull request #10425 from owncloud/set_default_share_folder
Set default share folder
-rw-r--r-- | apps/files_sharing/appinfo/update.php | 3 | ||||
-rw-r--r-- | apps/files_sharing/lib/helper.php | 20 | ||||
-rw-r--r-- | apps/files_sharing/lib/share/file.php | 15 | ||||
-rw-r--r-- | apps/files_sharing/tests/helper.php | 41 | ||||
-rw-r--r-- | apps/files_sharing/tests/share.php | 30 | ||||
-rw-r--r-- | apps/files_sharing/tests/sharedstorage.php | 8 | ||||
-rw-r--r-- | apps/files_sharing/tests/update.php | 5 | ||||
-rwxr-xr-x | config/config.sample.php | 5 |
8 files changed, 123 insertions, 4 deletions
diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php index 72acdbac736..e393b1575af 100644 --- a/apps/files_sharing/appinfo/update.php +++ b/apps/files_sharing/appinfo/update.php @@ -113,5 +113,8 @@ function removeSharedFolder($mkdirs = true, $chunkSize = 99) { $query->execute(array()); } + // set config to keep the Shared folder as the default location for new shares + \OCA\Files_Sharing\Helper::setShareFolder('/Shared'); + } } diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php index c15b1d48114..f444404c2b1 100644 --- a/apps/files_sharing/lib/helper.php +++ b/apps/files_sharing/lib/helper.php @@ -237,4 +237,24 @@ class Helper { return ($result === 'yes') ? true : false; } + /** + * get default share folder + * + * @return string + */ + public static function getShareFolder() { + $shareFolder = \OCP\Config::getSystemValue('share_folder', '/'); + + return \OC\Files\Filesystem::normalizePath($shareFolder); + } + + /** + * set default share folder + * + * @param string $shareFolder + */ + public static function setShareFolder($shareFolder) { + \OCP\Config::setSystemValue('share_folder', $shareFolder); + } + } diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php index 91595461a61..2ae7fdc16ab 100644 --- a/apps/files_sharing/lib/share/file.php +++ b/apps/files_sharing/lib/share/file.php @@ -61,7 +61,8 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { * @return string */ public function generateTarget($filePath, $shareWith, $exclude = null) { - $target = '/'.basename($filePath); + $shareFolder = \OCA\Files_Sharing\Helper::getShareFolder(); + $target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($filePath)); // for group shares we return the target right away if ($shareWith === false) { @@ -70,6 +71,18 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { \OC\Files\Filesystem::initMountPoints($shareWith); $view = new \OC\Files\View('/' . $shareWith . '/files'); + + if (!$view->is_dir($shareFolder)) { + $dir = ''; + $subdirs = explode('/', $shareFolder); + foreach ($subdirs as $subdir) { + $dir = $dir . '/' . $subdir; + if (!$view->is_dir($dir)) { + $view->mkdir($dir); + } + } + } + $excludeList = \OCP\Share::getItemsSharedWithUser('file', $shareWith, self::FORMAT_TARGET_NAMES); if (is_array($exclude)) { $excludeList = array_merge($excludeList, $exclude); diff --git a/apps/files_sharing/tests/helper.php b/apps/files_sharing/tests/helper.php new file mode 100644 index 00000000000..6169a9f5094 --- /dev/null +++ b/apps/files_sharing/tests/helper.php @@ -0,0 +1,41 @@ +<?php +/** + * ownCloud + * + * @author Bjoern Schiessle + * @copyright 2014 Bjoern Schiessle <schiessle@owncloud.com> + * + * 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/>. + * + */ +require_once __DIR__ . '/base.php'; + +class Test_Files_Sharing_Helper extends Test_Files_Sharing_Base { + + /** + * test set and get share folder + */ + function testSetGetShareFolder() { + $this->assertSame('/', \OCA\Files_Sharing\Helper::getShareFolder()); + + \OCA\Files_Sharing\Helper::setShareFolder('/Shared'); + + $this->assertSame('/Shared', \OCA\Files_Sharing\Helper::getShareFolder()); + + // cleanup + \OCP\Config::deleteSystemValue('share_folder'); + + } + +} diff --git a/apps/files_sharing/tests/share.php b/apps/files_sharing/tests/share.php index d3ca1816c75..31246c5df44 100644 --- a/apps/files_sharing/tests/share.php +++ b/apps/files_sharing/tests/share.php @@ -125,6 +125,36 @@ class Test_Files_Sharing extends Test_Files_Sharing_Base { } + function testShareWithDifferentShareFolder() { + + $fileinfo = $this->view->getFileInfo($this->filename); + $folderinfo = $this->view->getFileInfo($this->folder); + + $fileShare = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, + self::TEST_FILES_SHARING_API_USER2, 31); + $this->assertTrue($fileShare); + + \OCA\Files_Sharing\Helper::setShareFolder('/Shared/subfolder'); + + $folderShare = \OCP\Share::shareItem('folder', $folderinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, + self::TEST_FILES_SHARING_API_USER2, 31); + $this->assertTrue($folderShare); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER2); + + $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename)); + $this->assertTrue(\OC\Files\Filesystem::file_exists('/Shared/subfolder/' . $this->folder)); + + //cleanup + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, + self::TEST_FILES_SHARING_API_USER2); + \OCP\Share::unshare('folder', $folderinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, + self::TEST_FILES_SHARING_API_USER2); + + \OCP\Config::deleteSystemValue('share_folder'); + } + /** * shared files should never have delete permissions * @dataProvider DataProviderTestFileSharePermissions diff --git a/apps/files_sharing/tests/sharedstorage.php b/apps/files_sharing/tests/sharedstorage.php index 27f3b5150d5..972f9257e25 100644 --- a/apps/files_sharing/tests/sharedstorage.php +++ b/apps/files_sharing/tests/sharedstorage.php @@ -52,9 +52,11 @@ class Test_Files_Sharing_Storage extends Test_Files_Sharing_Base { } /** + * if the parent of the mount point is gone then the mount point should move up + * * @medium */ - function testDeleteParentOfMountPoint() { + function testParentOfMountPointIsGone() { // share to user $fileinfo = $this->view->getFileInfo($this->folder); @@ -79,8 +81,8 @@ class Test_Files_Sharing_Storage extends Test_Files_Sharing_Base { $this->assertFalse($user2View->is_dir($this->folder)); // delete the local folder - $result = $user2View->unlink('/localfolder'); - $this->assertTrue($result); + $fullPath = \OC_Config::getValue('datadirectory') . '/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder'; + rmdir($fullPath); //enforce reload of the mount points self::loginHelper(self::TEST_FILES_SHARING_API_USER2); diff --git a/apps/files_sharing/tests/update.php b/apps/files_sharing/tests/update.php index d3555cc2ee3..be29c38acc3 100644 --- a/apps/files_sharing/tests/update.php +++ b/apps/files_sharing/tests/update.php @@ -152,8 +152,13 @@ class Test_Files_Sharing_Update_Routine extends Test_Files_Sharing_Base { } } + $shareFolder = \OCP\Config::getSystemValue('share_folder', '/'); + + $this->assertSame('/Shared', $shareFolder); + // cleanup $this->cleanupSharedTable(); + \OCP\Config::deleteSystemValue('share_folder'); } diff --git a/config/config.sample.php b/config/config.sample.php index a0f3e0a4e72..2aa240afe22 100755 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -341,4 +341,9 @@ $CONFIG = array( ), ), +/** + * define default folder for shared files and folders + */ +'share_folder' => '/', + ); |