Пример #1
0
 protected function actionReceive($parameters)
 {
     $targetUser = \AJXP_Utils::sanitize($parameters["shareWith"], AJXP_SANITIZE_EMAILCHARS);
     if (!\AuthService::userExists($targetUser)) {
         throw new UserNotFoundException();
     }
     $token = \AJXP_Utils::sanitize($parameters["token"], AJXP_SANITIZE_ALPHANUM);
     $remoteId = \AJXP_Utils::sanitize($parameters["remoteId"], AJXP_SANITIZE_ALPHANUM);
     $documentName = \AJXP_Utils::sanitize($parameters["name"], AJXP_SANITIZE_FILENAME);
     $sender = \AJXP_Utils::sanitize($parameters["owner"], AJXP_SANITIZE_EMAILCHARS);
     $remote = $parameters["remote"];
     $testParts = parse_url($remote);
     if (!is_array($testParts) || empty($testParts["scheme"]) || empty($testParts["host"])) {
         throw new InvalidArgumentsException();
     }
     $endpoints = OCSClient::findEndpointsForURL($remote);
     $share = new RemoteShare();
     $share->setUser($targetUser);
     $share->setOcsRemoteId($remoteId);
     $share->setOcsToken($token);
     $share->setDocumentName($documentName);
     $share->setSender($sender);
     $share->setReceptionDate(time());
     $share->setStatus(OCS_INVITATION_STATUS_PENDING);
     $share->setHost(rtrim($remote, '/'));
     $share->setOcsServiceUrl(rtrim($remote, '/') . $endpoints['share']);
     $share->setOcsDavUrl(rtrim($remote, '/') . $endpoints['webdav']);
     $share->pingRemoteDAVPoint();
     $store = new SQLStore();
     $newShare = $store->storeRemoteShare($share);
     $response = $this->buildResponse("ok", 200, "Successfully received share, waiting for user response.", array("id" => $newShare->getId()));
     $this->sendResponse($response, $this->getFormat($parameters));
     $userRole = \AuthService::getRole("AJXP_USR_/" . $targetUser);
     if ($userRole !== false) {
         // Artificially "touch" user role
         // to force repositories reload if he is logged in
         \AuthService::updateRole($userRole);
     }
 }