diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-10-05 16:18:14 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-10-05 16:18:14 +0200 |
commit | 76a528e5112698afec67eb6fce43e2ba809972ac (patch) | |
tree | 0bb77e04b77462d2041657255331149b22086773 /apps/files_sharing | |
parent | cab0be6eedef14c419a2c94dce0461418e5f9cf8 (diff) | |
download | nextcloud-server-76a528e5112698afec67eb6fce43e2ba809972ac.tar.gz nextcloud-server-76a528e5112698afec67eb6fce43e2ba809972ac.zip |
Make the external share manager a mount provider
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/lib/external/manager.php | 61 | ||||
-rw-r--r-- | apps/files_sharing/lib/helper.php | 1 | ||||
-rw-r--r-- | apps/files_sharing/tests/external/managertest.php | 28 |
3 files changed, 44 insertions, 46 deletions
diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index 2ba02f40d2f..662e70d1237 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -28,9 +28,12 @@ namespace OCA\Files_Sharing\External; use OC\Files\Filesystem; use OCP\Files; +use OCP\Files\Config\IMountProvider; +use OCP\Files\Storage\IStorageFactory; use OC\Notification\IManager; +use OCP\IUser; -class Manager { +class Manager implements IMountProvider { const STORAGE = '\OCA\Files_Sharing\External\Storage'; /** @@ -152,26 +155,20 @@ class Manager { return $this->mountShare($options); } - private function setupMounts() { - // don't setup server-to-server shares if the admin disabled it - if (\OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled() === false) { - return false; - } - - if (!is_null($this->uid)) { - $query = $this->connection->prepare(' + public function getMountsForUser(IUser $user, IStorageFactory $loader) { + $query = $this->connection->prepare(' SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner` FROM `*PREFIX*share_external` WHERE `user` = ? AND `accepted` = ? '); - $query->execute(array($this->uid, 1)); - - while ($row = $query->fetch()) { - $row['manager'] = $this; - $row['token'] = $row['share_token']; - $this->mountShare($row); - } + $query->execute([$user->getUID(), 1]); + $mounts = []; + while ($row = $query->fetch()) { + $row['manager'] = $this; + $row['token'] = $row['share_token']; + $mounts[] = $this->getMount($row, $loader); } + return $mounts; } /** @@ -276,24 +273,6 @@ class Manager { } /** - * setup the server-to-server mounts - * - * @param array $params - */ - public static function setup(array $params) { - $externalManager = new \OCA\Files_Sharing\External\Manager( - \OC::$server->getDatabaseConnection(), - \OC\Files\Filesystem::getMountManager(), - \OC\Files\Filesystem::getLoader(), - \OC::$server->getHTTPHelper(), - \OC::$server->getNotificationManager(), - $params['user'] - ); - - $externalManager->setupMounts(); - } - - /** * remove '/user/files' from the path and trailing slashes * * @param string $path @@ -304,16 +283,20 @@ class Manager { return rtrim(substr($path, strlen($prefix)), '/'); } + protected function getMount($data, IStorageFactory $storageFactory) { + $data['manager'] = $this; + $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; + $data['mountpoint'] = $mountPoint; + $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); + return new Mount(self::STORAGE, $mountPoint, $data, $this, $storageFactory); + } + /** * @param array $data * @return Mount */ protected function mountShare($data) { - $data['manager'] = $this; - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; - $data['mountpoint'] = $mountPoint; - $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); - $mount = new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); + $mount = $this->getMount($data, $this->storageLoader); $this->mountManager->addMount($mount); return $mount; } diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php index 38cb73be29c..2d92cac6c94 100644 --- a/apps/files_sharing/lib/helper.php +++ b/apps/files_sharing/lib/helper.php @@ -30,7 +30,6 @@ namespace OCA\Files_Sharing; class Helper { public static function registerHooks() { - \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OCA\Files_Sharing\External\Manager', 'setup'); \OCP\Util::connectHook('OC_Filesystem', 'delete', '\OC\Files\Cache\Shared_Updater', 'deleteHook'); \OCP\Util::connectHook('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Shared_Updater', 'renameHook'); \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren'); diff --git a/apps/files_sharing/tests/external/managertest.php b/apps/files_sharing/tests/external/managertest.php index 8e03c67a9a3..2d31b163064 100644 --- a/apps/files_sharing/tests/external/managertest.php +++ b/apps/files_sharing/tests/external/managertest.php @@ -24,8 +24,10 @@ namespace OCA\Files_Sharing\Tests\External; use OC\Files\Storage\StorageFactory; use OCA\Files_Sharing\External\Manager; use OCA\Files_Sharing\Tests\TestCase; +use Test\Traits\UserTrait; class ManagerTest extends TestCase { + use UserTrait; /** @var Manager **/ private $manager; @@ -38,10 +40,17 @@ class ManagerTest extends TestCase { private $uid; + /** + * @var \OCP\IUser + */ + private $user; + protected function setUp() { parent::setUp(); $this->uid = $this->getUniqueID('user'); + $this->createUser($this->uid, ''); + $this->user = \OC::$server->getUserManager()->get($this->uid); $this->mountManager = new \OC\Files\Mount\Manager(); $this->httpHelper = $httpHelper = $this->getMockBuilder('\OC\HTTPHelper')->disableOriginalConstructor()->getMock(); /** @var \OC\HTTPHelper $httpHelper */ @@ -55,6 +64,13 @@ class ManagerTest extends TestCase { ); } + private function setupMounts() { + $mounts = $this->manager->getMountsForUser($this->user, new StorageFactory()); + foreach ($mounts as $mount) { + $this->mountManager->addMount($mount); + } + } + public function testAddShare() { $shareData1 = [ @@ -77,7 +93,7 @@ class ManagerTest extends TestCase { $this->assertCount(1, $openShares); $this->assertExternalShareEntry($shareData1, $openShares[0], 1, '{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); - self::invokePrivate($this->manager, 'setupMounts'); + $this->setupMounts(); $this->assertNotMount('SharedFolder'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); @@ -89,7 +105,7 @@ class ManagerTest extends TestCase { // New share falls back to "-1" appendix, because the name is already taken $this->assertExternalShareEntry($shareData2, $openShares[1], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1'); - self::invokePrivate($this->manager, 'setupMounts'); + $this->setupMounts(); $this->assertNotMount('SharedFolder'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); @@ -111,7 +127,7 @@ class ManagerTest extends TestCase { $this->assertCount(1, $openShares); $this->assertExternalShareEntry($shareData2, $openShares[0], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1'); - self::invokePrivate($this->manager, 'setupMounts'); + $this->setupMounts(); $this->assertMount($shareData1['name']); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); @@ -124,7 +140,7 @@ class ManagerTest extends TestCase { // New share falls back to the original name (no "-\d", because the name is not taken) $this->assertExternalShareEntry($shareData3, $openShares[1], 3, '{{TemporaryMountPointName#' . $shareData3['name'] . '}}'); - self::invokePrivate($this->manager, 'setupMounts'); + $this->setupMounts(); $this->assertMount($shareData1['name']); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); @@ -136,7 +152,7 @@ class ManagerTest extends TestCase { // Decline the third share $this->manager->declineShare($openShares[1]['id']); - self::invokePrivate($this->manager, 'setupMounts'); + $this->setupMounts(); $this->assertMount($shareData1['name']); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); @@ -151,7 +167,7 @@ class ManagerTest extends TestCase { $this->assertCount(1, $openShares); $this->assertExternalShareEntry($shareData2, $openShares[0], 2, '{{TemporaryMountPointName#' . $shareData2['name'] . '}}-1'); - self::invokePrivate($this->manager, 'setupMounts'); + $this->setupMounts(); $this->assertMount($shareData1['name']); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}'); $this->assertNotMount('{{TemporaryMountPointName#' . $shareData1['name'] . '}}-1'); |