From 3e5bbe93092007b9e171bb95cbf8276a43ff4593 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Tue, 11 Dec 2018 15:35:04 +0300 Subject: [PATCH 01/27] change icon class for actions --- css/main.css | 4 ++++ js/main.js | 8 ++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/css/main.css b/css/main.css index 5690a4c7..a025e7d0 100644 --- a/css/main.css +++ b/css/main.css @@ -35,6 +35,10 @@ .icon-onlyoffice-new-pptx { background-image: url("../img/new-pptx.svg"); } +.icon-onlyoffice-open, +.icon-onlyoffice-convert { + background-image: url("../img/app-dark.svg"); +} .AscDesktopEditor #header { display: none; diff --git a/js/main.js b/js/main.js index b663d0ee..73947201 100644 --- a/js/main.js +++ b/js/main.js @@ -156,9 +156,7 @@ displayName: t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE"), mime: attr.mime, permissions: OC.PERMISSION_READ, - icon: function () { - return OC.imagePath(OCA.Onlyoffice.AppName, "app-dark"); - }, + iconClass: "icon-onlyoffice-open", actionHandler: OCA.Onlyoffice.FileClick }); @@ -172,9 +170,7 @@ displayName: t(OCA.Onlyoffice.AppName, "Convert with ONLYOFFICE"), mime: attr.mime, permissions: OC.PERMISSION_READ, - icon: function () { - return OC.imagePath(OCA.Onlyoffice.AppName, "app-dark"); - }, + iconClass: "icon-onlyoffice-convert", actionHandler: OCA.Onlyoffice.FileConvertClick }); } From ba66079af65a4c068baf368d449a0bdab179b922 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Tue, 11 Dec 2018 15:36:54 +0300 Subject: [PATCH 02/27] duplicate mimetype (80ab138f42be0ebb7175a679624adeb76e71096e) --- js/main.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/js/main.js b/js/main.js index 73947201..5c75b82c 100644 --- a/js/main.js +++ b/js/main.js @@ -151,6 +151,9 @@ var formats = OCA.Onlyoffice.setting.formats; $.each(formats, function (ext, attr) { + if (!attr.mime) { + return true; + } fileList.fileActions.registerAction({ name: "onlyofficeOpen", displayName: t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE"), From 1f777ca7b0662975ce96e5533eae32c3fa4fef8f Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Tue, 11 Dec 2018 15:38:22 +0300 Subject: [PATCH 03/27] update documentation link --- README.md | 4 ++-- controller/editorcontroller.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ee32374a..8ee9b71f 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ After that find **ONLYOFFICE** in the list of available applications and install If the server with the ownCloud installed does not have an Internet access, or if you need it for some other reason, the administrator can install the application manually. To start using ONLYOFFICE Document Server with ownCloud, the following steps must be performed: -1. Go to the ownCloud server _apps/_ directory (or some other directory [used](https://doc.owncloud.org/server/latest/admin_manual/installation/apps_management_installation.html#using-custom-app-directories)): +1. Go to the ownCloud server _apps/_ directory (or some other directory [used](https://doc.owncloud.org/server/administration_manual/installation/apps_management_installation.html#using-custom-app-directories)): ``` cd apps/ ``` @@ -144,4 +144,4 @@ When the _Log-in credentials, save in session_ authentication type is used, the But if the encryption with the _per-user encryption keys_ (used by default in ownCloud **Default encryption module** app) is enabled, ONLYOFFICE Document Server cannot open the encrypted files for editing and save them after the editing. The ONLYOFFICE section of the administrative settings page will display a notification about it. However if you set the encryption with the _master key_, ONLYOFFICE application will work as intended. -The instruction on enabling _master key_ based encryption is available in the official documentation on [ownCloud](https://doc.owncloud.org/server/latest/admin_manual/configuration/files/encryption_configuration.html#enabling-master-key-based-encryption-from-the-command-line) websites. +The instruction on enabling _master key_ based encryption is available in the official documentation on [ownCloud](https://doc.owncloud.org/server/administration_manual/configuration/files/encryption_configuration.html#enabling-encryption-from-the-command-line) websites. diff --git a/controller/editorcontroller.php b/controller/editorcontroller.php index dcc85dd4..28bace65 100644 --- a/controller/editorcontroller.php +++ b/controller/editorcontroller.php @@ -638,7 +638,7 @@ private function getShare($token) { return [NULL, $this->trans->t("You do not have enough permissions to view the file")]; } - if ($share->getPassword() + if ($share->getPassword() && (!$this->session->exists("public_link_authenticated") || $this->session->get("public_link_authenticated") !== (string) $share->getId())) { return [NULL, $this->trans->t("You do not have enough permissions to view the file")]; From 4e327875af5d0cc6caf277bc42b8fb44afab5402 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Tue, 11 Dec 2018 16:11:16 +0300 Subject: [PATCH 04/27] getting file in shared folder by link --- controller/callbackcontroller.php | 10 +++++++++- controller/editorcontroller.php | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/controller/callbackcontroller.php b/controller/callbackcontroller.php index 05f8e300..461752f8 100644 --- a/controller/callbackcontroller.php +++ b/controller/callbackcontroller.php @@ -444,6 +444,8 @@ public function track($doc, $users, $key, $status, $url, $token) { break; } + $this->logger->debug("Track: " . $fileId . " status " . $status . " result " . $error, array("app" => $this->appName)); + return new JSONResponse(["error" => $error], Http::STATUS_OK); } @@ -462,6 +464,7 @@ private function getFile($userId, $fileId) { } $files = $this->root->getUserFolder($userId)->getById($fileId); + if (empty($files)) { $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)]; @@ -499,7 +502,12 @@ private function getFileByToken($fileId, $token) { } if ($node instanceof Folder) { - $file = $node->getById($fileId)[0]; + $files = $node->getById($fileId); + + if (empty($files)) { + return [NULL, new JSONResponse(["message" => $this->trans->t("File not found")], Http::STATUS_NOT_FOUND)]; + } + $file = $files[0]; } else { $file = $node; } diff --git a/controller/editorcontroller.php b/controller/editorcontroller.php index 28bace65..3927f513 100644 --- a/controller/editorcontroller.php +++ b/controller/editorcontroller.php @@ -576,6 +576,7 @@ private function getFile($userId, $fileId) { if (!$file->isReadable()) { return [NULL, $this->trans->t("You do not have enough permissions to view the file")]; } + return [$file, NULL]; } @@ -606,7 +607,12 @@ private function getFileByToken($fileId, $token) { } if ($node instanceof Folder) { - $file = $node->getById($fileId)[0]; + $files = $node->getById($fileId); + + if (empty($files)) { + return [NULL, $this->trans->t("File not found")]; + } + $file = $files[0]; } else { $file = $node; } From fb2f03a400cb6582e3fd30f80eec58b901e6ce54 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Wed, 12 Dec 2018 12:28:01 +0300 Subject: [PATCH 05/27] fix warning --- controller/editorcontroller.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/controller/editorcontroller.php b/controller/editorcontroller.php index 3927f513..4f1bca95 100644 --- a/controller/editorcontroller.php +++ b/controller/editorcontroller.php @@ -558,7 +558,7 @@ public function config($fileId, $token = NULL, $desktop = false) { */ private function getFile($userId, $fileId) { if (empty($fileId)) { - return [NULL, $this->trans->t("FileId is empty")]; + return [NULL, $this->trans->t("FileId is empty"), NULL]; } if ($userId !== NULL) { @@ -569,15 +569,15 @@ private function getFile($userId, $fileId) { } if (empty($files)) { - return [NULL, $this->trans->t("File not found")]; + return [NULL, $this->trans->t("File not found"), NULL]; } $file = $files[0]; if (!$file->isReadable()) { - return [NULL, $this->trans->t("You do not have enough permissions to view the file")]; + return [NULL, $this->trans->t("You do not have enough permissions to view the file"), NULL]; } - return [$file, NULL]; + return [$file, NULL, NULL]; } /** @@ -592,25 +592,25 @@ private function getFileByToken($fileId, $token) { list ($share, $error) = $this->getShare($token); if (isset($error)) { - return [NULL, $error]; + return [NULL, $error, NULL]; } if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) { - return [NULL, $this->trans->t("You do not have enough permissions to view the file")]; + return [NULL, $this->trans->t("You do not have enough permissions to view the file"), NULL]; } try { $node = $share->getNode(); } catch (NotFoundException $e) { $this->logger->error("getFileByToken error: " . $e->getMessage(), array("app" => $this->appName)); - return [NULL, $this->trans->t("File not found")]; + return [NULL, $this->trans->t("File not found"), NULL]; } if ($node instanceof Folder) { $files = $node->getById($fileId); if (empty($files)) { - return [NULL, $this->trans->t("File not found")]; + return [NULL, $this->trans->t("File not found"), NULL]; } $file = $files[0]; } else { From ffffa62cf175db2ebec18291a8da2968649be242 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Wed, 12 Dec 2018 16:35:35 +0300 Subject: [PATCH 06/27] fix public folder --- js/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index 5c75b82c..1cefde07 100644 --- a/js/main.js +++ b/js/main.js @@ -228,7 +228,7 @@ }; var initPage = function(){ - if ($("#isPublic").val() && !$("#dir").val().length) { + if ($("#isPublic").val() === "1" && !$("#filestable").length) { var fileName = $("#filename").val(); var extension = fileName.substr(fileName.lastIndexOf(".") + 1).toLowerCase(); From 364814ac6e745e01fa78bfe93b7d53efe01e5339 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Thu, 13 Dec 2018 11:56:42 +0300 Subject: [PATCH 07/27] fix php warning --- controller/settingscontroller.php | 1 + lib/appconfig.php | 11 +++++++++-- templates/settings.php | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/controller/settingscontroller.php b/controller/settingscontroller.php index 269e1f56..8e251256 100644 --- a/controller/settingscontroller.php +++ b/controller/settingscontroller.php @@ -156,6 +156,7 @@ public function SaveSettings($documentserver, $this->config->SetDocumentServerSecret($secret); $documentserver = $this->config->GetDocumentServerUrl(); + $error = NULL; if (!empty($documentserver)) { $error = $this->checkDocServiceUrl(); $this->config->SetSettingsError($error); diff --git a/lib/appconfig.php b/lib/appconfig.php index 9ef88e00..8f2672d6 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -438,9 +438,12 @@ public function GetSameTab() { /** * Save the list of groups * - * @param array $value - same tab + * @param array $value - the list of groups */ public function SetLimitGroups($groups) { + if (!is_array($groups)) { + $groups = array(); + } $value = json_encode($groups); $this->logger->info("Set groups: " . $value, array("app" => $this->appName)); @@ -457,7 +460,11 @@ public function GetLimitGroups() { if (empty($value)) { return array(); } - return json_decode($value, true); + $groups = json_decode($value, true); + if (!is_array($groups)) { + $groups = array(); + } + return $groups; } /** diff --git a/templates/settings.php b/templates/settings.php index c2eaaf1c..9761c289 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -84,7 +84,7 @@ checked="checked" /> + checked="checked" /> @@ -100,7 +100,7 @@ checked="checked" /> + checked="checked" /> From 8eebc80ae65d57db801bd096586775cd2036ecc0 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Thu, 13 Dec 2018 16:54:03 +0300 Subject: [PATCH 08/27] check https --- controller/settingscontroller.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/controller/settingscontroller.php b/controller/settingscontroller.php index 8e251256..229778c8 100644 --- a/controller/settingscontroller.php +++ b/controller/settingscontroller.php @@ -207,10 +207,8 @@ public function GetSettings() { private function checkDocServiceUrl() { try { - $documentServerUrl = $this->config->GetDocumentServerUrl(); - if (substr($this->urlGenerator->getAbsoluteURL("/"), 0, strlen("https")) === "https" - && preg_match("/^https?:\/\//i", $documentServerUrl) - && substr($documentServerUrl, 0, strlen("https")) !== "https") { + 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.")); } From 5f0259d5d801c7ee5725f676ad8720245728b14b Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Tue, 22 Jan 2019 18:22:27 +0300 Subject: [PATCH 09/27] 2019 --- appinfo/app.php | 2 +- appinfo/application.php | 2 +- appinfo/routes.php | 2 +- controller/callbackcontroller.php | 2 +- controller/editorcontroller.php | 2 +- controller/settingscontroller.php | 2 +- css/editor.css | 2 +- css/main.css | 2 +- css/settings.css | 2 +- js/desktop.js | 2 +- js/editor.js | 2 +- js/main.js | 2 +- js/settings.js | 2 +- lib/adminsettings.php | 2 +- lib/appconfig.php | 2 +- lib/crypt.php | 2 +- lib/documentservice.php | 2 +- settings.php | 2 +- templates/editor.php | 2 +- templates/settings.php | 2 +- 20 files changed, 20 insertions(+), 20 deletions(-) diff --git a/appinfo/app.php b/appinfo/app.php index 7ddc0624..a1febdeb 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -1,7 +1,7 @@ Date: Thu, 14 Feb 2019 17:56:00 +0300 Subject: [PATCH 10/27] fix size on mobile (ONLYOFFICE/web-apps-pro@f560e6fd5c404bb1aa556826b0de44d2adebf5fe) --- js/editor.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/editor.js b/js/editor.js index 550c22a4..2b36aeec 100644 --- a/js/editor.js +++ b/js/editor.js @@ -99,6 +99,10 @@ }; var docEditor = new DocsAPI.DocEditor("iframeEditor", config); + + if (config.type === "mobile" && $("#app > iframe").css("position") === "fixed") { + $("#app > iframe").css("height", "calc(100% - 45px)") + } } } }); From 327d3a8c37abbd28f8057e549536d7903d5c5466 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Thu, 28 Feb 2019 16:58:18 +0300 Subject: [PATCH 11/27] permissions modifyFilter --- controller/editorcontroller.php | 8 ++++++++ lib/appconfig.php | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/controller/editorcontroller.php b/controller/editorcontroller.php index 38f0fad7..0b8ceaea 100644 --- a/controller/editorcontroller.php +++ b/controller/editorcontroller.php @@ -538,6 +538,14 @@ public function config($fileId, $token = NULL, $desktop = false) { $params = $this->setCustomization($params); + $permissions_modifyFilter = $this->config->getSystemValue($this->config->_permissions_modifyFilter); + if (isset($permissions_modifyFilter)) { + if (!array_key_exists("permissions", $params["document"])) { + $params["document"]["permissions"] = []; + } + $params["document"]["permissions"]["modifyFilter"] = $permissions_modifyFilter; + } + if (!empty($this->config->GetDocumentServerSecret())) { $token = \Firebase\JWT\JWT::encode($params, $this->config->GetDocumentServerSecret()); $params["token"] = $token; diff --git a/lib/appconfig.php b/lib/appconfig.php index 8e7ee365..aecdef58 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -144,6 +144,13 @@ class AppConfig { */ private $_settingsError = "settings_error"; + /** + * The config key for the modifyFilter + * + * @var string + */ + public $_permissions_modifyFilter = "permissions_modifyFilter"; + /** * The config key for the customer * From 5a6652e8389200ea8ba48124d1455de2f2d3e5a2 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Fri, 1 Mar 2019 15:40:15 +0300 Subject: [PATCH 12/27] using IClientService --- lib/documentservice.php | 72 +++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/lib/documentservice.php b/lib/documentservice.php index 4ca98297..fb609278 100644 --- a/lib/documentservice.php +++ b/lib/documentservice.php @@ -154,30 +154,30 @@ function SendRequestToConvertService($document_uri, $from_extension, $to_extensi $response_xml_data; $countTry = 0; - $opts = array("http" => array( - "method" => "POST", - "timeout" => "120", - "header"=> "Content-type: application/json\r\n", - "content" => json_encode($data) - ) - ); + $opts = array( + "timeout" => "120", + "headers" => [ + "Content-type" => "application/json" + ], + "body" => json_encode($data) + ); if (!empty($this->config->GetDocumentServerSecret())) { $params = [ "payload" => $data ]; $token = \Firebase\JWT\JWT::encode($params, $this->config->GetDocumentServerSecret()); - $opts["http"]["header"] = $opts["http"]["header"] . $this->config->JwtHeader() . ": Bearer " . $token . "\r\n"; + $opts["headers"][$this->config->JwtHeader()] = "Bearer " . $token; $token = \Firebase\JWT\JWT::encode($data, $this->config->GetDocumentServerSecret()); $data["token"] = $token; - $opts["http"]["content"] = json_encode($data); + $opts["body"] = json_encode($data); } $ServiceConverterMaxTry = 3; while ($countTry < $ServiceConverterMaxTry) { $countTry = $countTry + 1; - $response_xml_data = $this->Request($urlToConverter, $opts); + $response_xml_data = $this->Request($urlToConverter, "post", $opts); if ($response_xml_data !== false) { break; } } @@ -265,12 +265,7 @@ function HealthcheckRequest() { $urlHealthcheck = $documentServerUrl . "healthcheck"; - $opts = array("http" => array( - "timeout" => "60" - ) - ); - - if (($response = $this->Request($urlHealthcheck, $opts)) === false) { + if (($response = $this->Request($urlHealthcheck)) === false) { throw new \Exception ($this->trans->t("Bad Request or timeout error")); } @@ -298,27 +293,26 @@ function CommandRequest($method) { "c" => $method ]; - $opts = array("http" => array( - "method" => "POST", - "timeout" => "60", - "header"=> "Content-type: application/json\r\n", - "content" => json_encode($data) - ) - ); + $opts = array( + "headers" => [ + "Content-type" => "application/json" + ], + "body" => json_encode($data) + ); if (!empty($this->config->GetDocumentServerSecret())) { $params = [ "payload" => $data ]; $token = \Firebase\JWT\JWT::encode($params, $this->config->GetDocumentServerSecret()); - $opts["http"]["header"] = $opts["http"]["header"] . $this->config->JwtHeader() . ": Bearer " . $token . "\r\n"; + $opts["headers"][$this->config->JwtHeader()] = "Bearer " . $token; $token = \Firebase\JWT\JWT::encode($data, $this->config->GetDocumentServerSecret()); $data["token"] = $token; - $opts["http"]["content"] = json_encode($data); + $opts["body"] = json_encode($data); } - if (($response = $this->Request($urlCommand, $opts)) === false) { + if (($response = $this->Request($urlCommand, "post", $opts)) === false) { throw new \Exception ($this->trans->t("Bad Request or timeout error")); } @@ -364,24 +358,32 @@ function ProcessCommandServResponceError($errorCode) { * Request to Document Server with turn off verification * * @param string $url - request address - * @param array $opts - stream context options + * @param array $method - request method + * @param array $opts - request options * * @return string */ - public function Request($url, $opts = NULL) { + + public function Request($url, $method = "get", $opts = NULL) { + $httpClientService = \OC::$server->getHTTPClientService(); + $client = $httpClientService->newClient(); + if (NULL === $opts) { $opts = array(); } - if (substr($url, 0, strlen("https")) === "https" && $this->config->TurnOffVerification()) { - $opts["ssl"] = array( - "verify_peer" => false, - "verify_peer_name" => false - ); + $opts["verify"] = false; + } + if (!array_key_exists("timeout", $opts)) { + $opts["timeout"] = 60; } - $context = stream_context_create($opts); + if ($method === "post") { + $response = $client->post($url, $opts); + } else { + $response = $client->get($url, $opts); + } - return file_get_contents($url, false, $context); + return $response->getBody(); } } From bccab5add4616d1c5eb61912473b69641070756d Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Fri, 1 Mar 2019 17:31:50 +0300 Subject: [PATCH 13/27] using instance's secret --- controller/settingscontroller.php | 2 -- lib/appconfig.php | 16 ++-------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/controller/settingscontroller.php b/controller/settingscontroller.php index 4476f600..c7484930 100644 --- a/controller/settingscontroller.php +++ b/controller/settingscontroller.php @@ -162,8 +162,6 @@ public function SaveSettings($documentserver, $this->config->SetSettingsError($error); } - $this->config->DropSKey(); - $this->config->SetDefaultFormats($defFormats); $this->config->SetEditableFormats($editFormats); $this->config->SetSameTab($sameTab); diff --git a/lib/appconfig.php b/lib/appconfig.php index aecdef58..976ebd0b 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -86,7 +86,7 @@ class AppConfig { * * @var string */ - private $_cryptSecret = "skey"; + private $_cryptSecret = "secret"; /** * The config key for the default formats @@ -357,19 +357,7 @@ public function GetDocumentServerSecret() { * @return string */ public function GetSKey() { - $skey = $this->config->getAppValue($this->appName, $this->_cryptSecret, ""); - if (empty($skey)) { - $skey = number_format(round(microtime(true) * 1000), 0, ".", ""); - $this->config->setAppValue($this->appName, $this->_cryptSecret, $skey); - } - return $skey; - } - - /** - * Regenerate the secret key - */ - public function DropSKey() { - $this->config->setAppValue($this->appName, $this->_cryptSecret, ""); + return $this->config->getSystemValue($this->_cryptSecret, true); } /** From dcc1e8abfb6e8c41ae68b960e11ceff4d2b9c106 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Tue, 5 Mar 2019 12:36:12 +0300 Subject: [PATCH 14/27] change generate url --- js/editor.js | 5 ++++- js/main.js | 5 ++++- js/settings.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/js/editor.js b/js/editor.js index 2b36aeec..695a4924 100644 --- a/js/editor.js +++ b/js/editor.js @@ -51,7 +51,10 @@ return; } - var configUrl = OC.generateUrl("apps/onlyoffice/ajax/config/" + (fileId || 0)); + var configUrl = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/config/{fileId}", + { + fileId: fileId || 0 + }); var params = []; if (fileToken) { diff --git a/js/main.js b/js/main.js index cee1ceb8..29f34d42 100644 --- a/js/main.js +++ b/js/main.js @@ -79,7 +79,10 @@ }); if ($("#isPublic").val()) { - url = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/" + encodeURIComponent($("#sharingToken").val())) + "?fileId=" + fileId; + url = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/" + encodeURIComponent($("#sharingToken").val()) + "?fileId={fileId}", + { + fileId: fileId + }); } if (winEditor && winEditor.location) { diff --git a/js/settings.js b/js/settings.js index 4562e81e..a8b48cb1 100644 --- a/js/settings.js +++ b/js/settings.js @@ -93,7 +93,7 @@ $.ajax({ method: "PUT", - url: OC.generateUrl("apps/onlyoffice/ajax/settings"), + url: OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/settings"), data: { documentserver: onlyofficeUrl, documentserverInternal: onlyofficeInternalUrl, From d28b04c7979d7f143f70d9d9b47f0168d6e7bc86 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Tue, 5 Mar 2019 12:39:15 +0300 Subject: [PATCH 15/27] unknown user use token --- controller/editorcontroller.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/controller/editorcontroller.php b/controller/editorcontroller.php index 0b8ceaea..930cad9e 100644 --- a/controller/editorcontroller.php +++ b/controller/editorcontroller.php @@ -569,14 +569,10 @@ private function getFile($userId, $fileId) { return [NULL, $this->trans->t("FileId is empty"), NULL]; } - if ($userId !== NULL) { - $files = $this->root->getUserFolder($userId)->getById($fileId); - } else { - $this->logger->debug("getFile by unknown user: " . $fileId, array("app" => $this->appName)); - $files = $this->root->getById($fileId); - } + $files = $this->root->getUserFolder($userId)->getById($fileId); if (empty($files)) { + $this->logger->info("Files not found: " . $fileId, array("app" => $this->appName)); return [NULL, $this->trans->t("File not found"), NULL]; } $file = $files[0]; @@ -618,6 +614,7 @@ private function getFileByToken($fileId, $token) { $files = $node->getById($fileId); if (empty($files)) { + $this->logger->info("Files not found: " . $fileId, array("app" => $this->appName)); return [NULL, $this->trans->t("File not found"), NULL]; } $file = $files[0]; From 57e5d54f3f7a53b8eeac62e35834049804a4b9b6 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Tue, 5 Mar 2019 13:14:35 +0300 Subject: [PATCH 16/27] filePath as addition param --- controller/editorcontroller.php | 24 +++++++++++++++++++----- js/editor.js | 4 ++++ js/main.js | 12 +++++++----- templates/editor.php | 2 +- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/controller/editorcontroller.php b/controller/editorcontroller.php index 930cad9e..f416be21 100644 --- a/controller/editorcontroller.php +++ b/controller/editorcontroller.php @@ -342,14 +342,15 @@ public function convert($fileId) { * * @param integer $fileId - file identifier * @param string $token - access token + * @param string $filePath - file path * * @return TemplateResponse|RedirectResponse * * @NoAdminRequired * @NoCSRFRequired */ - public function index($fileId, $token = NULL) { - $this->logger->debug("Open: " . $fileId, array("app" => $this->appName)); + public function index($fileId, $token = NULL, $filePath = NULL) { + $this->logger->debug("Open: " . $fileId . " " . $filePath, array("app" => $this->appName)); if (empty($token) && !$this->userSession->isLoggedIn()) { $redirectUrl = $this->urlGenerator->linkToRoute("core.login.showLoginForm", [ @@ -372,6 +373,7 @@ public function index($fileId, $token = NULL) { $params = [ "documentServerUrl" => $documentServerUrl, "fileId" => $fileId, + "filePath" => $filePath, "token" => $token ]; @@ -411,6 +413,7 @@ public function PublicPage($fileId, $token) { * Collecting the file parameters for the document service * * @param integer $fileId - file identifier + * @param string $filePath - file path * @param string $token - access token * @param bool $desktop - desktop label * @@ -419,7 +422,7 @@ public function PublicPage($fileId, $token) { * @NoAdminRequired * @PublicPage */ - public function config($fileId, $token = NULL, $desktop = false) { + public function config($fileId, $filePath = NULL, $token = NULL, $desktop = false) { if (empty($token) && !$this->config->isUserAllowedToUse()) { return ["error" => $this->trans->t("Not permitted")]; @@ -431,7 +434,7 @@ public function config($fileId, $token = NULL, $desktop = false) { $userId = $user->getUID(); } - list ($file, $error, $share) = empty($token) ? $this->getFile($userId, $fileId) : $this->getFileByToken($fileId, $token); + list ($file, $error, $share) = empty($token) ? $this->getFile($userId, $fileId, $filePath) : $this->getFileByToken($fileId, $token); if (isset($error)) { $this->logger->error("Config: " . $fileId . " " . $error, array("app" => $this->appName)); @@ -561,10 +564,11 @@ public function config($fileId, $token = NULL, $desktop = false) { * * @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, $this->trans->t("FileId is empty"), NULL]; } @@ -575,8 +579,18 @@ private function getFile($userId, $fileId) { $this->logger->info("Files not found: " . $fileId, array("app" => $this->appName)); return [NULL, $this->trans->t("File not found"), NULL]; } + $file = $files[0]; + if (count($files) > 1 && !empty($filePath)) { + $filePath = "/" . $userId . "/files" . $filePath; + foreach ($files as $curFile) { + if ($curFile->getPath() === $filePath) { + $file = $curFile; + } + } + } + if (!$file->isReadable()) { return [NULL, $this->trans->t("You do not have enough permissions to view the file"), NULL]; } diff --git a/js/editor.js b/js/editor.js index 695a4924..d9fc896d 100644 --- a/js/editor.js +++ b/js/editor.js @@ -40,6 +40,7 @@ }; var fileId = $("#iframeEditor").data("id"); + var filePath = $("#iframeEditor").data("path"); var fileToken = $("#iframeEditor").data("token"); if (!fileId && !fileToken) { displayError(t(OCA.Onlyoffice.AppName, "FileId is empty")); @@ -57,6 +58,9 @@ }); var params = []; + if (filePath) { + params.push("filePath=" + encodeURIComponent(filePath)); + } if (fileToken) { params.push("token=" + encodeURIComponent(fileToken)); } diff --git a/js/main.js b/js/main.js index 29f34d42..19a43b6a 100644 --- a/js/main.js +++ b/js/main.js @@ -63,7 +63,7 @@ } fileList.add(response, { animate: true }); - OCA.Onlyoffice.OpenEditor(response.id, winEditor); + OCA.Onlyoffice.OpenEditor(response.id, dir, response.name, winEditor); OC.Notification.show(t(OCA.Onlyoffice.AppName, "File created"), { timeout: 3 @@ -72,10 +72,12 @@ ); }; - OCA.Onlyoffice.OpenEditor = function (fileId, winEditor) { - var url = OC.generateUrl("/apps/" + OCA.Onlyoffice.AppName + "/{fileId}", + OCA.Onlyoffice.OpenEditor = function (fileId, fileDir, fileName, winEditor) { + var filePath = fileDir.replace(new RegExp("\/$"), "") + "/" + fileName; + var url = OC.generateUrl("/apps/" + OCA.Onlyoffice.AppName + "/{fileId}?filePath={filePath}", { - fileId: fileId + fileId: fileId, + filePath: filePath }); if ($("#isPublic").val()) { @@ -96,7 +98,7 @@ OCA.Onlyoffice.FileClick = function (fileName, context) { var fileInfoModel = context.fileInfoModel || context.fileList.getModelForFile(fileName); - OCA.Onlyoffice.OpenEditor(fileInfoModel.id); + OCA.Onlyoffice.OpenEditor(fileInfoModel.id, context.dir, fileName); }; OCA.Onlyoffice.FileConvertClick = function (fileName, context) { diff --git a/templates/editor.php b/templates/editor.php index ac3de450..38deacc2 100644 --- a/templates/editor.php +++ b/templates/editor.php @@ -34,7 +34,7 @@
-
" data-token="">
+
" data-path="" data-token="">