summaryrefslogtreecommitdiffstats
path: root/apps/federatedfilesharing
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2016-05-17 15:03:37 +0200
committerBjörn Schießle <schiessle@owncloud.com>2016-05-20 21:15:16 +0200
commit92fa0c7dfdd5f8d9bc40ddc1c40ced97620d49f5 (patch)
tree422240b4e09e9ca7aa04307cf68dde57546e8942 /apps/federatedfilesharing
parent2dc26aada7977ad1416d6ac9797355807ab3d190 (diff)
downloadnextcloud-server-92fa0c7dfdd5f8d9bc40ddc1c40ced97620d49f5.tar.gz
nextcloud-server-92fa0c7dfdd5f8d9bc40ddc1c40ced97620d49f5.zip
fall back to old re-sharing behaviour in case the remote server doesn't support flat-reshares
Diffstat (limited to 'apps/federatedfilesharing')
-rw-r--r--apps/federatedfilesharing/lib/FederatedShareProvider.php98
-rw-r--r--apps/federatedfilesharing/lib/Notifications.php7
2 files changed, 70 insertions, 35 deletions
diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php
index 91398f4af35..20e915ef022 100644
--- a/apps/federatedfilesharing/lib/FederatedShareProvider.php
+++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php
@@ -133,7 +133,6 @@ class FederatedShareProvider implements IShareProvider {
$shareWith = $share->getSharedWith();
$itemSource = $share->getNodeId();
$itemType = $share->getNodeType();
- $uidOwner = $share->getShareOwner();
$permissions = $share->getPermissions();
$sharedBy = $share->getSharedBy();
@@ -160,7 +159,7 @@ class FederatedShareProvider implements IShareProvider {
throw new \Exception($message_t);
}
- $shareWith = $user . '@' . $remote;
+ $share->setSharedWith($user . '@' . $remote);
try {
$remoteShare = $this->getShareFromExternalShareTable($share);
@@ -169,39 +168,33 @@ class FederatedShareProvider implements IShareProvider {
}
if ($remoteShare) {
- $uidOwner = $remoteShare['owner'] . '@' . $remoteShare['remote'];
- $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, 'tmp_token_' . time());
- list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId);
- // remote share was create successfully if we get a valid token as return
- $send = is_string($token) && $token !== '';
- if ($send) {
- $this->updateSuccessfulReshare($shareId, $token);
- $this->storeRemoteId($shareId, $remoteId);
+ try {
+ $uidOwner = $remoteShare['owner'] . '@' . $remoteShare['remote'];
+ $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, 'tmp_token_' . time());
+ list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId);
+ // remote share was create successfully if we get a valid token as return
+ $send = is_string($token) && $token !== '';
+ if ($send) {
+ $this->updateSuccessfulReshare($shareId, $token);
+ $this->storeRemoteId($shareId, $remoteId);
+ }
+ } catch (\Exception $e) {
+ // fall back to old re-share behavior if the remote server
+ // doesn't support flat re-shares (was introduced with ownCloud 9.1)
+ $data = $this->getRawShare($shareId);
+ $brokenShare = $this->createShareObject($data);
+ $this->removeShareFromTable($brokenShare);
+ list($shareId, $send) = $this->createFederatedShare($share);
}
} else {
- $token = $this->tokenHandler->generateToken();
- $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token);
- $sharedByFederatedId = $share->getSharedBy();
- if ($this->userManager->userExists($sharedByFederatedId)) {
- $sharedByFederatedId = $sharedByFederatedId . '@' . $this->addressHandler->generateRemoteURL();
- }
- $send = $this->notifications->sendRemoteShare(
- $token,
- $shareWith,
- $share->getNode()->getName(),
- $shareId,
- $share->getShareOwner(),
- $share->getShareOwner() . '@' . $this->addressHandler->generateRemoteURL(),
- $share->getSharedBy(),
- $sharedByFederatedId
- );
+ list($shareId, $send) = $this->createFederatedShare($share);
}
$data = $this->getRawShare($shareId);
- $share = $this->createShare($data);
+ $share = $this->createShareObject($data);
if ($send === false) {
- $this->delete($share);
+ $this->removeShareFromTable($share);
$message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable.',
[$share->getNode()->getName(), $shareWith]);
throw new \Exception($message_t);
@@ -211,6 +204,41 @@ class FederatedShareProvider implements IShareProvider {
}
/**
+ * create federated share and inform the recipient
+ *
+ * @param IShare $share
+ * @return array
+ */
+ protected function createFederatedShare(IShare $share) {
+ $token = $this->tokenHandler->generateToken();
+ $shareId = $this->addShareToDB(
+ $share->getNodeId(),
+ $share->getNodeType(),
+ $share->getSharedWith(),
+ $share->getSharedBy(),
+ $share->getShareOwner(),
+ $share->getPermissions(),
+ $token
+ );
+ $sharedByFederatedId = $share->getSharedBy();
+ if ($this->userManager->userExists($sharedByFederatedId)) {
+ $sharedByFederatedId = $sharedByFederatedId . '@' . $this->addressHandler->generateRemoteURL();
+ }
+ $send = $this->notifications->sendRemoteShare(
+ $token,
+ $share->getSharedWith(),
+ $share->getNode()->getName(),
+ $shareId,
+ $share->getShareOwner(),
+ $share->getShareOwner() . '@' . $this->addressHandler->generateRemoteURL(),
+ $share->getSharedBy(),
+ $sharedByFederatedId
+ );
+
+ return [$shareId, $send];
+ }
+
+ /**
* @param string $shareWith
* @param IShare $share
* @param string $shareId internal share Id
@@ -421,7 +449,7 @@ class FederatedShareProvider implements IShareProvider {
$cursor = $qb->execute();
while($data = $cursor->fetch()) {
- $children[] = $this->createShare($data);
+ $children[] = $this->createShareObject($data);
}
$cursor->closeCursor();
@@ -562,7 +590,7 @@ class FederatedShareProvider implements IShareProvider {
$cursor = $qb->execute();
$shares = [];
while($data = $cursor->fetch()) {
- $shares[] = $this->createShare($data);
+ $shares[] = $this->createShareObject($data);
}
$cursor->closeCursor();
@@ -589,7 +617,7 @@ class FederatedShareProvider implements IShareProvider {
}
try {
- $share = $this->createShare($data);
+ $share = $this->createShareObject($data);
} catch (InvalidShare $e) {
throw new ShareNotFound();
}
@@ -614,7 +642,7 @@ class FederatedShareProvider implements IShareProvider {
$shares = [];
while($data = $cursor->fetch()) {
- $shares[] = $this->createShare($data);
+ $shares[] = $this->createShareObject($data);
}
$cursor->closeCursor();
@@ -653,7 +681,7 @@ class FederatedShareProvider implements IShareProvider {
$cursor = $qb->execute();
while($data = $cursor->fetch()) {
- $shares[] = $this->createShare($data);
+ $shares[] = $this->createShareObject($data);
}
$cursor->closeCursor();
@@ -684,7 +712,7 @@ class FederatedShareProvider implements IShareProvider {
}
try {
- $share = $this->createShare($data);
+ $share = $this->createShareObject($data);
} catch (InvalidShare $e) {
throw new ShareNotFound();
}
@@ -726,7 +754,7 @@ class FederatedShareProvider implements IShareProvider {
* @throws InvalidShare
* @throws ShareNotFound
*/
- private function createShare($data) {
+ private function createShareObject($data) {
$share = new Share($this->rootFolder, $this->userManager);
$share->setId((int)$data['id'])
diff --git a/apps/federatedfilesharing/lib/Notifications.php b/apps/federatedfilesharing/lib/Notifications.php
index ef59d0a5fdc..a6c198e395a 100644
--- a/apps/federatedfilesharing/lib/Notifications.php
+++ b/apps/federatedfilesharing/lib/Notifications.php
@@ -23,6 +23,7 @@
namespace OCA\FederatedFileSharing;
+use OCP\AppFramework\Http;
use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClientService;
@@ -291,6 +292,12 @@ class Notifications {
$result['success'] = true;
break;
} catch (\Exception $e) {
+ // if flat re-sharing is not supported by the remote server
+ // we re-throw the exception and fall back to the old behaviour.
+ // (flat re-shares has been introduced in ownCloud 9.1)
+ if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
+ throw $e;
+ }
$try++;
$protocol = 'http://';
}