Skip to content

Commit

Permalink
Merge pull request #331 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/6.1.1
  • Loading branch information
LinneyS authored Nov 3, 2020
2 parents 4354f08 + 7afbaff commit e075967
Show file tree
Hide file tree
Showing 44 changed files with 1,184 additions and 189 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## 6.1.1
## Added
- connection test command
- store author name for version
- generate file preview
- Italian translation

## Changed
- display local time in history

## 6.0.1
## Added
- saving intermediate versions when editing
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ Enable or disable the _Open file in the same tab_ setting.
The **Open in ONLYOFFICE** action will be added to the file context menu.
You can specify this action as default and it will be used when the file name is clicked for the selected file types.

## Checking the connection

You can check the connection to ONLYOFFICE Document Server by using the following occ command:

`occ onlyoffice:documentserver --check`

You will see a text either with information about the successful connection or the cause of the error.

## How it works

The ONLYOFFICE integration follows the API documented [here](https://api.onlyoffice.com/editors/basic):
Expand Down
8 changes: 7 additions & 1 deletion appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use OCP\AppFramework\App;
use OCP\Files\IMimeTypeDetector;
use OCP\Util;
use OCP\IPreview;

use OCA\Onlyoffice\AppConfig;
use OCA\Onlyoffice\Controller\CallbackController;
Expand All @@ -30,6 +31,7 @@
use OCA\Onlyoffice\Crypt;
use OCA\Onlyoffice\Hookhandler;
use OCA\Onlyoffice\Hooks;
use OCA\Onlyoffice\Preview;

class Application extends App {

Expand Down Expand Up @@ -85,10 +87,14 @@ function () {

$detector = $container->query(IMimeTypeDetector::class);
$detector->getAllMappings();
$detector->registerType("ott","application/vnd.oasis.opendocument.text-template");
$detector->registerType("ott", "application/vnd.oasis.opendocument.text-template");
$detector->registerType("ots", "application/vnd.oasis.opendocument.spreadsheet-template");
$detector->registerType("otp", "application/vnd.oasis.opendocument.presentation-template");

$previewManager = $container->query(IPreview::class);
$previewManager->registerProvider(Preview::getMimeTypeRegex(), function() use ($container) {
return $container->query(Preview::class);
});

$container->registerService("L10N", function ($c) {
return $c->query("ServerContainer")->getL10N($c->query("AppName"));
Expand Down
7 changes: 5 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<id>onlyoffice</id>
<name>ONLYOFFICE</name>
<summary>ONLYOFFICE connector</summary>
<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>
<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.0.1</version>
<version>6.1.1</version>
<namespace>Onlyoffice</namespace>
<types>
<filesystem/>
Expand All @@ -27,4 +27,7 @@
<dependencies>
<owncloud min-version="10" max-version="10" />
</dependencies>
<commands>
<command>OCA\Onlyoffice\Command\DocumentServer</command>
</commands>
</info>
19 changes: 17 additions & 2 deletions controller/callbackcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,11 @@ public function download($doc) {
}

$userId = null;

$user = null;
if ($this->userSession->isLoggedIn()) {
$userId = $this->userSession->getUser()->getUID();
$user = $this->userSession->getUser();
$userId = $user->getUID();
} else {
\OC_Util::tearDownFS();

Expand Down Expand Up @@ -246,6 +249,14 @@ public function download($doc) {
return new JSONResponse(["message" => $this->trans->t("Access denied")], Http::STATUS_FORBIDDEN);
}

if (empty($user)
&& $this->config->checkEncryptionModule() !== "master") {
$owner = $file->getFileInfo()->getOwner();
if ($owner !== null) {
\OC_Util::setupFS($owner->getUID());
}
}

if ($changes) {
if ($this->versionManager->available !== true) {
$this->logger->error("Download changes: versionManager is null", ["app" => $this->appName]);
Expand Down Expand Up @@ -527,7 +538,7 @@ public function track($doc, $users, $key, $status, $url, $token, $history, $chan

if (!$isForcesave
&& !$prevIsForcesave
&& $this->versionManager !== null) {
&& $this->versionManager->available) {
$changes = null;
if (!empty($changesurl)) {
$changesurl = $this->config->ReplaceDocumentServerUrlToInternal($changesurl);
Expand All @@ -536,6 +547,10 @@ public function track($doc, $users, $key, $status, $url, $token, $history, $chan
FileVersions::saveHistory($file->getFileInfo(), $history, $changes, $prevVersion);
}

if (!empty($user)) {
FileVersions::saveAuthor($file->getFileInfo(), $user);
}

$result = 0;
} catch (\Exception $e) {
$this->logger->logException($e, ["message" => "Track: $fileId status $status error", "app" => $this->appName]);
Expand Down
46 changes: 30 additions & 16 deletions controller/editorcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,16 @@ public function history($fileId, $shareToken = null) {
$fileId = $file->getId();
}

$owner = null;
$ownerId = null;
$owner = $file->getFileInfo()->getOwner();
if ($owner !== null) {
$ownerId = $owner->getUID();
}

$versions = array();
if ($this->versionManager->available) {
$owner = $file->getFileInfo()->getOwner();
if ($owner !== null) {
$ownerId = $owner->getUID();
$versions = array_reverse($this->versionManager->getVersionsForFile($owner, $file->getFileInfo()));
}
if ($this->versionManager->available
&& $owner !== null) {
$versions = array_reverse($this->versionManager->getVersionsForFile($owner, $file->getFileInfo()));
}

$prevVersion = "";
Expand All @@ -478,16 +479,22 @@ public function history($fileId, $shareToken = null) {
$key = DocumentService::GenerateRevisionId($key);

$historyItem = [
"created" => $this->trans->l("datetime", $version->getTimestamp(), ["width" => "short"]),
"created" => $version->getTimestamp(),
"key" => $key,
"user" => [
"id" => $this->buildUserId($ownerId),
"name" => $owner->getDisplayName()
],
"version" => $versionNum
];

$versionId = $version->getRevisionId();

$author = FileVersions::getAuthor($ownerId, $fileId, $versionId);
$authorId = $author !== null ? $author["id"] : $ownerId;
$authorName = $author !== null ? $author["name"] : $owner->getDisplayName();

$historyItem["user"] = [
"id" => $this->buildUserId($authorId),
"name" => $authorName
];

$historyData = FileVersions::getHistoryData($ownerId, $fileId, $versionId, $prevVersion);
if ($historyData !== null) {
$historyItem["changes"] = $historyData["changes"];
Expand All @@ -503,19 +510,26 @@ public function history($fileId, $shareToken = null) {
$key = DocumentService::GenerateRevisionId($key);

$historyItem = [
"created" => $this->trans->l("datetime", $file->getMTime(), ["width" => "short"]),
"created" => $file->getMTime(),
"key" => $key,
"version" => $versionNum + 1
];

if ($owner !== null) {
$versionId = $file->getFileInfo()->getMtime();

$author = FileVersions::getAuthor($ownerId, $fileId, $versionId);
if ($author !== null) {
$historyItem["user"] = [
"id" => $this->buildUserId($owner->getUID()),
"id" => $this->buildUserId($author["id"]),
"name" => $author["name"]
];
} else if ($owner !== null) {
$historyItem["user"] = [
"id" => $this->buildUserId($ownerId),
"name" => $owner->getDisplayName()
];
}

$versionId = $file->getFileInfo()->getMtime();
$historyData = FileVersions::getHistoryData($ownerId, $fileId, $versionId, $prevVersion);
if ($historyData !== null) {
$historyItem["changes"] = $historyData["changes"];
Expand Down
90 changes: 6 additions & 84 deletions controller/settingscontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function index() {
"currentServer" => $this->urlGenerator->getAbsoluteURL("/"),
"formats" => $this->config->FormatsSetting(),
"sameTab" => $this->config->GetSameTab(),
"preview" => $this->config->GetPreview(),
"encryption" => ($this->config->checkEncryptionModule() === true),
"limitGroups" => $this->config->GetLimitGroups(),
"chat" => $this->config->GetCustomizationChat(),
Expand Down Expand Up @@ -161,7 +162,8 @@ public function SaveAddress($documentserver,
if (empty($error)) {
$documentserver = $this->config->GetDocumentServerUrl();
if (!empty($documentserver)) {
list ($error, $version) = $this->checkDocServiceUrl();
$documentService = new DocumentService($this->trans, $this->config);
list ($error, $version) = $documentService->checkDocServiceUrl($this->urlGenerator, $this->crypt);
$this->config->SetSettingsError($error);
}

Expand All @@ -187,6 +189,7 @@ public function SaveAddress($documentserver,
* @param array $defFormats - formats array with default action
* @param array $editFormats - editable formats array
* @param bool $sameTab - open in the same tab
* @param bool $preview - generate preview files
* @param array $limitGroups - list of groups
* @param bool $chat - display chat
* @param bool $compactHeader - display compact header
Expand All @@ -201,6 +204,7 @@ public function SaveAddress($documentserver,
public function SaveCommon($defFormats,
$editFormats,
$sameTab,
$preview,
$limitGroups,
$chat,
$compactHeader,
Expand All @@ -214,6 +218,7 @@ public function SaveCommon($defFormats,
$this->config->SetDefaultFormats($defFormats);
$this->config->SetEditableFormats($editFormats);
$this->config->SetSameTab($sameTab);
$this->config->SetPreview($preview);
$this->config->SetLimitGroups($limitGroups);
$this->config->SetCustomizationChat($chat);
$this->config->SetCustomizationCompactHeader($compactHeader);
Expand Down Expand Up @@ -243,87 +248,4 @@ public function GetSettings() {
];
return $result;
}


/**
* Checking document service location
*
* @return array
*/
private function checkDocServiceUrl() {
$version = null;

try {

if (preg_match("/^https:\/\//i", $this->urlGenerator->getAbsoluteURL("/"))
&& preg_match("/^http:\/\//i", $this->config->GetDocumentServerUrl())) {
throw new \Exception($this->trans->t("Mixed Active Content is not allowed. HTTPS address for Document Server is required."));
}

} catch (\Exception $e) {
$this->logger->logException($e, ["message" => "Protocol on check error", "app" => $this->appName]);
return [$e->getMessage(), $version];
}

try {

$documentService = new DocumentService($this->trans, $this->config);

$healthcheckResponse = $documentService->HealthcheckRequest();
if (!$healthcheckResponse) {
throw new \Exception($this->trans->t("Bad healthcheck status"));
}

} catch (\Exception $e) {
$this->logger->logException($e, ["message" => "HealthcheckRequest on check error", "app" => $this->appName]);
return [$e->getMessage(), $version];
}

try {

$documentService = new DocumentService($this->trans, $this->config);

$commandResponse = $documentService->CommandRequest("version");

$this->logger->debug("CommandRequest on check: " . json_encode($commandResponse), ["app" => $this->appName]);

if (empty($commandResponse)) {
throw new \Exception($this->trans->t("Error occurred in the document service"));
}

$version = floatval($commandResponse->version);
if ($version > 0.0 && $version < 4.2) {
throw new \Exception($this->trans->t("Not supported version"));
}

} catch (\Exception $e) {
$this->logger->logException($e, ["message" => "CommandRequest on check error", "app" => $this->appName]);
return [$e->getMessage(), $version];
}

$convertedFileUri = null;
try {

$hashUrl = $this->crypt->GetHash(["action" => "empty"]);
$fileUrl = $this->urlGenerator->linkToRouteAbsolute($this->appName . ".callback.emptyfile", ["doc" => $hashUrl]);
if (!empty($this->config->GetStorageUrl())) {
$fileUrl = str_replace($this->urlGenerator->getAbsoluteURL("/"), $this->config->GetStorageUrl(), $fileUrl);
}

$convertedFileUri = $documentService->GetConvertedUri($fileUrl, "docx", "docx", "check_" . rand());

} catch (\Exception $e) {
$this->logger->logException($e, ["message" => "GetConvertedUri on check error", "app" => $this->appName]);
return [$e->getMessage(), $version];
}

try {
$documentService->Request($convertedFileUri);
} catch (\Exception $e) {
$this->logger->logException($e, ["message" => "Request converted file on check error", "app" => $this->appName]);
return [$e->getMessage(), $version];
}

return ["", $version];
}
}
5 changes: 5 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ body.onlyoffice-inline #content #app-content {
opacity: 1;
}

.onlyoffice-public-open {
display: inline-block;
margin-top: 10px;
}

/* AscDesktopEditor */
.AscDesktopEditor #header {
display: none;
Expand Down
7 changes: 7 additions & 0 deletions js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@
if (fileVersion.version >= currentVersion) {
currentVersion = fileVersion.version;
}

fileVersion.created = moment(fileVersion.created * 1000).format("L LTS");
if (fileVersion.changes) {
$.each(fileVersion.changes, function (j, change) {
change.created = moment(change.created + "+00:00").format("L LTS");
});
}
});

if (version) {
Expand Down
4 changes: 2 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,14 @@

var button = document.createElement("a");
button.href = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/" + encodeURIComponent($("#sharingToken").val()));
button.className = "button";
button.className = "onlyoffice-public-open button";
button.innerText = t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE")

if (!OCA.Onlyoffice.setting.sameTab) {
button.target = "_blank";
}

$("#preview").append(button);
$("#preview").prepend(button);
};

OCA.Onlyoffice.GetSettings(initSharedButton);
Expand Down
Loading

0 comments on commit e075967

Please sign in to comment.