/** * Delete a share * * @param IShare $share */ public function delete(IShare $share) { $qb = $this->dbConnection->getQueryBuilder(); $qb->delete('share')->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))); $qb->execute(); list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith()); $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken()); }
/** * send server-to-server share to remote server * * @param string $token * @param string $shareWith * @param string $name * @param int $remote_id * @param string $owner * @return bool */ public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner) { list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); if ($user && $remote) { $url = $remote; $local = $this->addressHandler->generateRemoteURL(); $fields = array('shareWith' => $user, 'token' => $token, 'name' => $name, 'remoteId' => $remote_id, 'owner' => $owner, 'remote' => $local); $url = $this->addressHandler->removeProtocolFromUrl($url); $result = $this->tryHttpPostToShareEndpoint($url, '', $fields); $status = json_decode($result['result'], true); if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) { \OC_Hook::emit('OCP\\Share', 'federated_share_added', ['server' => $remote]); return true; } } return false; }
/** * in case of a re-share we need to send the other use (initiator or owner) * a message that the file was unshared * * @param IShare $share * @param bool $isOwner the user can either be the owner or the user who re-sahred it * @throws ShareNotFound * @throws \OC\HintException */ protected function revokeShare($share, $isOwner) { // also send a unShare request to the initiator, if this is a different user than the owner if ($share->getShareOwner() !== $share->getSharedBy()) { if ($isOwner) { list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); } else { list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); } $remoteId = $this->getRemoteId($share); $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); } }
/** * decline server-to-server share * * @param array $params * @return \OC_OCS_Result */ public function declineShare($params) { if (!$this->isS2SEnabled()) { return new \OC_OCS_Result(null, 503, 'Server does not support federated cloud sharing'); } $id = (int) $params['id']; $token = isset($_POST['token']) ? $_POST['token'] : null; try { $share = $this->federatedShareProvider->getShareById($id); } catch (Share\Exceptions\ShareNotFound $e) { return new \OC_OCS_Result(); } if ($this->verifyShare($share, $token)) { if ($share->getShareOwner() !== $share->getSharedBy()) { list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); $remoteId = $this->federatedShareProvider->getRemoteId($share); $this->notifications->sendDeclineShare($remote, $remoteId, $share->getToken()); } $this->executeDeclineShare($share); } return new \OC_OCS_Result(); }
/** * @dataProvider dataTestSplitUserRemoteError * * @param string $id * @expectedException \OC\HintException */ public function testSplitUserRemoteError($id) { $this->addressHandler->splitUserRemote($id); }