diff options
author | Sergey Linnik <sergey.linnik@onlyoffice.com> | 2018-03-20 14:50:16 +0300 |
---|---|---|
committer | Sergey Linnik <sergey.linnik@onlyoffice.com> | 2018-03-20 17:27:30 +0300 |
commit | c3f17a93b1b8920ba00c94aed7ce31b039ada2c4 (patch) | |
tree | 3fc0c3ea41d4fa264d074c635c0ee98aaaa70a34 | |
parent | d473501c9b09b7cf425983ac92de9e1c03b2daee (diff) |
shared link to folder
-rw-r--r-- | controller/callbackcontroller.php | 20 | ||||
-rw-r--r-- | controller/editorcontroller.php | 37 | ||||
-rw-r--r-- | js/editor.js | 2 | ||||
-rw-r--r-- | js/main.js | 44 |
4 files changed, 57 insertions, 46 deletions
diff --git a/controller/callbackcontroller.php b/controller/callbackcontroller.php index 3e88352..284e7d8 100644 --- a/controller/callbackcontroller.php +++ b/controller/callbackcontroller.php @@ -32,6 +32,7 @@ use OCP\AppFramework\Http\DataDownloadResponse; use OCP\AppFramework\Http\JSONResponse; use OCP\Constants; use OCP\Files\File; +use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\NotPermittedException; use OCP\IL10N; @@ -204,7 +205,7 @@ class CallbackController extends Controller { $userId = $hashData->userId; $token = $hashData->token; - list ($file, $error) = empty($token) ? $this->getFile($userId, $fileId) : $this->getFileByToken($token); + list ($file, $error) = empty($token) ? $this->getFile($userId, $fileId) : $this->getFileByToken($fileId, $token); if (isset($error)) { return $error; @@ -359,7 +360,7 @@ class CallbackController extends Controller { } $token = $hashData->token; - list ($file, $error) = empty($token) ? $this->getFile($userId, $fileId) : $this->getFileByToken($token); + list ($file, $error) = empty($token) ? $this->getFile($userId, $fileId) : $this->getFileByToken($fileId, $token); if (isset($error)) { return $error; @@ -444,11 +445,12 @@ class CallbackController extends Controller { /** * Getting file by token * - * @param string $token - file token + * @param integer $fileId - file identifier + * @param string $token - access token * * @return array */ - private function getFileByToken($token) { + private function getFileByToken($fileId, $token) { list ($share, $error) = $this->getShare($token); if (isset($error)) { @@ -457,13 +459,19 @@ class CallbackController extends Controller { $node = $share->getNode(); - return [$node, NULL]; + if ($node instanceof Folder) { + $file = $node->getById($fileId)[0]; + } else { + $file = $node; + } + + return [$file, NULL]; } /** * Getting share by token * - * @param string $token - file token + * @param string $token - access token * * @return array */ diff --git a/controller/editorcontroller.php b/controller/editorcontroller.php index c2da674..d5a28bc 100644 --- a/controller/editorcontroller.php +++ b/controller/editorcontroller.php @@ -32,6 +32,7 @@ use OCP\AppFramework\Controller; use OCP\AutoloadNotAllowedException; use OCP\Constants; use OCP\Files\FileInfo; +use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\IL10N; use OCP\ILogger; @@ -318,12 +319,13 @@ class EditorController extends Controller { * Print editor section * * @param integer $fileId - file identifier - * @param string $token - file token + * @param string $token - access token * * @return TemplateResponse * * @NoAdminRequired * @NoCSRFRequired + * @PublicPage */ public function index($fileId, $token = NULL) { $this->logger->debug("Open: " . $fileId, array("app" => $this->appName)); @@ -360,7 +362,7 @@ class EditorController extends Controller { /** * Print public editor section * - * @param string $token - file token + * @param string $token - access token * * @return TemplateResponse * @@ -369,22 +371,14 @@ class EditorController extends Controller { * @PublicPage */ public function PublicPage($token) { - - list ($file, $error) = $this->getFileByToken($token); - - if (isset($error)) { - $this->logger->error("PublicPage: " . $fileId . " " . $error, array("app" => $this->appName)); - return ["error" => $error]; - } - - return $this->index($file->getId(), $token); + return $this->index(0, $token); } /** * Collecting the file parameters for the document service * * @param integer $fileId - file identifier - * @param string $token - file token + * @param string $token - access token * * @return array * @@ -393,7 +387,7 @@ class EditorController extends Controller { */ public function config($fileId, $token = NULL) { - list ($file, $error) = empty($token) ? $this->getFile($fileId) : $this->getFileByToken($token); + list ($file, $error) = empty($token) ? $this->getFile($fileId) : $this->getFileByToken($fileId, $token); if (isset($error)) { $this->logger->error("Config: " . $fileId . " " . $error, array("app" => $this->appName)); @@ -512,11 +506,12 @@ class EditorController extends Controller { /** * Getting file by token * - * @param string $token - file token + * @param integer $fileId - file identifier + * @param string $token - access token * * @return array */ - private function getFileByToken($token) { + private function getFileByToken($fileId, $token) { list ($share, $error) = $this->getShare($token); if (isset($error)) { @@ -529,13 +524,19 @@ class EditorController extends Controller { $node = $share->getNode(); - return [$node, NULL]; + if ($node instanceof Folder) { + $file = $node->getById($fileId)[0]; + } else { + $file = $node; + } + + return [$file, NULL]; } /** * Getting share by token * - * @param string $token - file token + * @param string $token - access token * * @return array */ @@ -577,7 +578,7 @@ class EditorController extends Controller { * Generate secure link to download document * * @param integer $fileId - file identifier - * @param string $token - file token + * @param string $token - access token * * @return string */ diff --git a/js/editor.js b/js/editor.js index f8e77dc..803edee 100644 --- a/js/editor.js +++ b/js/editor.js @@ -39,7 +39,7 @@ var fileId = $("#iframeEditor").data("id"); var fileToken = $("#iframeEditor").data("token"); - if (!fileId) { + if (!fileId && !fileToken) { displayError(t(OCA.Onlyoffice.AppName, "FileId is empty")); return; } @@ -79,6 +79,10 @@ fileId: fileId }); + if ($("#isPublic").val()) { + url += "?token=" + encodeURIComponent($("#sharingToken").val()); + } + if (winEditor && winEditor.location) { winEditor.location.href = url; } else if (!OCA.Onlyoffice.setting.sameTab) { @@ -91,7 +95,7 @@ OCA.Onlyoffice.FileClick = function (fileName, context, attr) { var fileInfoModel = context.fileInfoModel || context.fileList.getModelForFile(fileName); var fileList = context.fileList; - if (!attr.conv || (fileList.dirInfo.permissions & OC.PERMISSION_CREATE) !== OC.PERMISSION_CREATE) { + if (!attr.conv || (fileList.dirInfo.permissions & OC.PERMISSION_CREATE) !== OC.PERMISSION_CREATE || $("#isPublic").val()) { OCA.Onlyoffice.OpenEditor(fileInfoModel.id); return; } @@ -224,31 +228,29 @@ }; - if ($("#isPublic").val()) { - if (!$("#dir").val().length) { - var fileName = $("#filename").val(); - var extension = fileName.substr(fileName.lastIndexOf(".") + 1); + if ($("#isPublic").val() && !$("#dir").val().length) { + var fileName = $("#filename").val(); + var extension = fileName.substr(fileName.lastIndexOf(".") + 1); - var initSharedButton = function() { - var mimes = OCA.Onlyoffice.setting.formats; + var initSharedButton = function() { + var mimes = OCA.Onlyoffice.setting.formats; - var conf = mimes[extension]; - if (conf) { - var button = document.createElement("a"); - button.href = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/" + $("#sharingToken").val()); - button.className = "button"; - button.innerText = t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE") - - if (!OCA.Onlyoffice.setting.sameTab) { - button.target = "_blank"; - } + var conf = mimes[extension]; + if (conf) { + var button = document.createElement("a"); + button.href = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/" + encodeURIComponent($("#sharingToken").val())); + button.className = "button"; + button.innerText = t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE") - $("#preview").append(button); + if (!OCA.Onlyoffice.setting.sameTab) { + button.target = "_blank"; } - }; - OCA.Onlyoffice.GetSettings(initSharedButton); - } + $("#preview").append(button); + } + }; + + OCA.Onlyoffice.GetSettings(initSharedButton); } else { OC.Plugins.register("OCA.Files.FileList", OCA.Onlyoffice.FileList); OC.Plugins.register("OCA.Files.NewFileMenu", OCA.Onlyoffice.NewFileMenu); |