diff options
author | Robin Appelman <robin@icewind.nl> | 2017-01-27 12:52:17 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2017-02-08 15:17:02 +0100 |
commit | fa49c4a13b6c5455b13ad44cfc158b271aa9b616 (patch) | |
tree | 1014b6de1bd3761e2e26467c78c6f5fd4697ea56 /apps/files_sharing/lib/External | |
parent | 1a591cea97313b8500154d6c2c9ce3aaf2f38a88 (diff) | |
download | nextcloud-server-fa49c4a13b6c5455b13ad44cfc158b271aa9b616.tar.gz nextcloud-server-fa49c4a13b6c5455b13ad44cfc158b271aa9b616.zip |
Add a single public api for resolving a cloud id to a user and remote and back
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_sharing/lib/External')
-rw-r--r-- | apps/files_sharing/lib/External/Cache.php | 18 | ||||
-rw-r--r-- | apps/files_sharing/lib/External/MountProvider.php | 11 | ||||
-rw-r--r-- | apps/files_sharing/lib/External/Storage.php | 31 |
3 files changed, 35 insertions, 25 deletions
diff --git a/apps/files_sharing/lib/External/Cache.php b/apps/files_sharing/lib/External/Cache.php index eaf8e0c4acf..c7793cf0595 100644 --- a/apps/files_sharing/lib/External/Cache.php +++ b/apps/files_sharing/lib/External/Cache.php @@ -24,21 +24,25 @@ namespace OCA\Files_Sharing\External; +use OCP\Federation\ICloudId; + class Cache extends \OC\Files\Cache\Cache { + /** @var ICloudId */ + private $cloudId; private $remote; private $remoteUser; private $storage; /** * @param \OCA\Files_Sharing\External\Storage $storage - * @param string $remote - * @param string $remoteUser + * @param ICloudId $cloudId */ - public function __construct($storage, $remote, $remoteUser) { + public function __construct($storage, ICloudId $cloudId) { + $this->cloudId = $cloudId; $this->storage = $storage; - list(, $remote) = explode('://', $remote, 2); + list(, $remote) = explode('://', $cloudId->getRemote(), 2); $this->remote = $remote; - $this->remoteUser = $remoteUser; + $this->remoteUser = $cloudId->getUser(); parent::__construct($storage); } @@ -47,7 +51,7 @@ class Cache extends \OC\Files\Cache\Cache { if (!$result) { return false; } - $result['displayname_owner'] = $this->remoteUser . '@' . $this->remote; + $result['displayname_owner'] = $this->cloudId->getDisplayId(); if (!$file || $file === '') { $result['is_share_mount_point'] = true; $mountPoint = rtrim($this->storage->getMountPoint()); @@ -59,7 +63,7 @@ class Cache extends \OC\Files\Cache\Cache { public function getFolderContentsById($id) { $results = parent::getFolderContentsById($id); foreach ($results as &$file) { - $file['displayname_owner'] = $this->remoteUser . '@' . $this->remote; + $file['displayname_owner'] = $this->cloudId->getDisplayId(); } return $results; } diff --git a/apps/files_sharing/lib/External/MountProvider.php b/apps/files_sharing/lib/External/MountProvider.php index 3f2f39a74f7..27ee9fcb46b 100644 --- a/apps/files_sharing/lib/External/MountProvider.php +++ b/apps/files_sharing/lib/External/MountProvider.php @@ -22,6 +22,7 @@ namespace OCA\Files_Sharing\External; +use OCP\Federation\ICloudIdManager; use OCP\Files\Config\IMountProvider; use OCP\Files\Storage\IStorageFactory; use OCP\IDBConnection; @@ -41,12 +42,19 @@ class MountProvider implements IMountProvider { private $managerProvider; /** + * @var ICloudIdManager + */ + private $cloudIdManager; + + /** * @param \OCP\IDBConnection $connection * @param callable $managerProvider due to setup order we need a callable that return the manager instead of the manager itself + * @param ICloudIdManager $cloudIdManager */ - public function __construct(IDBConnection $connection, callable $managerProvider) { + public function __construct(IDBConnection $connection, callable $managerProvider, ICloudIdManager $cloudIdManager) { $this->connection = $connection; $this->managerProvider = $managerProvider; + $this->cloudIdManager = $cloudIdManager; } public function getMount(IUser $user, $data, IStorageFactory $storageFactory) { @@ -55,6 +63,7 @@ class MountProvider implements IMountProvider { $data['manager'] = $manager; $mountPoint = '/' . $user->getUID() . '/files/' . ltrim($data['mountpoint'], '/'); $data['mountpoint'] = $mountPoint; + $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']); $data['certificateManager'] = \OC::$server->getCertificateManager($user->getUID()); $data['HttpClientService'] = \OC::$server->getHTTPClientService(); return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory); diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php index 93f3571e803..51d97388db7 100644 --- a/apps/files_sharing/lib/External/Storage.php +++ b/apps/files_sharing/lib/External/Storage.php @@ -35,15 +35,14 @@ use OC\ForbiddenException; use OCA\FederatedFileSharing\DiscoveryManager; use OCA\Files_Sharing\ISharedStorage; use OCP\AppFramework\Http; +use OCP\Federation\ICloudId; use OCP\Files\NotFoundException; use OCP\Files\StorageInvalidException; use OCP\Files\StorageNotAvailableException; class Storage extends DAV implements ISharedStorage { - /** @var string */ - private $remoteUser; - /** @var string */ - private $remote; + /** @var ICloudId */ + private $cloudId; /** @var string */ private $mountPoint; /** @var string */ @@ -72,9 +71,8 @@ class Storage extends DAV implements ISharedStorage { $this->manager = $options['manager']; $this->certificateManager = $options['certificateManager']; - $this->remote = $options['remote']; - $this->remoteUser = $options['owner']; - list($protocol, $remote) = explode('://', $this->remote); + $this->cloudId = $options['cloudId']; + list($protocol, $remote) = explode('://', $this->cloudId->getRemote()); if (strpos($remote, '/')) { list($host, $root) = explode('/', $remote, 2); } else { @@ -82,7 +80,7 @@ class Storage extends DAV implements ISharedStorage { $root = ''; } $secure = $protocol === 'https'; - $root = rtrim($root, '/') . $discoveryManager->getWebDavEndpoint($this->remote); + $root = rtrim($root, '/') . $discoveryManager->getWebDavEndpoint($this->cloudId->getRemote()); $this->mountPoint = $options['mountpoint']; $this->token = $options['token']; parent::__construct(array( @@ -106,11 +104,11 @@ class Storage extends DAV implements ISharedStorage { } public function getRemoteUser() { - return $this->remoteUser; + return $this->cloudId->getUser(); } public function getRemote() { - return $this->remote; + return $this->cloudId->getRemote(); } public function getMountPoint() { @@ -130,12 +128,12 @@ class Storage extends DAV implements ISharedStorage { * @return string */ public function getId() { - return 'shared::' . md5($this->token . '@' . $this->remote); + return 'shared::' . md5($this->token . '@' . $this->getRemote()); } public function getCache($path = '', $storage = null) { if (is_null($this->cache)) { - $this->cache = new Cache($this, $this->remote, $this->remoteUser); + $this->cache = new Cache($this, $this->cloudId); } return $this->cache; } @@ -251,9 +249,9 @@ class Storage extends DAV implements ISharedStorage { */ protected function testRemote() { try { - return $this->testRemoteUrl($this->remote . '/ocs-provider/index.php') - || $this->testRemoteUrl($this->remote . '/ocs-provider/') - || $this->testRemoteUrl($this->remote . '/status.php'); + return $this->testRemoteUrl($this->getRemote() . '/ocs-provider/index.php') + || $this->testRemoteUrl($this->getRemote() . '/ocs-provider/') + || $this->testRemoteUrl($this->getRemote() . '/status.php'); } catch (\Exception $e) { return false; } @@ -343,8 +341,7 @@ class Storage extends DAV implements ISharedStorage { } public function getOwner($path) { - list(, $remote) = explode('://', $this->remote, 2); - return $this->remoteUser . '@' . $remote; + return $this->cloudId->getDisplayId(); } public function isSharable($path) { |