diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-12-04 19:51:04 +0100 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-12-19 15:20:24 +0100 |
commit | 24993280edcf66f9daa5a5e82428fefef4a3ab56 (patch) | |
tree | ede7ca0417af874185588a845fe5f7f754076f60 /apps/files_sharing/api | |
parent | f671b232cc122cdb8e993c8b35bd5419b32a9ae4 (diff) | |
download | nextcloud-server-24993280edcf66f9daa5a5e82428fefef4a3ab56.tar.gz nextcloud-server-24993280edcf66f9daa5a5e82428fefef4a3ab56.zip |
Next step in server-to-server sharing next generation, see #12285
Beside some small improvements and bug fixes this will probably the final state for OC8.
To test this you need to set up two ownCloud instances. Let's say:
URL: myPC/firstOwnCloud user: user1
URL: myPC/secondOwnCloud user: user2
Now user1 can share a file with user2 by entering the username and the URL to the second ownCloud to the share-drop-down, in this case "user2@myPC/secondOwnCloud".
The next time user2 login he will get a notification that he received a server-to-server share with the option to accept/decline it. If he accept it the share will be mounted. In both cases a event will be send back to user1 and add a notification to the activity stream that the share was accepted/declined.
If user1 decides to unshare the file again from user2 the share will automatically be removed from the second ownCloud server and user2 will see a notification in his activity stream that user1@myPC/firstOwnCloud has unshared the file/folder from him.
Diffstat (limited to 'apps/files_sharing/api')
-rw-r--r-- | apps/files_sharing/api/server2server.php | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/apps/files_sharing/api/server2server.php b/apps/files_sharing/api/server2server.php index 2949e2dd09c..f78d64caa73 100644 --- a/apps/files_sharing/api/server2server.php +++ b/apps/files_sharing/api/server2server.php @@ -34,7 +34,7 @@ class Server2Server { public function createShare($params) { if (!$this->isS2SEnabled(true)) { - return \OC_OCS_Result(null, 503, 'Server does not support server-to-server sharing'); + return new \OC_OCS_Result(null, 503, 'Server does not support server-to-server sharing'); } $remote = isset($_POST['remote']) ? $_POST['remote'] : null; @@ -42,7 +42,7 @@ class Server2Server { $name = isset($_POST['name']) ? $_POST['name'] : null; $owner = isset($_POST['owner']) ? $_POST['owner'] : null; $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; - $remoteId = isset($_POST['remote_id']) ? (int)$_POST['remote_id'] : null; + $remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null; if ($remote && $token && $name && $owner && $remoteId && $shareWith) { @@ -56,19 +56,28 @@ class Server2Server { \OC_Util::setupFS($shareWith); - $mountPoint = \OC\Files\Filesystem::normalizePath('/' . $name); + $externalManager = new \OCA\Files_Sharing\External\Manager( + \OC::$server->getDatabaseConnection(), + \OC\Files\Filesystem::getMountManager(), + \OC\Files\Filesystem::getLoader(), + \OC::$server->getUserSession(), + \OC::$server->getHTTPHelper()); + $name = \OCP\Files::buildNotExistingFileName('/', $name); try { - \OCA\Files_Sharing\Helper::addServer2ServerShare($remote, $token, $name, $mountPoint, $owner, $shareWith, '', $remoteId); + $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId); + + $user = $owner . '@' . $this->cleanupRemote($remote); \OC::$server->getActivityManager()->publishActivity( - 'files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($owner), '', array(), - '', '', $shareWith, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW); + 'files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($user), '', array(), + '', '', $shareWith, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW); return new \OC_OCS_Result(); } catch (\Exception $e) { - return new \OC_OCS_Result(null, 500, 'server can not add remote share, ' . $e->getMessage()); + \OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR); + return new \OC_OCS_Result(null, 500, 'internal server error, was not able to add share from ' . $remote); } } @@ -84,7 +93,7 @@ class Server2Server { public function acceptShare($params) { if (!$this->isS2SEnabled()) { - return \OC_OCS_Result(null, 503, 'Server does not support server-to-server sharing'); + return new \OC_OCS_Result(null, 503, 'Server does not support server-to-server sharing'); } $id = $params['id']; @@ -95,8 +104,8 @@ class Server2Server { list($file, $link) = self::getFile($share['uid_owner'], $share['file_source']); \OC::$server->getActivityManager()->publishActivity( - 'files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_ACCEPTED, array($share['share_with'], basename($file)), '', array(), - $file, $link, $share['uid_owner'], \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW); + 'files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_ACCEPTED, array($share['share_with'], basename($file)), '', array(), + $file, $link, $share['uid_owner'], \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW); } return new \OC_OCS_Result(); @@ -111,7 +120,7 @@ class Server2Server { public function declineShare($params) { if (!$this->isS2SEnabled()) { - return \OC_OCS_Result(null, 503, 'Server does not support server-to-server sharing'); + return new \OC_OCS_Result(null, 503, 'Server does not support server-to-server sharing'); } $id = $params['id']; @@ -126,8 +135,8 @@ class Server2Server { list($file, $link) = $this->getFile($share['uid_owner'], $share['file_source']); \OC::$server->getActivityManager()->publishActivity( - 'files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_DECLINED, array($share['share_with'], basename($file)), '', array(), - $file, $link, $share['uid_owner'], \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW); + 'files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_DECLINED, array($share['share_with'], basename($file)), '', array(), + $file, $link, $share['uid_owner'], \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW); } return new \OC_OCS_Result(); @@ -142,7 +151,7 @@ class Server2Server { public function unshare($params) { if (!$this->isS2SEnabled()) { - return \OC_OCS_Result(null, 503, 'Server does not support server-to-server sharing'); + return new \OC_OCS_Result(null, 503, 'Server does not support server-to-server sharing'); } $id = $params['id']; @@ -154,7 +163,9 @@ class Server2Server { if ($token && $id && !empty($share)) { - $owner = $share['owner'] . '@' . $share['remote']; + $remote = $this->cleanupRemote($share['remote']); + + $owner = $share['owner'] . '@' . $remote; $mountpoint = $share['mountpoint']; $user = $share['user']; @@ -162,13 +173,19 @@ class Server2Server { $query->execute(array($id, $token)); \OC::$server->getActivityManager()->publishActivity( - 'files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_DECLINED, array($owner, $mountpoint), '', array(), - '', '', $user, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_MEDIUM); + 'files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_UNSHARED, array($owner, $mountpoint), '', array(), + '', '', $user, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_MEDIUM); } return new \OC_OCS_Result(); } + private function cleanupRemote($remote) { + $remote = substr($remote, strpos($remote, '://') + 3); + + return rtrim($remote, '/'); + } + /** * get share * |