Skip to content

Commit

Permalink
Merge pull request #332 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/6.2.1
  • Loading branch information
LinneyS authored Dec 9, 2020
2 parents e075967 + b719e55 commit b805d7f
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 23 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

## 6.2.1
## Changed
- the ability to use forcesave for federated share files

## 6.1.1
## Added
- connection test command
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 allows you to view, edit and collaborate on text documents, spreadsheets and presentations within ownCloud using ONLYOFFICE Docs. This will create a new Edit in ONLYOFFICE action within the document library for Office documents. This allows multiple users to co-author documents in real time from the familiar web interface and save the changes back to your file storage.</description>
<licence>apl2</licence>
<author>Ascensio System SIA</author>
<version>6.1.1</version>
<version>6.2.1</version>
<namespace>Onlyoffice</namespace>
<types>
<filesystem/>
Expand Down
3 changes: 2 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
["name" => "settings#get_settings", "url" => "/ajax/settings", "verb" => "GET"],
],
"ocs" => [
["name" => "federation#key", "url" => "/api/v1/key", "verb" => "POST"]
["name" => "federation#key", "url" => "/api/v1/key", "verb" => "POST"],
["name" => "federation#keylock", "url" => "/api/v1/keylock", "verb" => "POST"]
]
];
25 changes: 15 additions & 10 deletions controller/callbackcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,23 +518,28 @@ public function track($doc, $users, $key, $status, $url, $token, $history, $chan

$isForcesave = $status === self::TrackerStatus_ForceSave || $status === self::TrackerStatus_CorruptedForceSave;

if ($isForcesave
&& $file->getStorage()->instanceOfStorage(SharingExternalStorage::class)) {
$this->logger->info("Track: $fileId status $status not allowed for external file", ["app" => $this->appName]);
break;
if ($file->getStorage()->instanceOfStorage(SharingExternalStorage::class)) {
$isLock = KeyManager::lockFederatedKey($file, $isForcesave, null);
if ($isForcesave && !$isLock) {
break;
}
} else {
KeyManager::lock($fileId, $isForcesave);
}

//lock the key when forcesave and unlock if last forcesave is broken
KeyManager::lock($fileId, $isForcesave);

$this->logger->debug("Track put content " . $file->getPath(), ["app" => $this->appName]);
$this->retryOperation(function () use ($file, $newData) {
return $file->putContent($newData);
});

//unlock key for future federated save
KeyManager::lock($fileId, false);
KeyManager::setForcesave($fileId, $isForcesave);
if ($file->getStorage()->instanceOfStorage(SharingExternalStorage::class)) {
if ($isForcesave) {
KeyManager::lockFederatedKey($file, false, $isForcesave);
}
} else {
KeyManager::lock($fileId, false);
KeyManager::setForcesave($fileId, $isForcesave);
}

if (!$isForcesave
&& !$prevIsForcesave
Expand Down
5 changes: 0 additions & 5 deletions controller/editorcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,11 +988,6 @@ public function config($fileId, $filePath = null, $shareToken = null, $version =

$params = $this->setCustomization($params);

if ($file->getStorage()->instanceOfStorage(SharingExternalStorage::class)) {
//otherwise forcesave will delete the key
$params["editorConfig"]["customization"]["forcesave"] = false;
}

if ($this->config->UseDemo()) {
$params["editorConfig"]["tenant"] = $this->config->GetSystemValue("instanceid", true);
}
Expand Down
43 changes: 43 additions & 0 deletions controller/federationcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@

use OC\OCS\Result;

use OCA\Files_Sharing\External\Storage as SharingExternalStorage;

use OCA\Onlyoffice\AppConfig;
use OCA\Onlyoffice\DocumentService;
use OCA\Onlyoffice\FileUtility;
use OCA\Onlyoffice\KeyManager;

/**
* OCS handler
Expand Down Expand Up @@ -109,4 +112,44 @@ public function key($shareToken, $path) {

return new Result(["key" => $key]);
}

/**
* Lock the origin document key for editor
*
* @param string $shareToken - access token
* @param string $path - file path
* @param bool $lock - status
* @param bool $fs - status
*
* @return Result
*
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
*/
public function keylock($shareToken, $path, $lock, $fs) {
list ($file, $error, $share) = $this->fileUtility->getFileByToken(null, $shareToken, $path);

if (isset($error)) {
$this->logger->error("Federated getFileByToken: $error", ["app" => $this->appName]);
return new Result(["error" => $error]);
}

$fileId = $file->getId();

if ($file->getStorage()->instanceOfStorage(SharingExternalStorage::class)) {
$isLock = KeyManager::lockFederatedKey($file, $lock, $fs);
if (!$isLock) {
return new Result(["error" => "Failed request"]);
}
} else {
KeyManager::lock($fileId, $lock);
if (!empty($fs)) {
KeyManager::setForcesave($fileId, $fs);
}
}

$this->logger->debug("Federated request lock for " . $fileId, ["app" => $this->appName]);
return new Result();
}
}
9 changes: 3 additions & 6 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@
OCA.Onlyoffice.folderUrl = null;
}

if (OCA.Versions) {
OCA.Onlyoffice.bindVersionClick();
}
OCA.Onlyoffice.bindVersionClick();
};

OCA.Onlyoffice.OpenShareDialog = function () {
Expand Down Expand Up @@ -390,9 +388,8 @@
OC.Plugins.register("OCA.Files.FileList", OCA.Onlyoffice.FileList);
OC.Plugins.register("OCA.Files.NewFileMenu", OCA.Onlyoffice.NewFileMenu);

if (OCA.Versions) {
OCA.Onlyoffice.bindVersionClick();
}
OCA.Onlyoffice.bindVersionClick();

if (OCA.Onlyoffice.Share) {
OCA.Onlyoffice.Share();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public static function fileUpdate($params) {
$fileId = $fileInfo->getId();

KeyManager::delete($fileId);

\OC::$server->getLogger()->debug("Hook fileUpdate " . json_encode($params), ["app" => self::$appName]);
}

/**
Expand Down
58 changes: 58 additions & 0 deletions lib/keymanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace OCA\Onlyoffice;

use OCP\Files\File;

/**
* Key manager
Expand All @@ -27,6 +28,11 @@
*/
class KeyManager {

/**
* App name
*/
private const App_Name = "onlyoffice";

/**
* Table name
*/
Expand Down Expand Up @@ -147,4 +153,56 @@ public static function wasForcesave($fileId) {

return $fs === "1";
}

/**
* Change lock status in the federated share
*
* @param File $file - file
* @param bool $lock - status
* @param bool $fs - status
*
* @return bool
*/
public static function lockFederatedKey($file, $lock, $fs) {
$logger = \OC::$server->getLogger();
$action = $lock ? "lock" : "unlock";

$remote = $file->getStorage()->getRemote();
$shareToken = $file->getStorage()->getToken();
$internalPath = $file->getInternalPath();

$httpClientService = \OC::$server->getHTTPClientService();
$client = $httpClientService->newClient();
$data = [
"timeout" => 5,
"body" => [
"shareToken" => $shareToken,
"path" => $internalPath,
"lock" => $lock
]
];
if (!empty($fs)) {
$data["body"]["fs"] = $fs;
}

try {
$response = $client->post($remote . "/ocs/v2.php/apps/" . self::App_Name . "/api/v1/keylock?format=json", $data);
$body = \json_decode($response->getBody(), true);

$data = $body["ocs"]["data"];

if (empty($data)) {
$logger->debug("Federated request" . $action . "for " . $file->getFileInfo()->getId() . " is successful", ["app" => self::App_Name]);
return true;
}

if (!empty($data["error"])) {
$logger->error("Error" . $action . "federated key for " . $file->getFileInfo()->getId() . ": " . $data["error"], ["app" => self::App_Name]);
return false;
}
} catch(\Exception $e) {
$logger->logException($e, ["message" => "Failed to request federated " . $action . " for " . $file->getFileInfo()->getId(), "app" => self::App_Name]);
return false;
}
}
}

0 comments on commit b805d7f

Please sign in to comment.