summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-03-01 11:27:28 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-03-01 11:27:28 +0100
commit5fe5233f419624dc3eac8ee4bf95a38b001ea6fd (patch)
tree4c0b5ea576ec67cc2d5f57ccb186e65276d1cc3c /apps/files_sharing
parent73e145cf63e94f68dc1f129da14e470695d46abd (diff)
parent88fc5149eddcbeaf41358c0eb56be45ad2c94a59 (diff)
downloadnextcloud-server-5fe5233f419624dc3eac8ee4bf95a38b001ea6fd.tar.gz
nextcloud-server-5fe5233f419624dc3eac8ee4bf95a38b001ea6fd.zip
Merge pull request #22681 from owncloud/add-autodiscovery-for-ocs
Add autodiscovery support to server-to-server sharing implementation
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/ajax/external.php6
-rw-r--r--apps/files_sharing/api/remote.php31
-rw-r--r--apps/files_sharing/api/server2server.php6
-rw-r--r--apps/files_sharing/appinfo/application.php6
-rw-r--r--apps/files_sharing/lib/external/manager.php18
-rw-r--r--apps/files_sharing/lib/external/storage.php7
-rw-r--r--apps/files_sharing/lib/hooks.php6
-rw-r--r--apps/files_sharing/tests/external/managertest.php6
-rw-r--r--apps/files_sharing/tests/server2server.php7
9 files changed, 86 insertions, 7 deletions
diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php
index 1efe4356b4c..76f9d5d7668 100644
--- a/apps/files_sharing/ajax/external.php
+++ b/apps/files_sharing/ajax/external.php
@@ -57,13 +57,17 @@ if (\OC\Share\Helper::isSameUserOnSameServer($owner, $remote, $currentUser, $cur
exit();
}
-
+$discoveryManager = new \OCA\FederatedFileSharing\DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+);
$externalManager = new \OCA\Files_Sharing\External\Manager(
\OC::$server->getDatabaseConnection(),
\OC\Files\Filesystem::getMountManager(),
\OC\Files\Filesystem::getLoader(),
\OC::$server->getHTTPHelper(),
\OC::$server->getNotificationManager(),
+ $discoveryManager,
\OC::$server->getUserSession()->getUser()->getUID()
);
diff --git a/apps/files_sharing/api/remote.php b/apps/files_sharing/api/remote.php
index 8b47955b51e..1b5eb28aa86 100644
--- a/apps/files_sharing/api/remote.php
+++ b/apps/files_sharing/api/remote.php
@@ -24,6 +24,7 @@
namespace OCA\Files_Sharing\API;
use OC\Files\Filesystem;
+use OCA\FederatedFileSharing\DiscoveryManager;
use OCA\Files_Sharing\External\Manager;
class Remote {
@@ -35,12 +36,17 @@ class Remote {
* @return \OC_OCS_Result
*/
public static function getOpenShares($params) {
+ $discoveryManager = new DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
$externalManager = new Manager(
\OC::$server->getDatabaseConnection(),
Filesystem::getMountManager(),
Filesystem::getLoader(),
\OC::$server->getHTTPHelper(),
\OC::$server->getNotificationManager(),
+ $discoveryManager,
\OC_User::getUser()
);
@@ -54,12 +60,17 @@ class Remote {
* @return \OC_OCS_Result
*/
public static function acceptShare($params) {
+ $discoveryManager = new DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
$externalManager = new Manager(
\OC::$server->getDatabaseConnection(),
Filesystem::getMountManager(),
Filesystem::getLoader(),
\OC::$server->getHTTPHelper(),
\OC::$server->getNotificationManager(),
+ $discoveryManager,
\OC_User::getUser()
);
@@ -80,12 +91,17 @@ class Remote {
* @return \OC_OCS_Result
*/
public static function declineShare($params) {
+ $discoveryManager = new DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
$externalManager = new Manager(
\OC::$server->getDatabaseConnection(),
Filesystem::getMountManager(),
Filesystem::getLoader(),
\OC::$server->getHTTPHelper(),
\OC::$server->getNotificationManager(),
+ $discoveryManager,
\OC_User::getUser()
);
@@ -123,12 +139,17 @@ class Remote {
* @return \OC_OCS_Result
*/
public static function getShares($params) {
+ $discoveryManager = new DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
$externalManager = new Manager(
\OC::$server->getDatabaseConnection(),
Filesystem::getMountManager(),
Filesystem::getLoader(),
\OC::$server->getHTTPHelper(),
\OC::$server->getNotificationManager(),
+ $discoveryManager,
\OC_User::getUser()
);
@@ -146,12 +167,17 @@ class Remote {
* @return \OC_OCS_Result
*/
public static function getShare($params) {
+ $discoveryManager = new DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
$externalManager = new Manager(
\OC::$server->getDatabaseConnection(),
Filesystem::getMountManager(),
Filesystem::getLoader(),
\OC::$server->getHTTPHelper(),
\OC::$server->getNotificationManager(),
+ $discoveryManager,
\OC_User::getUser()
);
@@ -172,12 +198,17 @@ class Remote {
* @return \OC_OCS_Result
*/
public static function unshare($params) {
+ $discoveryManager = new DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
$externalManager = new Manager(
\OC::$server->getDatabaseConnection(),
Filesystem::getMountManager(),
Filesystem::getLoader(),
\OC::$server->getHTTPHelper(),
\OC::$server->getNotificationManager(),
+ $discoveryManager,
\OC_User::getUser()
);
diff --git a/apps/files_sharing/api/server2server.php b/apps/files_sharing/api/server2server.php
index f04ddc81b84..6da95ed6549 100644
--- a/apps/files_sharing/api/server2server.php
+++ b/apps/files_sharing/api/server2server.php
@@ -25,6 +25,7 @@
namespace OCA\Files_Sharing\API;
+use OCA\FederatedFileSharing\DiscoveryManager;
use OCA\Files_Sharing\Activity;
use OCP\Files\NotFoundException;
@@ -70,12 +71,17 @@ class Server2Server {
\OC_Util::setupFS($shareWith);
+ $discoveryManager = new DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
$externalManager = new \OCA\Files_Sharing\External\Manager(
\OC::$server->getDatabaseConnection(),
\OC\Files\Filesystem::getMountManager(),
\OC\Files\Filesystem::getLoader(),
\OC::$server->getHTTPHelper(),
\OC::$server->getNotificationManager(),
+ $discoveryManager,
$shareWith
);
diff --git a/apps/files_sharing/appinfo/application.php b/apps/files_sharing/appinfo/application.php
index e4a2262fece..64c7517456d 100644
--- a/apps/files_sharing/appinfo/application.php
+++ b/apps/files_sharing/appinfo/application.php
@@ -24,6 +24,7 @@
namespace OCA\Files_Sharing\AppInfo;
+use OCA\FederatedFileSharing\DiscoveryManager;
use OCA\Files_Sharing\MountProvider;
use OCP\AppFramework\App;
use OC\AppFramework\Utility\SimpleContainer;
@@ -76,12 +77,17 @@ class Application extends App {
$container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) {
$user = $server->getUserSession()->getUser();
$uid = $user ? $user->getUID() : null;
+ $discoveryManager = new DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
return new \OCA\Files_Sharing\External\Manager(
$server->getDatabaseConnection(),
\OC\Files\Filesystem::getMountManager(),
\OC\Files\Filesystem::getLoader(),
$server->getHTTPHelper(),
$server->getNotificationManager(),
+ $discoveryManager,
$uid
);
});
diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php
index 84de1da69f6..ec487449625 100644
--- a/apps/files_sharing/lib/external/manager.php
+++ b/apps/files_sharing/lib/external/manager.php
@@ -27,6 +27,7 @@
namespace OCA\Files_Sharing\External;
use OC\Files\Filesystem;
+use OCA\FederatedFileSharing\DiscoveryManager;
use OCP\Files;
use OCP\Notification\IManager;
@@ -62,6 +63,8 @@ class Manager {
* @var IManager
*/
private $notificationManager;
+ /** @var DiscoveryManager */
+ private $discoveryManager;
/**
* @param \OCP\IDBConnection $connection
@@ -69,16 +72,23 @@ class Manager {
* @param \OCP\Files\Storage\IStorageFactory $storageLoader
* @param \OC\HTTPHelper $httpHelper
* @param IManager $notificationManager
+ * @param DiscoveryManager $discoveryManager
* @param string $uid
*/
- public function __construct(\OCP\IDBConnection $connection, \OC\Files\Mount\Manager $mountManager,
- \OCP\Files\Storage\IStorageFactory $storageLoader, \OC\HTTPHelper $httpHelper, IManager $notificationManager, $uid) {
+ public function __construct(\OCP\IDBConnection $connection,
+ \OC\Files\Mount\Manager $mountManager,
+ \OCP\Files\Storage\IStorageFactory $storageLoader,
+ \OC\HTTPHelper $httpHelper,
+ IManager $notificationManager,
+ DiscoveryManager $discoveryManager,
+ $uid) {
$this->connection = $connection;
$this->mountManager = $mountManager;
$this->storageLoader = $storageLoader;
$this->httpHelper = $httpHelper;
$this->uid = $uid;
$this->notificationManager = $notificationManager;
+ $this->discoveryManager = $discoveryManager;
}
/**
@@ -246,13 +256,13 @@ class Manager {
*/
private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) {
- $url = rtrim($remote, '/') . \OCP\Share::BASE_PATH_TO_SHARE_API . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT;
+ $url = rtrim($remote, '/') . $this->discoveryManager->getShareEndpoint($remote) . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT;
$fields = array('token' => $token);
$result = $this->httpHelper->post($url, $fields);
$status = json_decode($result['result'], true);
- return ($result['success'] && $status['ocs']['meta']['statuscode'] === 100);
+ return ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200));
}
/**
diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php
index ed391f331ad..41f7bef589b 100644
--- a/apps/files_sharing/lib/external/storage.php
+++ b/apps/files_sharing/lib/external/storage.php
@@ -67,6 +67,11 @@ class Storage extends DAV implements ISharedStorage {
private $manager;
public function __construct($options) {
+ $discoveryManager = new DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
+
$this->manager = $options['manager'];
$this->certificateManager = $options['certificateManager'];
$this->remote = $options['remote'];
@@ -79,7 +84,7 @@ class Storage extends DAV implements ISharedStorage {
$root = '';
}
$secure = $protocol === 'https';
- $root = rtrim($root, '/') . '/public.php/webdav';
+ $root = rtrim($root, '/') . $discoveryManager->getWebDavEndpoint($this->remote);
$this->mountPoint = $options['mountpoint'];
$this->token = $options['token'];
parent::__construct(array(
diff --git a/apps/files_sharing/lib/hooks.php b/apps/files_sharing/lib/hooks.php
index 166905b9aa4..e3f24d02268 100644
--- a/apps/files_sharing/lib/hooks.php
+++ b/apps/files_sharing/lib/hooks.php
@@ -25,16 +25,22 @@
namespace OCA\Files_Sharing;
use OC\Files\Filesystem;
+use OCA\FederatedFileSharing\DiscoveryManager;
class Hooks {
public static function deleteUser($params) {
+ $discoveryManager = new DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
$manager = new External\Manager(
\OC::$server->getDatabaseConnection(),
\OC\Files\Filesystem::getMountManager(),
\OC\Files\Filesystem::getLoader(),
\OC::$server->getHTTPHelper(),
\OC::$server->getNotificationManager(),
+ $discoveryManager,
$params['uid']);
$manager->removeUserShares($params['uid']);
diff --git a/apps/files_sharing/tests/external/managertest.php b/apps/files_sharing/tests/external/managertest.php
index f73fedaf05c..2836a3dc024 100644
--- a/apps/files_sharing/tests/external/managertest.php
+++ b/apps/files_sharing/tests/external/managertest.php
@@ -24,6 +24,7 @@
namespace OCA\Files_Sharing\Tests\External;
use OC\Files\Storage\StorageFactory;
+use OCA\FederatedFileSharing\DiscoveryManager;
use OCA\Files_Sharing\External\Manager;
use OCA\Files_Sharing\External\MountProvider;
use OCA\Files_Sharing\Tests\TestCase;
@@ -64,6 +65,10 @@ class ManagerTest extends TestCase {
$this->user = \OC::$server->getUserManager()->get($this->uid);
$this->mountManager = new \OC\Files\Mount\Manager();
$this->httpHelper = $httpHelper = $this->getMockBuilder('\OC\HTTPHelper')->disableOriginalConstructor()->getMock();
+ $discoveryManager = new DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
/** @var \OC\HTTPHelper $httpHelper */
$this->manager = new Manager(
\OC::$server->getDatabaseConnection(),
@@ -71,6 +76,7 @@ class ManagerTest extends TestCase {
new StorageFactory(),
$httpHelper,
\OC::$server->getNotificationManager(),
+ $discoveryManager,
$this->uid
);
$this->mountProvider = new MountProvider(\OC::$server->getDatabaseConnection(), function() {
diff --git a/apps/files_sharing/tests/server2server.php b/apps/files_sharing/tests/server2server.php
index a282f92ecb9..298f1008f71 100644
--- a/apps/files_sharing/tests/server2server.php
+++ b/apps/files_sharing/tests/server2server.php
@@ -153,14 +153,19 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase {
function testDeleteUser($toDelete, $expected, $remainingUsers) {
$this->createDummyS2SShares();
+ $discoveryManager = new \OCA\FederatedFileSharing\DiscoveryManager(
+ \OC::$server->getMemCacheFactory(),
+ \OC::$server->getHTTPClientService()
+ );
$manager = new OCA\Files_Sharing\External\Manager(
\OC::$server->getDatabaseConnection(),
\OC\Files\Filesystem::getMountManager(),
\OC\Files\Filesystem::getLoader(),
\OC::$server->getHTTPHelper(),
\OC::$server->getNotificationManager(),
+ $discoveryManager,
$toDelete
- );
+ );
$manager->removeUserShares($toDelete);