diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-01-26 19:54:14 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-01-26 19:54:14 +0100 |
commit | bd888748bd9d0d9e9268447501fe35abf121083b (patch) | |
tree | e22d3e68a9617f6d30e6a3037144a750a26363fb /apps/files_sharing | |
parent | 44d69d71780d94ab89f81e54ebf9ec23a5b04316 (diff) | |
parent | 5ba19ba7fcda12e21fe37e8686218122936c9a68 (diff) | |
download | nextcloud-server-bd888748bd9d0d9e9268447501fe35abf121083b.tar.gz nextcloud-server-bd888748bd9d0d9e9268447501fe35abf121083b.zip |
Merge pull request #13490 from owncloud/fix_reshare_s2s_share
use uid provided by setupfs hook to mount server2server shares
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/ajax/external.php | 4 | ||||
-rw-r--r-- | apps/files_sharing/api/server2server.php | 5 | ||||
-rw-r--r-- | apps/files_sharing/application.php | 6 | ||||
-rw-r--r-- | apps/files_sharing/lib/controllers/sharecontroller.php | 1 | ||||
-rw-r--r-- | apps/files_sharing/lib/external/manager.php | 78 | ||||
-rw-r--r-- | apps/files_sharing/lib/hooks.php | 4 | ||||
-rw-r--r-- | apps/files_sharing/tests/server2server.php | 5 |
7 files changed, 64 insertions, 39 deletions
diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php index 1a709eda07c..a206cacafa3 100644 --- a/apps/files_sharing/ajax/external.php +++ b/apps/files_sharing/ajax/external.php @@ -34,8 +34,8 @@ $externalManager = new \OCA\Files_Sharing\External\Manager( \OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), - \OC::$server->getUserSession(), - \OC::$server->getHTTPHelper() + \OC::$server->getHTTPHelper(), + \OC::$server->getUserSession()->getUser()->getUID() ); $name = OCP\Files::buildNotExistingFileName('/', $name); diff --git a/apps/files_sharing/api/server2server.php b/apps/files_sharing/api/server2server.php index f78d64caa73..7dce0df7d83 100644 --- a/apps/files_sharing/api/server2server.php +++ b/apps/files_sharing/api/server2server.php @@ -60,8 +60,9 @@ class Server2Server { \OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), - \OC::$server->getUserSession(), - \OC::$server->getHTTPHelper()); + \OC::$server->getHTTPHelper(), + $shareWith + ); $name = \OCP\Files::buildNotExistingFileName('/', $name); diff --git a/apps/files_sharing/application.php b/apps/files_sharing/application.php index 56ec448d6a9..3302848106f 100644 --- a/apps/files_sharing/application.php +++ b/apps/files_sharing/application.php @@ -69,12 +69,14 @@ class Application extends App { return Helper::isIncomingServer2serverShareEnabled(); }); $container->registerService('ExternalManager', function(SimpleContainer $c) use ($server){ + $user = $server->getUserSession()->getUser(); + $uid = $user ? $user->getUID() : null; return new \OCA\Files_Sharing\External\Manager( $server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), - $server->getUserSession(), - $server->getHTTPHelper() + $server->getHTTPHelper(), + $uid ); }); diff --git a/apps/files_sharing/lib/controllers/sharecontroller.php b/apps/files_sharing/lib/controllers/sharecontroller.php index 1d8eabc1984..cd013d4ca96 100644 --- a/apps/files_sharing/lib/controllers/sharecontroller.php +++ b/apps/files_sharing/lib/controllers/sharecontroller.php @@ -142,7 +142,6 @@ class ShareController extends Controller { return new TemplateResponse('core', '404', array(), 'guest'); } - $linkItem = OCP\Share::getShareByToken($token, false); $shareOwner = $linkItem['uid_owner']; $originalSharePath = null; $rootLinkItem = OCP\Share::resolveReShare($linkItem); diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index 57dc38a9954..8985aeb3fce 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -14,6 +14,11 @@ class Manager { const STORAGE = '\OCA\Files_Sharing\External\Storage'; /** + * @var string + */ + private $uid; + + /** * @var \OCP\IDBConnection */ private $connection; @@ -29,11 +34,6 @@ class Manager { private $storageLoader; /** - * @var \OC\User\Session - */ - private $userSession; - - /** * @var \OC\HTTPHelper */ private $httpHelper; @@ -41,21 +41,35 @@ class Manager { /** * @param \OCP\IDBConnection $connection * @param \OC\Files\Mount\Manager $mountManager - * @param \OC\User\Session $userSession * @param \OC\Files\Storage\StorageFactory $storageLoader + * @param \OC\HTTPHelper $httpHelper + * @param string $uid */ public function __construct(\OCP\IDBConnection $connection, \OC\Files\Mount\Manager $mountManager, - \OC\Files\Storage\StorageFactory $storageLoader, \OC\User\Session $userSession, \OC\HTTPHelper $httpHelper) { + \OC\Files\Storage\StorageFactory $storageLoader, \OC\HTTPHelper $httpHelper, $uid) { $this->connection = $connection; $this->mountManager = $mountManager; - $this->userSession = $userSession; $this->storageLoader = $storageLoader; $this->httpHelper = $httpHelper; + $this->uid = $uid; } + /** + * add new server-to-server share + * + * @param string $remote + * @param string $token + * @param string $password + * @param string $name + * @param string $owner + * @param boolean $accepted + * @param string $user + * @param int $remoteId + * @return mixed + */ public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) { - $user = $user ? $user: $this->userSession->getUser()->getUID(); + $user = $user ? $user : $this->uid; $accepted = $accepted ? 1 : 0; $mountPoint = Filesystem::normalizePath('/' . $name); @@ -86,14 +100,13 @@ class Manager { return false; } - $user = $this->userSession->getUser(); - if ($user) { + if (!is_null($this->uid)) { $query = $this->connection->prepare(' SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner` FROM `*PREFIX*share_external` WHERE `user` = ? AND `accepted` = ? '); - $query->execute(array($user->getUID(), 1)); + $query->execute(array($this->uid, 1)); while ($row = $query->fetch()) { $row['manager'] = $this; @@ -114,7 +127,7 @@ class Manager { SELECT `remote`, `share_token` FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); - $result = $getShare->execute(array($id, $this->userSession->getUser()->getUID())); + $result = $getShare->execute(array($id, $this->uid)); return $result ? $getShare->fetch() : false; } @@ -133,7 +146,7 @@ class Manager { UPDATE `*PREFIX*share_external` SET `accepted` = ? WHERE `id` = ? AND `user` = ?'); - $acceptShare->execute(array(1, $id, $this->userSession->getUser()->getUID())); + $acceptShare->execute(array(1, $id, $this->uid)); $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $id, 'accept'); } } @@ -150,7 +163,7 @@ class Manager { if ($share) { $removeShare = $this->connection->prepare(' DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); - $removeShare->execute(array($id, $this->userSession->getUser()->getUID())); + $removeShare->execute(array($id, $this->uid)); $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $id, 'decline'); } } @@ -175,19 +188,31 @@ class Manager { return ($result['success'] && $status['ocs']['meta']['statuscode'] === 100); } - public static function setup() { + /** + * 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->getUserSession(), - \OC::$server->getHTTPHelper() + \OC::$server->getHTTPHelper(), + $params['user'] ); + $externalManager->setupMounts(); } + /** + * remove '/user/files' from the path and trailing slashes + * + * @param string $path + * @return string + */ protected function stripPath($path) { - $prefix = '/' . $this->userSession->getUser()->getUID() . '/files'; + $prefix = '/' . $this->uid . '/files'; return rtrim(substr($path, strlen($prefix)), '/'); } @@ -196,11 +221,10 @@ class Manager { * @return Mount */ protected function mountShare($data) { - $user = $this->userSession->getUser(); $data['manager'] = $this; - $mountPoint = '/' . $user->getUID() . '/files' . $data['mountpoint']; + $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; $data['mountpoint'] = $mountPoint; - $data['certificateManager'] = \OC::$server->getCertificateManager($user); + $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); $mount = new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); $this->mountManager->addMount($mount); return $mount; @@ -219,7 +243,6 @@ class Manager { * @return bool */ public function setMountPoint($source, $target) { - $user = $this->userSession->getUser(); $source = $this->stripPath($source); $target = $this->stripPath($target); $sourceHash = md5($source); @@ -231,13 +254,12 @@ class Manager { WHERE `mountpoint_hash` = ? AND `user` = ? '); - $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $user->getUID())); + $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); return $result; } public function removeShare($mountPoint) { - $user = $this->userSession->getUser(); $mountPoint = $this->stripPath($mountPoint); $hash = md5($mountPoint); @@ -245,7 +267,7 @@ class Manager { SELECT `remote`, `share_token`, `remote_id` FROM `*PREFIX*share_external` WHERE `mountpoint_hash` = ? AND `user` = ?'); - $result = $getShare->execute(array($hash, $user->getUID())); + $result = $getShare->execute(array($hash, $this->uid)); if ($result) { $share = $getShare->fetch(); @@ -257,7 +279,7 @@ class Manager { WHERE `mountpoint_hash` = ? AND `user` = ? '); - return (bool)$query->execute(array($hash, $user->getUID())); + return (bool)$query->execute(array($hash, $this->uid)); } /** @@ -294,7 +316,7 @@ class Manager { */ public function getOpenShares() { $openShares = $this->connection->prepare('SELECT * FROM `*PREFIX*share_external` WHERE `accepted` = ? AND `user` = ?'); - $result = $openShares->execute(array(0, $this->userSession->getUser()->getUID())); + $result = $openShares->execute(array(0, $this->uid)); return $result ? $openShares->fetchAll() : array(); diff --git a/apps/files_sharing/lib/hooks.php b/apps/files_sharing/lib/hooks.php index 6f23c103b1d..10e16be4a91 100644 --- a/apps/files_sharing/lib/hooks.php +++ b/apps/files_sharing/lib/hooks.php @@ -30,8 +30,8 @@ class Hooks { \OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), - \OC::$server->getUserSession(), - \OC::$server->getHTTPHelper()); + \OC::$server->getHTTPHelper(), + $params['uid']); $manager->removeUserShares($params['uid']); } diff --git a/apps/files_sharing/tests/server2server.php b/apps/files_sharing/tests/server2server.php index 2d59f7be9cd..6e9c0dd0ddd 100644 --- a/apps/files_sharing/tests/server2server.php +++ b/apps/files_sharing/tests/server2server.php @@ -153,8 +153,9 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase { \OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), - \OC::$server->getUserSession(), - \OC::$server->getHTTPHelper()); + \OC::$server->getHTTPHelper(), + $toDelete + ); $manager->removeUserShares($toDelete); |