/** * send server-to-server unshare to remote server * * @param string $remote url * @param int $id share id * @param string $token * @return bool */ public function sendRemoteUnShare($remote, $id, $token) { $url = rtrim($remote, '/'); $fields = array('token' => $token, 'format' => 'json'); $url = $this->addressHandler->removeProtocolFromUrl($url); $result = $this->tryHttpPostToShareEndpoint($url, '/' . $id . '/unshare', $fields); $status = json_decode($result['result'], true); return $result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); }
/** * send server-to-server unshare to remote server * * @param string $remote url * @param int $id share id * @param string $token * @return bool */ public function sendRemoteUnShare($remote, $id, $token) { $url = rtrim($remote, '/') . self::BASE_PATH_TO_SHARE_API . '/' . $id . '/unshare?format=' . self::RESPONSE_FORMAT; $fields = array('token' => $token, 'format' => 'json'); $url = $this->addressHandler->removeProtocolFromUrl($url); $result = $this->tryHttpPost($url, $fields); $status = json_decode($result['result'], true); return $result['success'] && $status['ocs']['meta']['statuscode'] === 100; }
/** * send server-to-server unshare to remote server * * @param string $remote url * @param int $id share id * @param string $token * @param int $try how often did we already tried to send the un-share request * @return bool */ public function sendRemoteUnShare($remote, $id, $token, $try = 0) { $url = rtrim($remote, '/'); $fields = array('token' => $token, 'format' => 'json'); $url = $this->addressHandler->removeProtocolFromUrl($url); $result = $this->tryHttpPostToShareEndpoint($url, '/' . $id . '/unshare', $fields); $status = json_decode($result['result'], true); if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) { return true; } elseif ($try === 0) { // only add new job on first try $this->jobList->add('OCA\\FederatedFileSharing\\BackgroundJob\\UnShare', ['remote' => $remote, 'id' => $id, 'token' => $token, 'try' => $try, 'lastRun' => $this->getTimestamp()]); } return false; }
/** * inform remote server whether server-to-server share was accepted/declined * * @param string $remote * @param string $token * @param int $remoteId Share id on the remote host * @param string $action possible actions: accept, decline, unshare, revoke, permissions * @param array $data * @param int $try * @return boolean */ public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { $fields = array('token' => $token); foreach ($data as $key => $value) { $fields[$key] = $value; } $url = $this->addressHandler->removeProtocolFromUrl($remote); $result = $this->tryHttpPostToShareEndpoint(rtrim($url, '/'), '/' . $remoteId . '/' . $action, $fields); $status = json_decode($result['result'], true); if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) { return true; } elseif ($try === 0) { // only add new job on first try $this->jobList->add('OCA\\FederatedFileSharing\\BackgroundJob\\RetryJob', ['remote' => $remote, 'remoteId' => $remoteId, 'token' => $token, 'action' => $action, 'data' => json_encode($data), 'try' => $try, 'lastRun' => $this->getTimestamp()]); } return false; }
/** * @dataProvider dataTestRemoveProtocolFromUrl * * @param string $url * @param string $expectedResult */ public function testRemoveProtocolFromUrl($url, $expectedResult) { $result = $this->addressHandler->removeProtocolFromUrl($url); $this->assertSame($expectedResult, $result); }