Skip to content

Commit

Permalink
Merge pull request #290 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/3.0.3
  • Loading branch information
LinneyS authored Oct 1, 2019
2 parents bcd4d31 + b68985c commit dce32a7
Show file tree
Hide file tree
Showing 22 changed files with 217 additions and 168 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 3.0.3
## Changed
- federated share saving fixed

## 3.0.1
## Added
- "save as" to the folder
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>ONLYOFFICE connector enables you to edit Office documents within ONLYOFFICE from the familiar web interface. This will create a new Open in ONLYOFFICE action within the document library for Office documents. This allows multiple users to collaborate in real time and to save back those changes to your file storage.</description>
<licence>agpl</licence>
<author>Ascensio System SIA</author>
<version>3.0.1</version>
<version>3.0.3</version>
<namespace>Onlyoffice</namespace>
<types>
<filesystem/>
Expand Down
2 changes: 1 addition & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
["name" => "callback#emptyfile", "url" => "/empty", "verb" => "GET"],
["name" => "callback#track", "url" => "/track", "verb" => "POST"],
["name" => "editor#index", "url" => "/{fileId}", "verb" => "GET"],
["name" => "editor#public_page", "url" => "/s/{token}", "verb" => "GET"],
["name" => "editor#public_page", "url" => "/s/{shareToken}", "verb" => "GET"],
["name" => "editor#config", "url" => "/ajax/config/{fileId}", "verb" => "GET"],
["name" => "editor#create", "url" => "/ajax/new", "verb" => "POST"],
["name" => "editor#convert", "url" => "/ajax/convert", "verb" => "POST"],
Expand Down
102 changes: 63 additions & 39 deletions controller/callbackcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function download($doc) {

list ($hashData, $error) = $this->crypt->ReadHash($doc);
if ($hashData === NULL) {
$this->logger->error("Download with empty or not correct hash: " . $error, array("app" => $this->appName));
$this->logger->error("Download with empty or not correct hash: $error", array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Access denied")], Http::STATUS_FORBIDDEN);
}
if ($hashData->action !== "download") {
Expand All @@ -188,7 +188,7 @@ public function download($doc) {
}

$fileId = $hashData->fileId;
$this->logger->debug("Download: " . $fileId, array("app" => $this->appName));
$this->logger->debug("Download: $fileId", array("app" => $this->appName));

if (!$this->userSession->isLoggedIn()) {
if (!empty($this->config->GetDocumentServerSecret())) {
Expand All @@ -212,11 +212,20 @@ public function download($doc) {
if ($this->userSession->isLoggedIn()) {
$userId = $this->userSession->getUser()->getUID();
} else {
$userId = $hashData->userId;
$userId = $hashData->ownerId;

if (empty($this->userManager->get($userId))) {
$userId = $hashData->userId;
}

\OC_Util::tearDownFS();
if (!empty($userId)) {
\OC_Util::setupFS($userId);
}
}

$token = isset($hashData->token) ? $hashData->token : NULL;
list ($file, $error) = empty($token) ? $this->getFile($userId, $fileId) : $this->getFileByToken($fileId, $token);
$shareToken = isset($hashData->shareToken) ? $hashData->shareToken : NULL;
list ($file, $error) = empty($shareToken) ? $this->getFile($userId, $fileId) : $this->getFileByToken($fileId, $shareToken);

if (isset($error)) {
return $error;
Expand All @@ -230,7 +239,7 @@ public function download($doc) {
try {
return new DataDownloadResponse($file->getContent(), $file->getName(), $file->getMimeType());
} catch (NotPermittedException $e) {
$this->logger->error("Download Not permitted: " . $fileId . " " . $e->getMessage(), array("app" => $this->appName));
$this->logger->error("Download Not permitted: $fileId " . $e->getMessage(), array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Not permitted")], Http::STATUS_FORBIDDEN);
}
return new JSONResponse(["message" => $this->trans->t("Download failed")], Http::STATUS_INTERNAL_SERVER_ERROR);
Expand All @@ -253,7 +262,7 @@ public function emptyfile($doc) {

list ($hashData, $error) = $this->crypt->ReadHash($doc);
if ($hashData === NULL) {
$this->logger->error("Download empty with empty or not correct hash: " . $error, array("app" => $this->appName));
$this->logger->error("Download empty with empty or not correct hash: $error", array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Access denied")], Http::STATUS_FORBIDDEN);
}
if ($hashData->action !== "empty") {
Expand Down Expand Up @@ -282,14 +291,14 @@ public function emptyfile($doc) {

$template = file_get_contents($templatePath);
if (!$template) {
$this->logger->info("Template for download empty not found: " . $templatePath, array("app" => $this->appName));
$this->logger->info("Template for download empty not found: $templatePath", array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("File not found")], Http::STATUS_NOT_FOUND);
}

try {
return new DataDownloadResponse($template, "new.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
} catch (NotPermittedException $e) {
$this->logger->error("Download Not permitted: " . $fileId . " " . $e->getMessage(), array("app" => $this->appName));
$this->logger->error("Download Not permitted: $fileId " . $e->getMessage(), array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Not permitted")], Http::STATUS_FORBIDDEN);
}
return new JSONResponse(["message" => $this->trans->t("Download failed")], Http::STATUS_INTERNAL_SERVER_ERROR);
Expand All @@ -303,7 +312,7 @@ public function emptyfile($doc) {
* @param string $key - the edited document identifier
* @param integer $status - the edited status
* @param string $url - the link to the edited document to be saved
* @param string $token - access token
* @param string $token - request signature
*
* @return array
*
Expand All @@ -316,7 +325,7 @@ public function track($doc, $users, $key, $status, $url, $token) {

list ($hashData, $error) = $this->crypt->ReadHash($doc);
if ($hashData === NULL) {
$this->logger->error("Track with empty or not correct hash: " . $error, array("app" => $this->appName));
$this->logger->error("Track with empty or not correct hash: $error", array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Access denied")], Http::STATUS_FORBIDDEN);
}
if ($hashData->action !== "track") {
Expand All @@ -325,7 +334,7 @@ public function track($doc, $users, $key, $status, $url, $token) {
}

$fileId = $hashData->fileId;
$this->logger->debug("Track: " . $fileId . " status " . $status, array("app" => $this->appName));
$this->logger->debug("Track: $fileId status $status", array("app" => $this->appName));

if (!empty($this->config->GetDocumentServerSecret())) {
if (!empty($token)) {
Expand Down Expand Up @@ -367,39 +376,44 @@ public function track($doc, $users, $key, $status, $url, $token) {
case "MustSave":
case "Corrupted":
if (empty($url)) {
$this->logger->error("Track without url: " . $fileId . " status " . $trackerStatus, array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("Url not found")], Http::STATUS_BAD_REQUEST);
$this->logger->error("Track without url: $fileId status $trackerStatus", array("app" => $this->appName));
return new JSONResponse(["message" => "Url not found"], Http::STATUS_BAD_REQUEST);
}

try {
$ownerId = $hashData->ownerId;
$token = isset($hashData->token) ? $hashData->token : NULL;
if (empty($ownerId) && empty($token)) {
$this->logger->error("Track without owner: " . $fileId . " status " . $trackerStatus, array("app" => $this->appName));
return new JSONResponse(["message" => $this->trans->t("File owner is empty")], Http::STATUS_BAD_REQUEST);
}
$shareToken = isset($hashData->shareToken) ? $hashData->shareToken : NULL;

$userId = $users[0];
$user = $this->userManager->get($userId);
if (!empty($user)) {
$this->userSession->setUser($user);
} else {
$this->logger->debug("Track by anonymous " . $userId, array("app" => $this->appName));
if (empty($shareToken)) {
$this->logger->error("Track without access: $fileId status $trackerStatus", array("app" => $this->appName));
return new JSONResponse(["message" => "User and token is empty"], Http::STATUS_BAD_REQUEST);
}

$this->logger->debug("Track by anonymous userId", array("app" => $this->appName));
}

if ($this->config->checkEncryptionModule() === "master") {
\OC_User::setIncognitoMode(true);
}

$ownerId = $hashData->ownerId;
if (!empty($this->userManager->get($ownerId))) {
$userId = $ownerId;
}

\OC_Util::tearDownFS();
if (!empty($ownerId)) {
\OC_Util::setupFS($ownerId);
if (!empty($userId)) {
\OC_Util::setupFS($userId);
}

list ($file, $error) = !empty($ownerId) ? $this->getFile($ownerId, $fileId) : $this->getFileByToken($fileId, $token);
list ($file, $error) = empty($shareToken) ? $this->getFile($userId, $fileId) : $this->getFileByToken($fileId, $shareToken);

if (isset($error)) {
$this->logger->error("track error" . $fileId ." " . json_encode($error->getData()), array("app" => $this->appName));
$this->logger->error("track error: $fileId " . json_encode($error->getData()), array("app" => $this->appName));
return $error;
}

Expand All @@ -414,7 +428,7 @@ public function track($doc, $users, $key, $status, $url, $token) {
$key = DocumentService::GenerateRevisionId($fileId . $url);

try {
$this->logger->debug("Converted from " . $downloadExt . " to " . $curExt, array("app" => $this->appName));
$this->logger->debug("Converted from $downloadExt to $curExt", array("app" => $this->appName));
$url = $documentService->GetConvertedUri($url, $downloadExt, $curExt, $key);
} catch (\Exception $e) {
$this->logger->error("Converted on save error: " . $e->getMessage(), array("app" => $this->appName));
Expand All @@ -428,7 +442,7 @@ public function track($doc, $users, $key, $status, $url, $token) {
$file->putContent($newData);
$result = 0;
} catch (\Exception $e) {
$this->logger->error("Track " . $trackerStatus . " error: " . $e->getMessage(), array("app" => $this->appName));
$this->logger->error("Track $trackerStatus error: " . $e->getMessage(), array("app" => $this->appName));
}
break;

Expand All @@ -438,7 +452,7 @@ public function track($doc, $users, $key, $status, $url, $token) {
break;
}

$this->logger->debug("Track: " . $fileId . " status " . $status . " result " . $result, array("app" => $this->appName));
$this->logger->debug("Track: $fileId status $status result $result", array("app" => $this->appName));

return new JSONResponse(["error" => $result], Http::STATUS_OK);
}
Expand All @@ -457,16 +471,21 @@ private function getFile($userId, $fileId) {
return [NULL, new JSONResponse(["message" => $this->trans->t("FileId is empty")], Http::STATUS_BAD_REQUEST)];
}

$files = $this->root->getUserFolder($userId)->getById($fileId);
try {
$files = $this->root->getUserFolder($userId)->getById($fileId);
} catch (\Exception $e) {
$this->logger->error("getFile: $fileId " . $e->getMessage(), array("app" => $this->appName));
return [NULL, new JSONResponse(["message" => $this->trans->t("Invalid request")], Http::STATUS_BAD_REQUEST)];
}

if (empty($files)) {
$this->logger->error("Files not found: " . $fileId, array("app" => $this->appName));
$this->logger->error("Files not found: $fileId", array("app" => $this->appName));
return [NULL, new JSONResponse(["message" => $this->trans->t("Files not found")], Http::STATUS_NOT_FOUND)];
}
$file = $files[0];

if (!($file instanceof File)) {
$this->logger->error("File not found: " . $fileId, array("app" => $this->appName));
$this->logger->error("File not found: $fileId", array("app" => $this->appName));
return [NULL, new JSONResponse(["message" => $this->trans->t("File not found")], Http::STATUS_NOT_FOUND)];
}

Expand All @@ -477,12 +496,12 @@ private function getFile($userId, $fileId) {
* Getting file by token
*
* @param integer $fileId - file identifier
* @param string $token - access token
* @param string $shareToken - access token
*
* @return array
*/
private function getFileByToken($fileId, $token) {
list ($share, $error) = $this->getShare($token);
private function getFileByToken($fileId, $shareToken) {
list ($share, $error) = $this->getShare($shareToken);

if (isset($error)) {
return [NULL, $error];
Expand All @@ -496,7 +515,12 @@ private function getFileByToken($fileId, $token) {
}

if ($node instanceof Folder) {
$files = $node->getById($fileId);
try {
$files = $node->getById($fileId);
} catch (\Exception $e) {
$this->logger->error("getFileByToken: $fileId " . $e->getMessage(), array("app" => $this->appName));
return [NULL, new JSONResponse(["message" => $this->trans->t("Invalid request")], Http::STATUS_NOT_FOUND)];
}

if (empty($files)) {
return [NULL, new JSONResponse(["message" => $this->trans->t("File not found")], Http::STATUS_NOT_FOUND)];
Expand All @@ -512,18 +536,18 @@ private function getFileByToken($fileId, $token) {
/**
* Getting share by token
*
* @param string $token - access token
* @param string $shareToken - access token
*
* @return array
*/
private function getShare($token) {
if (empty($token)) {
private function getShare($shareToken) {
if (empty($shareToken)) {
return [NULL, new JSONResponse(["message" => $this->trans->t("FileId is empty")], Http::STATUS_BAD_REQUEST)];
}

$share;
try {
$share = $this->shareManager->getShareByToken($token);
$share = $this->shareManager->getShareByToken($shareToken);
} catch (ShareNotFound $e) {
$this->logger->error("getShare error: " . $e->getMessage(), array("app" => $this->appName));
$share = NULL;
Expand Down
Loading

0 comments on commit dce32a7

Please sign in to comment.