summaryrefslogtreecommitdiffstats
path: root/apps/federatedfilesharing/lib/FederatedShareProvider.php
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-01-27 12:52:17 +0100
committerRobin Appelman <robin@icewind.nl>2017-02-08 15:17:02 +0100
commitfa49c4a13b6c5455b13ad44cfc158b271aa9b616 (patch)
tree1014b6de1bd3761e2e26467c78c6f5fd4697ea56 /apps/federatedfilesharing/lib/FederatedShareProvider.php
parent1a591cea97313b8500154d6c2c9ce3aaf2f38a88 (diff)
downloadnextcloud-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/federatedfilesharing/lib/FederatedShareProvider.php')
-rw-r--r--apps/federatedfilesharing/lib/FederatedShareProvider.php26
1 files changed, 18 insertions, 8 deletions
diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php
index 61f1b1c8f18..b8a584ce6be 100644
--- a/apps/federatedfilesharing/lib/FederatedShareProvider.php
+++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php
@@ -27,6 +27,7 @@
namespace OCA\FederatedFileSharing;
use OC\Share20\Share;
+use OCP\Federation\ICloudIdManager;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\IConfig;
@@ -80,6 +81,9 @@ class FederatedShareProvider implements IShareProvider {
/** @var IUserManager */
private $userManager;
+ /** @var ICloudIdManager */
+ private $cloudIdManager;
+
/**
* DefaultShareProvider constructor.
*
@@ -92,6 +96,7 @@ class FederatedShareProvider implements IShareProvider {
* @param IRootFolder $rootFolder
* @param IConfig $config
* @param IUserManager $userManager
+ * @param ICloudIdManager $cloudIdManager
*/
public function __construct(
IDBConnection $connection,
@@ -102,7 +107,8 @@ class FederatedShareProvider implements IShareProvider {
ILogger $logger,
IRootFolder $rootFolder,
IConfig $config,
- IUserManager $userManager
+ IUserManager $userManager,
+ ICloudIdManager $cloudIdManager
) {
$this->dbConnection = $connection;
$this->addressHandler = $addressHandler;
@@ -113,6 +119,7 @@ class FederatedShareProvider implements IShareProvider {
$this->rootFolder = $rootFolder;
$this->config = $config;
$this->userManager = $userManager;
+ $this->cloudIdManager = $cloudIdManager;
}
/**
@@ -153,17 +160,18 @@ class FederatedShareProvider implements IShareProvider {
// don't allow federated shares if source and target server are the same
- list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
+ $cloudId = $this->cloudIdManager->resolveCloudId($shareWith);
$currentServer = $this->addressHandler->generateRemoteURL();
$currentUser = $sharedBy;
- if ($this->addressHandler->compareAddresses($user, $remote, $currentUser, $currentServer)) {
+ if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) {
$message = 'Not allowed to create a federated share with the same user.';
$message_t = $this->l->t('Not allowed to create a federated share with the same user');
$this->logger->debug($message, ['app' => 'Federated File Sharing']);
throw new \Exception($message_t);
}
- $share->setSharedWith($user . '@' . $remote);
+
+ $share->setSharedWith(rtrim($cloudId->getId(), '/'));
try {
$remoteShare = $this->getShareFromExternalShareTable($share);
@@ -173,8 +181,8 @@ class FederatedShareProvider implements IShareProvider {
if ($remoteShare) {
try {
- $uidOwner = $remoteShare['owner'] . '@' . $remoteShare['remote'];
- $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, 'tmp_token_' . time());
+ $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']);
+ $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time());
$share->setId($shareId);
list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId);
// remote share was create successfully if we get a valid token as return
@@ -227,15 +235,17 @@ class FederatedShareProvider implements IShareProvider {
try {
$sharedByFederatedId = $share->getSharedBy();
if ($this->userManager->userExists($sharedByFederatedId)) {
- $sharedByFederatedId = $sharedByFederatedId . '@' . $this->addressHandler->generateRemoteURL();
+ $cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL());
+ $sharedByFederatedId = $cloudId->getId();
}
+ $ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL());
$send = $this->notifications->sendRemoteShare(
$token,
$share->getSharedWith(),
$share->getNode()->getName(),
$shareId,
$share->getShareOwner(),
- $share->getShareOwner() . '@' . $this->addressHandler->generateRemoteURL(),
+ $ownerCloudId->getId(),
$share->getSharedBy(),
$sharedByFederatedId
);