diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2018-05-29 16:21:13 +0200 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2018-07-02 11:29:28 +0200 |
commit | 8889e14c7cb848634895d8bbdedd13194c37301c (patch) | |
tree | 75f54fd99948e7b3d92ba3028dcdf29477b6630c /apps/federatedfilesharing/lib/Controller | |
parent | bbce8c3ea1c73726f233961fe7bdb16b8a08bb67 (diff) | |
download | nextcloud-server-8889e14c7cb848634895d8bbdedd13194c37301c.tar.gz nextcloud-server-8889e14c7cb848634895d8bbdedd13194c37301c.zip |
implement accept share notification
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/federatedfilesharing/lib/Controller')
-rw-r--r-- | apps/federatedfilesharing/lib/Controller/RequestHandlerController.php | 78 |
1 files changed, 16 insertions, 62 deletions
diff --git a/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php b/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php index e2cc050d879..628e306e994 100644 --- a/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php +++ b/apps/federatedfilesharing/lib/Controller/RequestHandlerController.php @@ -42,6 +42,7 @@ use OCP\AppFramework\OCSController; use OCP\Constants; use OCP\Federation\Exceptions\ProviderCouldNotAddShareException; use OCP\Federation\Exceptions\ProviderDoesNotExistsException; +use OCP\Federation\Exceptions\ShareNotFoundException; use OCP\Federation\ICloudFederationFactory; use OCP\Federation\ICloudFederationProviderManager; use OCP\Federation\ICloudIdManager; @@ -265,47 +266,32 @@ class RequestHandlerController extends OCSController { * @param int $id * @return Http\DataResponse * @throws OCSException + * @throws Share\Exceptions\ShareNotFound + * @throws \OC\HintException */ public function acceptShare($id) { - if (!$this->isS2SEnabled()) { - throw new OCSException('Server does not support federated cloud sharing', 503); - } - $token = isset($_POST['token']) ? $_POST['token'] : null; - try { - $share = $this->federatedShareProvider->getShareById($id); - } catch (Share\Exceptions\ShareNotFound $e) { - return new Http\DataResponse(); - } + $notification = [ + 'sharedSecret' => $token, + 'message' => 'Recipient accept the share' + ]; - if ($this->verifyShare($share, $token)) { - $this->executeAcceptShare($share); - if ($share->getShareOwner() !== $share->getSharedBy()) { - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); - $remoteId = $this->federatedShareProvider->getRemoteId($share); - $this->notifications->sendAcceptShare($remote, $remoteId, $share->getToken()); - } + try { + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); + $provider->notificationReceived('SHARE_ACCEPTED', $id, $notification); + } catch (ProviderDoesNotExistsException $e) { + throw new OCSException('Server does not support federated cloud sharing', 503); + } catch (ShareNotFoundException $e) { + $this->logger->debug('Share not found: ' . $e->getMessage()); + } catch (\Exception $e) { + $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); } return new Http\DataResponse(); } - protected function executeAcceptShare(Share\IShare $share) { - $fileId = (int) $share->getNode()->getId(); - list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId); - - $event = \OC::$server->getActivityManager()->generateEvent(); - $event->setApp('files_sharing') - ->setType('remote_share') - ->setAffectedUser($this->getCorrectUid($share)) - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]]) - ->setObject('files', $fileId, $file) - ->setLink($link); - \OC::$server->getActivityManager()->publish($event); - } - /** * @NoCSRFRequired * @PublicPage @@ -364,20 +350,6 @@ class RequestHandlerController extends OCSController { } /** - * check if we are the initiator or the owner of a re-share and return the correct UID - * - * @param Share\IShare $share - * @return string - */ - protected function getCorrectUid(Share\IShare $share) { - if ($this->userManager->userExists($share->getShareOwner())) { - return $share->getShareOwner(); - } - - return $share->getSharedBy(); - } - - /** * @NoCSRFRequired * @PublicPage * @@ -549,24 +521,6 @@ class RequestHandlerController extends OCSController { } /** - * check if we got the right share - * - * @param Share\IShare $share - * @param string $token - * @return bool - */ - protected function verifyShare(Share\IShare $share, $token) { - if ( - $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE && - $share->getToken() === $token - ) { - return true; - } - - return false; - } - - /** * @NoCSRFRequired * @PublicPage * |