fall back to old re-sharing behaviour in case the remote server doesn't support flat-reshares
This commit is contained in:
parent
2dc26aada7
commit
92fa0c7dfd
2 changed files with 70 additions and 35 deletions
|
@ -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);
|
||||
|
@ -210,6 +203,41 @@ class FederatedShareProvider implements IShareProvider {
|
|||
return $share;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -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'])
|
||||
|
|
|
@ -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://';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue