/** * create re-share on behalf of another user * * @param $params * @return \OC_OCS_Result */ public function reShare($params) { $id = isset($params['id']) ? (int) $params['id'] : null; $token = $this->request->getParam('token', null); $shareWith = $this->request->getParam('shareWith', null); $permission = (int) $this->request->getParam('permission', null); $remoteId = (int) $this->request->getParam('remoteId', null); if ($id === null || $token === null || $shareWith === null || $permission === null || $remoteId === null) { return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST); } try { $share = $this->federatedShareProvider->getShareById($id); } catch (Share\Exceptions\ShareNotFound $e) { return new \OC_OCS_Result(null, Http::STATUS_NOT_FOUND); } // don't allow to share a file back to the owner list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); $owner = $share->getShareOwner(); $currentServer = $this->addressHandler->generateRemoteURL(); if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) { return new \OC_OCS_Result(null, Http::STATUS_FORBIDDEN); } if ($this->verifyShare($share, $token)) { // check if re-sharing is allowed if ($share->getPermissions() | ~Constants::PERMISSION_SHARE) { $share->setPermissions($share->getPermissions() & $permission); // the recipient of the initial share is now the initiator for the re-share $share->setSharedBy($share->getSharedWith()); $share->setSharedWith($shareWith); try { $result = $this->federatedShareProvider->create($share); $this->federatedShareProvider->storeRemoteId((int) $result->getId(), $remoteId); return new \OC_OCS_Result(['token' => $result->getToken(), 'remoteId' => $result->getId()]); } catch (\Exception $e) { return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST); } } else { return new \OC_OCS_Result(null, Http::STATUS_FORBIDDEN); } } return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST); }