Skip to content

Commit

Permalink
Merge pull request #295 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/4.0.1
  • Loading branch information
LinneyS authored Dec 16, 2019
2 parents dce32a7 + 4157faf commit efa54f1
Show file tree
Hide file tree
Showing 22 changed files with 1,338 additions and 285 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## 4.0.1
## Added
- Polish translation
- British (en_GB) file templates

## Changed
- co-editing for federated share
- Advanced Sharing Permissions APIv2

## 3.0.3
## Changed
- federated share saving fixed
Expand Down
2 changes: 1 addition & 1 deletion appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
*/
App::registerAdmin("onlyoffice", "settings");

$app = new Application();
$app = \OC::$server->query(Application::class);
6 changes: 4 additions & 2 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function() {
&& $this->appConfig->isUserAllowedToUse()) {
Util::addScript("onlyoffice", "desktop");
Util::addScript("onlyoffice", "main");
Util::addScript("onlyoffice", "share");
Util::addStyle("onlyoffice", "main");
}
});
Expand Down Expand Up @@ -132,7 +133,8 @@ function() {
$this->appConfig,
$this->crypt,
$c->query("IManager"),
$c->query("Session")
$c->query("Session"),
$c->query("ClientService")
);
});

Expand All @@ -151,4 +153,4 @@ function() {
);
});
}
}
}
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.3</version>
<version>4.0.1</version>
<namespace>Onlyoffice</namespace>
<types>
<filesystem/>
Expand Down
5 changes: 4 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@
["name" => "settings#save_address", "url" => "/ajax/settings/address", "verb" => "PUT"],
["name" => "settings#save_common", "url" => "/ajax/settings/common", "verb" => "PUT"],
["name" => "settings#get_settings", "url" => "/ajax/settings", "verb" => "GET"],
],
"ocs" => [
["name" => "federation#key", "url" => "/api/v1/key", "verb" => "POST"]
]
];
];
Binary file added assets/en_GB/new.docx
Binary file not shown.
Binary file added assets/en_GB/new.pptx
Binary file not shown.
Binary file added assets/en_GB/new.xlsx
Binary file not shown.
106 changes: 86 additions & 20 deletions controller/callbackcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Lock\LockedException;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;

Expand Down Expand Up @@ -212,14 +213,13 @@ public function download($doc) {
if ($this->userSession->isLoggedIn()) {
$userId = $this->userSession->getUser()->getUID();
} else {
$userId = $hashData->ownerId;
\OC_Util::tearDownFS();

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

\OC_Util::tearDownFS();
if (!empty($userId)) {
$user = $this->userManager->get($userId);
if (!empty($user)) {
\OC_Util::setupFS($userId);
}
}
Expand Down Expand Up @@ -382,35 +382,51 @@ public function track($doc, $users, $key, $status, $url, $token) {

try {
$shareToken = isset($hashData->shareToken) ? $hashData->shareToken : NULL;
$filePath = null;

\OC_Util::tearDownFS();

// author of the latest changes
$userId = $this->parseUserId($users[0]);
\OC_User::setUserId($userId);

$userId = $users[0];
$user = $this->userManager->get($userId);
if (!empty($user)) {
$this->userSession->setUser($user);
} else {
if (empty($user)) {
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 without token: $fileId status $trackerStatus", array("app" => $this->appName));
} else {
$this->logger->debug("Track $fileId by token for $userId", array("app" => $this->appName));
}

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

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

// owner of file from the callback link
$ownerId = $hashData->ownerId;
if (!empty($this->userManager->get($ownerId))) {
$owner = $this->userManager->get($ownerId);

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

if (!empty($callbackUser)) {
// author of the callback link
$userId = $callbackUserId;

// path for author of the callback link
$filePath = $hashData->filePath;
}
}

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

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

if (isset($error)) {
$this->logger->error("track error: $fileId " . json_encode($error->getData()), array("app" => $this->appName));
Expand Down Expand Up @@ -439,7 +455,10 @@ public function track($doc, $users, $key, $status, $url, $token) {
$newData = $documentService->Request($url);

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

$result = 0;
} catch (\Exception $e) {
$this->logger->error("Track $trackerStatus error: " . $e->getMessage(), array("app" => $this->appName));
Expand All @@ -463,10 +482,11 @@ public function track($doc, $users, $key, $status, $url, $token) {
*
* @param string $userId - user identifier
* @param integer $fileId - file identifier
* @param string $filePath - file path
*
* @return array
*/
private function getFile($userId, $fileId) {
private function getFile($userId, $fileId, $filePath = NULL) {
if (empty($fileId)) {
return [NULL, new JSONResponse(["message" => $this->trans->t("FileId is empty")], Http::STATUS_BAD_REQUEST)];
}
Expand All @@ -482,8 +502,19 @@ private function getFile($userId, $fileId) {
$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 (count($files) > 1 && !empty($filePath)) {
$filePath = "/" . $userId . "/files" . $filePath;
foreach ($files as $curFile) {
if ($curFile->getPath() === $filePath) {
$file = $curFile;
break;
}
}
}

if (!($file instanceof File)) {
$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 Down Expand Up @@ -559,4 +590,39 @@ private function getShare($shareToken) {

return [$share, NULL];
}
}

/**
* Parse user identifier for current instance
*
* @param string $userId - unique user identifier
*
* @return string
*/
private function parseUserId($uniqueUserId) {
$instanceId = $this->config->GetSystemValue("instanceid", true);
$userId = ltrim($uniqueUserId, $instanceId . "_");
return $userId;
}

/**
* Retry operation if a LockedException occurred
* Other exceptions will still be thrown
*
* @param callable $operation
*
* @throws LockedException
*/
private function retryOperation(callable $operation) {
$i = 0;
while (true) {
try {
return $operation();
} catch (LockedException $e) {
if (++$i === 4) {
throw $e;
}
}
usleep(500000);
}
}
}
Loading

0 comments on commit efa54f1

Please sign in to comment.