Merge pull request #10425 from owncloud/set_default_share_folder

Set default share folder
This commit is contained in:
Björn Schießle 2014-08-19 10:21:21 +02:00
commit 19610157d3
8 changed files with 123 additions and 4 deletions

View File

@ -113,5 +113,8 @@ function removeSharedFolder($mkdirs = true, $chunkSize = 99) {
$query->execute(array()); $query->execute(array());
} }
// set config to keep the Shared folder as the default location for new shares
\OCA\Files_Sharing\Helper::setShareFolder('/Shared');
} }
} }

View File

@ -237,4 +237,24 @@ class Helper {
return ($result === 'yes') ? true : false; 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);
}
} }

View File

@ -61,7 +61,8 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
* @return string * @return string
*/ */
public function generateTarget($filePath, $shareWith, $exclude = null) { 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 // for group shares we return the target right away
if ($shareWith === false) { if ($shareWith === false) {
@ -70,6 +71,18 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
\OC\Files\Filesystem::initMountPoints($shareWith); \OC\Files\Filesystem::initMountPoints($shareWith);
$view = new \OC\Files\View('/' . $shareWith . '/files'); $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); $excludeList = \OCP\Share::getItemsSharedWithUser('file', $shareWith, self::FORMAT_TARGET_NAMES);
if (is_array($exclude)) { if (is_array($exclude)) {
$excludeList = array_merge($excludeList, $exclude); $excludeList = array_merge($excludeList, $exclude);

View File

@ -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');
}
}

View File

@ -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 * shared files should never have delete permissions
* @dataProvider DataProviderTestFileSharePermissions * @dataProvider DataProviderTestFileSharePermissions

View File

@ -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 * @medium
*/ */
function testDeleteParentOfMountPoint() { function testParentOfMountPointIsGone() {
// share to user // share to user
$fileinfo = $this->view->getFileInfo($this->folder); $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)); $this->assertFalse($user2View->is_dir($this->folder));
// delete the local folder // delete the local folder
$result = $user2View->unlink('/localfolder'); $fullPath = \OC_Config::getValue('datadirectory') . '/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder';
$this->assertTrue($result); rmdir($fullPath);
//enforce reload of the mount points //enforce reload of the mount points
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); self::loginHelper(self::TEST_FILES_SHARING_API_USER2);

View File

@ -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 // cleanup
$this->cleanupSharedTable(); $this->cleanupSharedTable();
\OCP\Config::deleteSystemValue('share_folder');
} }

View File

@ -341,4 +341,9 @@ $CONFIG = array(
), ),
), ),
/**
* define default folder for shared files and folders
*/
'share_folder' => '/',
); );