Merge pull request #8666 from owncloud/mount-remove
Support for (re)moving mountpointsremotes/origin/ldap_group_count
commit
c47d4ebbac
@ -0,0 +1,40 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OCA\Files_External; |
||||
|
||||
use OC\Files\Mount\Mount; |
||||
use OC\Files\Mount\MoveableMount; |
||||
|
||||
/** |
||||
* Person mount points can be moved by the user |
||||
*/ |
||||
class PersonalMount extends Mount implements MoveableMount { |
||||
/** |
||||
* Move the mount point to $target |
||||
* |
||||
* @param string $target the target mount point |
||||
* @return bool |
||||
*/ |
||||
public function moveMount($target) { |
||||
$result = \OC_Mount_Config::movePersonalMountPoint($this->getMountPoint(), $target, \OC_Mount_Config::MOUNT_TYPE_USER); |
||||
$this->setMountPoint($target); |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* Remove the mount points |
||||
* |
||||
* @return bool |
||||
*/ |
||||
public function removeMount() { |
||||
$user = \OCP\User::getUser(); |
||||
$relativeMountPoint = substr($this->getMountPoint(), strlen('/' . $user . '/files/')); |
||||
return \OC_Mount_Config::removeMountPoint($relativeMountPoint, \OC_Mount_Config::MOUNT_TYPE_USER, $user , true); |
||||
} |
||||
} |
@ -1 +1 @@ |
||||
0.4.1 |
||||
0.5 |
||||
|
@ -0,0 +1,161 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OCA\Files_Sharing; |
||||
|
||||
use OC\Files\Filesystem; |
||||
use OC\Files\Mount\Mount; |
||||
use OC\Files\Mount\MoveableMount; |
||||
use OC\Files\Storage\Shared; |
||||
|
||||
/** |
||||
* Shared mount points can be moved by the user |
||||
*/ |
||||
class SharedMount extends Mount implements MoveableMount { |
||||
/** |
||||
* @var \OC\Files\Storage\Shared $storage |
||||
*/ |
||||
protected $storage = null; |
||||
|
||||
public function __construct($storage, $mountpoint, $arguments = null, $loader = null) { |
||||
// first update the mount point before creating the parent |
||||
$newMountPoint = self::verifyMountPoint($arguments['share']); |
||||
$absMountPoint = '/' . \OCP\User::getUser() . '/files' . $newMountPoint; |
||||
parent::__construct($storage, $absMountPoint, $arguments, $loader); |
||||
} |
||||
|
||||
/** |
||||
* check if the parent folder exists otherwise move the mount point up |
||||
*/ |
||||
private static function verifyMountPoint(&$share) { |
||||
|
||||
$mountPoint = basename($share['file_target']); |
||||
$parent = dirname($share['file_target']); |
||||
|
||||
while (!\OC\Files\Filesystem::is_dir($parent)) { |
||||
$parent = dirname($parent); |
||||
} |
||||
|
||||
$newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget( |
||||
\OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
||||
array(), |
||||
new \OC\Files\View('/' . \OCP\User::getUser() . '/files') |
||||
); |
||||
|
||||
if($newMountPoint !== $share['file_target']) { |
||||
self::updateFileTarget($newMountPoint, $share); |
||||
$share['file_target'] = $newMountPoint; |
||||
$share['unique_name'] = true; |
||||
} |
||||
|
||||
return $newMountPoint; |
||||
} |
||||
|
||||
/** |
||||
* update fileTarget in the database if the mount point changed |
||||
* @param string $newPath |
||||
* @param array $share reference to the share which should be modified |
||||
* @return type |
||||
*/ |
||||
private static function updateFileTarget($newPath, &$share) { |
||||
// if the user renames a mount point from a group share we need to create a new db entry |
||||
// for the unique name |
||||
if ($share['share_type'] === \OCP\Share::SHARE_TYPE_GROUP && empty($share['unique_name'])) { |
||||
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`,' |
||||
.' `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`,' |
||||
.' `file_target`, `token`, `parent`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)'); |
||||
$arguments = array($share['item_type'], $share['item_source'], $share['item_target'], |
||||
2, \OCP\User::getUser(), $share['uid_owner'], $share['permissions'], $share['stime'], $share['file_source'], |
||||
$newPath, $share['token'], $share['id']); |
||||
} else { |
||||
// rename mount point |
||||
$query = \OC_DB::prepare( |
||||
'Update `*PREFIX*share` |
||||
SET `file_target` = ? |
||||
WHERE `id` = ?' |
||||
); |
||||
$arguments = array($newPath, $share['id']); |
||||
} |
||||
|
||||
$result = $query->execute($arguments); |
||||
|
||||
return $result === 1 ? true : false; |
||||
} |
||||
|
||||
/** |
||||
* Format a path to be relative to the /user/files/ directory |
||||
* |
||||
* @param string $path the absolute path |
||||
* @return string e.g. turns '/admin/files/test.txt' into '/test.txt' |
||||
*/ |
||||
private function stripUserFilesPath($path) { |
||||
$trimmed = ltrim($path, '/'); |
||||
$split = explode('/', $trimmed); |
||||
|
||||
// it is not a file relative to data/user/files |
||||
if (count($split) < 3 || $split[1] !== 'files') { |
||||
\OCP\Util::writeLog('file sharing', |
||||
'Can not strip userid and "files/" from path: ' . $path, |
||||
\OCP\Util::DEBUG); |
||||
return false; |
||||
} |
||||
|
||||
// skip 'user' and 'files' |
||||
$sliced = array_slice($split, 2); |
||||
$relPath = implode('/', $sliced); |
||||
|
||||
return '/' . $relPath; |
||||
} |
||||
|
||||
/** |
||||
* Move the mount point to $target |
||||
* |
||||
* @param string $target the target mount point |
||||
* @return bool |
||||
*/ |
||||
public function moveMount($target) { |
||||
// it shouldn't be possible to move a Shared storage into another one |
||||
list($targetStorage,) = Filesystem::resolvePath($target); |
||||
if ($targetStorage instanceof Shared) { |
||||
\OCP\Util::writeLog('file sharing', |
||||
'It is not allowed to move one mount point into another one', |
||||
\OCP\Util::DEBUG); |
||||
return false; |
||||
} |
||||
|
||||
$relTargetPath = $this->stripUserFilesPath($target); |
||||
$share = $this->storage->getShare(); |
||||
|
||||
$result = $this->updateFileTarget($relTargetPath, $share); |
||||
|
||||
if ($result) { |
||||
$this->setMountPoint($target); |
||||
$this->storage->setUniqueName(); |
||||
$this->storage->setMountPoint($relTargetPath); |
||||
|
||||
} else { |
||||
\OCP\Util::writeLog('file sharing', |
||||
'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"', |
||||
\OCP\Util::ERROR); |
||||
} |
||||
|
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* Remove the mount points |
||||
* |
||||
* @return bool |
||||
*/ |
||||
public function removeMount() { |
||||
$storage = $this->getStorage(); |
||||
$result = \OCP\Share::unshareFromSelf($storage->getItemType(), $storage->getMountPoint()); |
||||
|
||||
return $result; |
||||
} |
||||
} |
@ -0,0 +1,173 @@ |
||||
<?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'; |
||||
|
||||
use OCA\Files\Share; |
||||
|
||||
/** |
||||
* Class Test_Files_Sharing |
||||
*/ |
||||
class Test_Files_Sharing extends Test_Files_Sharing_Base { |
||||
|
||||
const TEST_FOLDER_NAME = '/folder_share_api_test'; |
||||
|
||||
private static $tempStorage; |
||||
|
||||
function setUp() { |
||||
parent::setUp(); |
||||
|
||||
$this->folder = self::TEST_FOLDER_NAME; |
||||
$this->subfolder = '/subfolder_share_api_test'; |
||||
$this->subsubfolder = '/subsubfolder_share_api_test'; |
||||
|
||||
$this->filename = '/share-api-test.txt'; |
||||
|
||||
// save file with content |
||||
$this->view->file_put_contents($this->filename, $this->data); |
||||
$this->view->mkdir($this->folder); |
||||
$this->view->mkdir($this->folder . $this->subfolder); |
||||
$this->view->mkdir($this->folder . $this->subfolder . $this->subsubfolder); |
||||
$this->view->file_put_contents($this->folder.$this->filename, $this->data); |
||||
$this->view->file_put_contents($this->folder . $this->subfolder . $this->filename, $this->data); |
||||
} |
||||
|
||||
function tearDown() { |
||||
$this->view->unlink($this->filename); |
||||
$this->view->deleteAll($this->folder); |
||||
|
||||
self::$tempStorage = null; |
||||
|
||||
parent::tearDown(); |
||||
} |
||||
|
||||
function testUnshareFromSelf() { |
||||
|
||||
\OC_Group::createGroup('testGroup'); |
||||
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup'); |
||||
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup'); |
||||
|
||||
$fileinfo = $this->view->getFileInfo($this->filename); |
||||
|
||||
$pathinfo = pathinfo($this->filename); |
||||
|
||||
$duplicate = '/' . $pathinfo['filename'] . ' (2).' . $pathinfo['extension']; |
||||
|
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, |
||||
\Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, 31); |
||||
|
||||
$this->assertTrue($result); |
||||
|
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, |
||||
'testGroup', 31); |
||||
|
||||
$this->assertTrue($result); |
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); |
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename)); |
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($duplicate)); |
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER3); |
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename)); |
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists($duplicate)); |
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); |
||||
\OC\Files\Filesystem::unlink($this->filename); |
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); |
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename)); |
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($duplicate)); |
||||
|
||||
// for user3 nothing should change |
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER3); |
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename)); |
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists($duplicate)); |
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); |
||||
\OC\Files\Filesystem::unlink($duplicate); |
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); |
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename)); |
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists($duplicate)); |
||||
|
||||
// for user3 nothing should change |
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER3); |
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename)); |
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists($duplicate)); |
||||
|
||||
//cleanup |
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); |
||||
\OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, |
||||
'testGroup'); |
||||
\OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, |
||||
self::TEST_FILES_SHARING_API_USER2); |
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup'); |
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup'); |
||||
\OC_Group::deleteGroup('testGroup'); |
||||
|
||||
|
||||
} |
||||
|
||||
/** |
||||
* shared files should never have delete permissions |
||||
* @dataProvider DataProviderTestFileSharePermissions |
||||
*/ |
||||
function testFileSharePermissions($permission, $expectedPermissions) { |
||||
|
||||
$fileinfo = $this->view->getFileInfo($this->filename); |
||||
|
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, |
||||
\Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, $permission); |
||||
|
||||
$this->assertTrue($result); |
||||
|
||||
$result = \OCP\Share::getItemShared('file', null); |
||||
|
||||
$this->assertTrue(is_array($result)); |
||||
|
||||
// test should return exactly one shares created from testCreateShare() |
||||
$this->assertTrue(count($result) === 1); |
||||
|
||||
$share = reset($result); |
||||
$this->assertSame($expectedPermissions, $share['permissions']); |
||||
|
||||
\OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, |
||||
\Test_Files_Sharing::TEST_FILES_SHARING_API_USER2); |
||||
} |
||||
|
||||
function DataProviderTestFileSharePermissions() { |
||||
$permission1 = \OCP\PERMISSION_ALL; |
||||
$permission2 = \OCP\PERMISSION_DELETE; |
||||
$permission3 = \OCP\PERMISSION_READ; |
||||
$permission4 = \OCP\PERMISSION_READ | \OCP\PERMISSION_UPDATE; |
||||
$permission5 = \OCP\PERMISSION_READ | \OCP\PERMISSION_DELETE; |
||||
$permission6 = \OCP\PERMISSION_READ | \OCP\PERMISSION_UPDATE | \OCP\PERMISSION_DELETE; |
||||
|
||||
return array( |
||||
array($permission1, \OCP\PERMISSION_ALL & ~\OCP\PERMISSION_DELETE), |
||||
array($permission2, 0), |
||||
array($permission3, $permission3), |
||||
array($permission4, $permission4), |
||||
array($permission5, $permission3), |
||||
array($permission6, $permission4), |
||||
); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,197 @@ |
||||
<?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_Api |
||||
*/ |
||||
class Test_Files_Sharing_Mount extends Test_Files_Sharing_Base { |
||||
|
||||
function setUp() { |
||||
parent::setUp(); |
||||
|
||||
$this->folder = '/folder_share_storage_test'; |
||||
|
||||
$this->filename = '/share-api-storage.txt'; |
||||
|
||||
|
||||
$this->view->mkdir($this->folder); |
||||
|
||||
// save file with content |
||||
$this->view->file_put_contents($this->filename, "root file"); |
||||
$this->view->file_put_contents($this->folder . $this->filename, "file in subfolder"); |
||||
} |
||||
|
||||
function tearDown() { |
||||
$this->view->unlink($this->folder); |
||||
$this->view->unlink($this->filename); |
||||
|
||||
parent::tearDown(); |
||||
} |
||||
|
||||
/** |
||||
* test if the mount point moves up if the parent folder no longer exists |
||||
*/ |
||||
function testShareMountLoseParentFolder() { |
||||
|
||||
// share to user |
||||
$fileinfo = $this->view->getFileInfo($this->folder); |
||||
$result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, |
||||
self::TEST_FILES_SHARING_API_USER2, 31); |
||||
|
||||
$statement = "UPDATE `*PREFIX*share` SET `file_target` = ? where `share_with` = ?"; |
||||
$query = \OC_DB::prepare($statement); |
||||
$arguments = array('/foo/bar' . $this->folder, self::TEST_FILES_SHARING_API_USER2); |
||||
$query->execute($arguments); |
||||
|
||||
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`'); |
||||
$result = $query->execute(); |
||||
|
||||
$shares = $result->fetchAll(); |
||||
|
||||
$this->assertSame(1, count($shares)); |
||||
|
||||
$share = reset($shares); |
||||
$this->assertSame('/foo/bar' . $this->folder, $share['file_target']); |
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); |
||||
|
||||
// share should have moved up |
||||
|
||||
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`'); |
||||
$result = $query->execute(); |
||||
|
||||
$shares = $result->fetchAll(); |
||||
|
||||
$this->assertSame(1, count($shares)); |
||||
|
||||
$share = reset($shares); |
||||
$this->assertSame($this->folder, $share['file_target']); |
||||
|
||||
//cleanup |
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); |
||||
\OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2); |
||||
$this->view->unlink($this->folder); |
||||
} |
||||
|
||||
/** |
||||
* @medium |
||||
*/ |
||||
function testDeleteParentOfMountPoint() { |
||||
|
||||
// share to user |
||||
$fileinfo = $this->view->getFileInfo($this->folder); |
||||
$result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, |
||||
self::TEST_FILES_SHARING_API_USER2, 31); |
||||
|
||||
$this->assertTrue($result); |
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); |
||||
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); |
||||
$this->assertTrue($user2View->file_exists($this->folder)); |
||||
|
||||
// create a local folder |
||||
$result = $user2View->mkdir('localfolder'); |
||||
$this->assertTrue($result); |
||||
|
||||
// move mount point to local folder |
||||
$result = $user2View->rename($this->folder, '/localfolder/' . $this->folder); |
||||
$this->assertTrue($result); |
||||
|
||||
// mount point in the root folder should no longer exist |
||||
$this->assertFalse($user2View->is_dir($this->folder)); |
||||
|
||||
// delete the local folder |
||||
$result = $user2View->unlink('/localfolder'); |
||||
$this->assertTrue($result); |
||||
|
||||
//enforce reload of the mount points |
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); |
||||
|
||||
//mount point should be back at the root |
||||
$this->assertTrue($user2View->is_dir($this->folder)); |
||||
|
||||
//cleanup |
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); |
||||
$this->view->unlink($this->folder); |
||||
} |
||||
|
||||
function testMoveSharedFile() { |
||||
$fileinfo = $this->view->getFileInfo($this->filename); |
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, |
||||
self::TEST_FILES_SHARING_API_USER2, 31); |
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); |
||||
|
||||
\OC\Files\Filesystem::rename($this->filename, "newFileName"); |
||||
|
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists('newFileName')); |
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename)); |
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); |
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename)); |
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists("newFileName")); |
||||
|
||||
//cleanup |
||||
\OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2); |
||||
} |
||||
|
||||
/** |
||||
* share file with a group if a user renames the file the filename should not change |
||||
* for the other users |
||||
*/ |
||||
function testMoveGroupShare () { |
||||
\OC_Group::createGroup('testGroup'); |
||||
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup'); |
||||
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup'); |
||||
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup'); |
||||
|
||||
$fileinfo = $this->view->getFileInfo($this->filename); |
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, |
||||
"testGroup", 31); |
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); |
||||
|
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename)); |
||||
|
||||
\OC\Files\Filesystem::rename($this->filename, "newFileName"); |
||||
|
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists('newFileName')); |
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename)); |
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER3); |
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename)); |
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists("newFileName")); |
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER3); |
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename)); |
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists("newFileName")); |
||||
|
||||
//cleanup |
||||
\OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup'); |
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup'); |
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup'); |
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup'); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,233 @@ |
||||
<?php |
||||
/** |
||||
* ownCloud |
||||
* |
||||
* @author Morris Jobke, Bjoern Schiessle |
||||
* @copyright 2014 Morris Jobke <morris.jobke@gmail.com> |
||||
* 2014 Bjoern Schiessle <schiessle@ownlcoud.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__ . '/../appinfo/update.php'; |
||||
require_once __DIR__ . '/base.php'; |
||||
|
||||
/** |
||||
* Class Test_Files_Sharing_Update |
||||
*/ |
||||
class Test_Files_Sharing_Update_Routine extends Test_Files_Sharing_Base { |
||||
|
||||
const TEST_FOLDER_NAME = '/folder_share_api_test'; |
||||
|
||||
function setUp() { |
||||
parent::setUp(); |
||||
|
||||
$this->folder = self::TEST_FOLDER_NAME; |
||||
|
||||
$this->filename = '/share-api-test.txt'; |
||||
|
||||
// save file with content |
||||
$this->view->file_put_contents($this->filename, $this->data); |
||||
$this->view->mkdir($this->folder); |
||||
$this->view->file_put_contents($this->folder . '/' . $this->filename, $this->data); |
||||
} |
||||
|
||||
function tearDown() { |
||||
$this->view->unlink($this->filename); |
||||
$this->view->deleteAll($this->folder); |
||||
|
||||
$removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share`'); |
||||
$removeShares->execute(); |
||||
$removeItems = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache`'); |
||||
$removeItems->execute(); |
||||
|
||||
parent::tearDown(); |
||||
} |
||||
|
||||
/** |
||||
* test update of file permission. The update should remove from all shared |
||||
* files the delete permission |
||||
*/ |
||||
function testUpdateFilePermissions() { |
||||
|
||||
self::prepareDBUpdateFilePermissions(); |
||||
// run the update routine to update the share permission |
||||
updateFilePermissions(2); |
||||
|
||||
// verify results |
||||
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`'); |
||||
$result = $query->execute(array()); |
||||
|
||||
while ($row = $result->fetchRow()) { |
||||
if ($row['item_type'] === 'file') { |
||||
// for all files the delete permission should be removed |
||||
$this->assertSame(0, (int)$row['permissions'] & \OCP\PERMISSION_DELETE); |
||||
} else { |
||||
// for all other the permission shouldn't change |
||||
$this->assertSame(31, (int)$row['permissions'] & \OCP\PERMISSION_ALL); |
||||
} |
||||
} |
||||
|
||||
// cleanup |
||||
$this->cleanupSharedTable(); |
||||
} |
||||
|
||||
/** |
||||
* @medium |
||||
*/ |
||||
function testRemoveBrokenShares() { |
||||
|
||||
$this->prepareFileCache(); |
||||
|
||||
// check if there are just 3 shares (see setUp - precondition: empty table) |
||||
$countShares = \OC_DB::prepare('SELECT COUNT(`id`) FROM `*PREFIX*share`'); |
||||
$result = $countShares->execute()->fetchOne(); |
||||
$this->assertEquals(3, $result); |
||||
|
||||
// check if there are just 2 items (see setUp - precondition: empty table) |
||||
$countItems = \OC_DB::prepare('SELECT COUNT(`fileid`) FROM `*PREFIX*filecache`'); |
||||
$result = $countItems->execute()->fetchOne(); |
||||
$this->assertEquals(2, $result); |
||||
|
||||
// execute actual code which should be tested |
||||
\OC\Files\Cache\Shared_Updater::fixBrokenSharesOnAppUpdate(); |
||||
|
||||
// check if there are just 2 shares (one gets killed by the code as there is no filecache entry for this) |
||||
$countShares = \OC_DB::prepare('SELECT COUNT(`id`) FROM `*PREFIX*share`'); |
||||
$result = $countShares->execute()->fetchOne(); |
||||
$this->assertEquals(2, $result); |
||||
|
||||
// check if the share of file '200' is removed as there is no entry for this in filecache table |
||||
$countShares = \OC_DB::prepare('SELECT COUNT(`id`) FROM `*PREFIX*share` WHERE `file_source` = 200'); |
||||
$result = $countShares->execute()->fetchOne(); |
||||
$this->assertEquals(0, $result); |
||||
|
||||
// check if there are just 2 items |
||||
$countItems = \OC_DB::prepare('SELECT COUNT(`fileid`) FROM `*PREFIX*filecache`'); |
||||
$result = $countItems->execute()->fetchOne(); |
||||
$this->assertEquals(2, $result); |
||||
} |
||||
|
||||
/** |
||||
* test update for the removal of the logical "Shared" folder. It should update |
||||
* the file_target for every share and create a physical "Shared" folder for each user |
||||
*/ |
||||
function testRemoveSharedFolder() { |
||||
self::prepareDB(); |
||||
// run the update routine to remove the shared folder and replace it with a real folder |
||||
removeSharedFolder(false, 2); |
||||
|
||||
// verify results |
||||
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`'); |
||||
$result = $query->execute(array()); |
||||
|
||||
$newDBContent = $result->fetchAll(); |
||||
|
||||
foreach ($newDBContent as $row) { |
||||
if ((int)$row['share_type'] === \OCP\Share::SHARE_TYPE_USER) { |
||||
$this->assertSame('/Shared', substr($row['file_target'], 0, strlen('/Shared'))); |
||||
} else { |
||||
$this->assertSame('/ShouldNotChange', $row['file_target']); |
||||
} |
||||
} |
||||
|
||||
// cleanup |
||||
$this->cleanupSharedTable(); |
||||
|
||||
} |
||||
|
||||
private function cleanupSharedTable() { |
||||
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*share`'); |
||||
$query->execute(); |
||||
} |
||||
|
||||
/** |
||||
* prepare sharing table for testRemoveSharedFolder() |
||||
*/ |
||||
private function prepareDB() { |
||||
$this->cleanupSharedTable(); |
||||
// add items except one - because this is the test case for the broken share table |
||||
$addItems = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`share_type`, `item_type`, ' . |
||||
'`share_with`, `uid_owner` , `file_target`) ' . |
||||
'VALUES (?, ?, ?, ?, ?)'); |
||||
$items = array( |
||||
array(\OCP\Share::SHARE_TYPE_USER, 'file', 'user1', 'admin' , '/foo'), |
||||
array(\OCP\Share::SHARE_TYPE_USER, 'folder', 'user2', 'admin', '/foo2'), |
||||
array(\OCP\Share::SHARE_TYPE_USER, 'file', 'user3', 'admin', '/foo3'), |
||||
array(\OCP\Share::SHARE_TYPE_USER, 'folder', 'user4', 'admin', '/foo4'), |
||||
array(\OCP\Share::SHARE_TYPE_LINK, 'file', 'user1', 'admin', '/ShouldNotChange'), |
||||
array(\OCP\Share::SHARE_TYPE_CONTACT, 'contact', 'admin', 'user1', '/ShouldNotChange'), |
||||
|
||||
); |
||||
foreach($items as $item) { |
||||
// the number is used as path_hash |
||||
$addItems->execute($item); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* prepare sharing table for testUpdateFilePermissions() |
||||
*/ |
||||
private function prepareDBUpdateFilePermissions() { |
||||
$this->cleanupSharedTable(); |
||||
// add items except one - because this is the test case for the broken share table |
||||
$addItems = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`share_type`, `item_type`, ' . |
||||
'`share_with`, `uid_owner` , `file_target`, `permissions`) ' . |
||||
'VALUES (?, ?, ?, ?, ?, ?)'); |
||||
$items = array( |
||||
array(\OCP\Share::SHARE_TYPE_LINK, 'file', 'user1', 'admin', '/foo', \OCP\PERMISSION_ALL), |
||||
array(\OCP\Share::SHARE_TYPE_CONTACT, 'contact', 'admin', 'user1', '/foo', \OCP\PERMISSION_ALL), |
||||
array(\OCP\Share::SHARE_TYPE_USER, 'folder', 'user4', 'admin', '/foo', \OCP\PERMISSION_ALL), |
||||
array(\OCP\Share::SHARE_TYPE_USER, 'file', 'user3', 'admin', '/foo3', \OCP\PERMISSION_ALL), |
||||
array(\OCP\Share::SHARE_TYPE_USER, 'file', 'user1', 'admin' , '/foo', \OCP\PERMISSION_DELETE), |
||||
array(\OCP\Share::SHARE_TYPE_USER, 'file', 'user1', 'admin' , '/foo', \OCP\PERMISSION_READ & \OCP\PERMISSION_DELETE), |
||||
array(\OCP\Share::SHARE_TYPE_USER, 'file', 'user1', 'admin' , '/foo', \OCP\PERMISSION_SHARE & \OCP\PERMISSION_UPDATE), |
||||
array(\OCP\Share::SHARE_TYPE_USER, 'file', 'user1', 'admin' , '/foo', \OCP\PERMISSION_ALL), |
||||
array(\OCP\Share::SHARE_TYPE_USER, 'file', 'user1', 'admin' , '/foo', \OCP\PERMISSION_SHARE & \OCP\PERMISSION_READ & \OCP\PERMISSION_DELETE), |
||||
); |
||||
foreach($items as $item) { |
||||
// the number is used as path_hash |
||||
$addItems->execute($item); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* prepare file cache for testRemoveBrokenShares() |
||||
*/ |
||||
private function prepareFileCache() { |
||||
// some previous tests didn't clean up and therefore this has to be done here |
||||
// FIXME: DIRTY HACK - TODO: find tests, that don't clean up and fix it there |
||||
$this->tearDown(); |
||||
|
||||
// add items except one - because this is the test case for the broken share table |
||||
$addItems = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache` (`storage`, `path_hash`, ' . |
||||
'`parent`, `mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`) ' . |
||||
'VALUES (1, ?, 1, 1, 1, 1, 1, 1)'); |
||||
$items = array(1, 3); |
||||
$fileIds = array(); |
||||
foreach($items as $item) { |
||||
// the number is used as path_hash |
||||
$addItems->execute(array($item)); |
||||
$fileIds[] = \OC_DB::insertId('*PREFIX*filecache'); |
||||
} |
||||
|
||||
$addShares = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`file_source`, `item_type`, `uid_owner`) VALUES (?, \'file\', 1)'); |
||||
// the number is used as item_source |
||||
$addShares->execute(array($fileIds[0])); |
||||
$addShares->execute(array(200)); // id of "deleted" file |
||||
$addShares->execute(array($fileIds[1])); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,30 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OC\Files\Mount; |
||||
|
||||
/** |
||||
* Defines the mount point to be (re)moved by the user |
||||
*/ |
||||
interface MoveableMount { |
||||
/** |
||||
* Move the mount point to $target |
||||
* |
||||
* @param string $target the target mount point |
||||
* @return bool |
||||
*/ |
||||
public function moveMount($target); |
||||
|
||||
/** |
||||
* Remove the mount points |
||||
* |
||||
* @return mixed |
||||
* @return bool |
||||
*/ |
||||
public function removeMount(); |
||||
} |
Loading…
Reference in new issue