From 7ef24654cf0963bc9e27e2846fabea706b1a1cc5 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Wed, 7 Dec 2016 00:57:01 +0100 Subject: [PATCH] Public editing Signed-off-by: Lukas Reschke --- appinfo/app.php | 7 ++ appinfo/database.xml | 16 --- appinfo/info.xml | 2 +- appinfo/routes.php | 3 +- css/style.css | 2 +- js/documents.js | 75 +++-------- js/viewer/viewer.js | 125 ++++++++++++------ lib/Controller/DocumentController.php | 172 +++++++++++++++++-------- lib/Controller/WopiController.php | 72 ++--------- lib/TokenManager.php | 105 ++++++++++++++++ lib/WOPI/DiscoveryManager.php | 20 +-- lib/db/wopi.php | 45 +------ lib/filter.php | 74 ----------- lib/helper.php | 12 -- lib/storage.php | 175 -------------------------- templates/documents.php | 9 ++ 16 files changed, 363 insertions(+), 551 deletions(-) create mode 100644 lib/TokenManager.php delete mode 100644 lib/filter.php delete mode 100644 lib/storage.php diff --git a/appinfo/app.php b/appinfo/app.php index 3c8e00d8..8650a508 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -31,6 +31,13 @@ $eventDispatcher->addListener( \OCP\Util::addStyle('richdocuments', 'viewer/odfviewer'); } ); +$eventDispatcher->addListener( + 'OCA\Files_Sharing::loadAdditionalScripts', + function() { + \OCP\Util::addScript('richdocuments', 'viewer/viewer'); + \OCP\Util::addStyle('richdocuments', 'viewer/odfviewer'); + } +); if (class_exists('\OC\Files\Type\TemplateManager')) { $manager = \OC_Helper::getFileTemplateManager(); diff --git a/appinfo/database.xml b/appinfo/database.xml index 128093e1..a3a74446 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -70,26 +70,22 @@ 1 true 4 - Unique per token owner_uid text 64 - Document owner UserId - a textual user identifier (unique?) editor_uid text 64 - Document editor's UserId, can be different from uid if shared fileid integer true 4 - The unique ID of the file authorized version @@ -97,28 +93,18 @@ true 0 4 - Authorized version, if any, of given fileid - - - path - text - true - 512 - Relative to storage e.g. /welcome.odt canwrite boolean false true - Can make changes to this file server_host text localhost true - Host from which token generation request originated token @@ -126,14 +112,12 @@ true 32 - File access token expiry integer true 4 - Expiration time of the token diff --git a/appinfo/info.xml b/appinfo/info.xml index e9d976d6..3371dc65 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -5,7 +5,7 @@ Collabora Online allows you to to work with all kinds of office documents directly in your browser. This application requires Collabora Cloudsuite to be installed on one of your servers, please read the documentation to learn more about that. Edit office documents directly in your browser. AGPL - 1.1.19 + 1.1.21 Collabora Productivity based on work of Frank Karlitschek, Victor Dubiniuk https://github.com/nextcloud/richdocuments/issues https://github.com/nextcloud/richdocuments.git diff --git a/appinfo/routes.php b/appinfo/routes.php index de620d1b..67dfc3fa 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -15,17 +15,16 @@ return [ 'routes' => [ //documents ['name' => 'document#index', 'url' => 'index', 'verb' => 'GET'], + ['name' => 'document#publicPage', 'url' => '/public', 'verb' => 'GET'], ['name' => 'document#create', 'url' => 'ajax/documents/create', 'verb' => 'POST'], // WOPI access - ['name' => 'wopi#getToken', 'url' => 'wopi/token/{fileId}', 'verb' => 'GET'], ['name' => 'wopi#checkFileInfo', 'url' => 'wopi/files/{fileId}', 'verb' => 'GET'], ['name' => 'wopi#getFile', 'url' => 'wopi/files/{fileId}/contents', 'verb' => 'GET'], ['name' => 'wopi#putFile', 'url' => 'wopi/files/{fileId}/contents', 'verb' => 'POST'], //settings ['name' => 'settings#setSettings', 'url' => 'ajax/admin.php', 'verb' => 'POST'], - ['name' => 'settings#getSupportedMimes', 'url' => 'ajax/mimes.php', 'verb' => 'GET'], ['name' => 'settings#getSettings', 'url' => 'ajax/settings.php', 'verb' => 'GET'], ] ]; diff --git a/css/style.css b/css/style.css index 73821bbb..78160fa9 100644 --- a/css/style.css +++ b/css/style.css @@ -124,7 +124,7 @@ width:100%; z-index: 500; background-color: #ddd !important; - top: 45px; + top: 0px; bottom: 0; } diff --git a/js/documents.js b/js/documents.js index f29df8c5..7beebee4 100644 --- a/js/documents.js +++ b/js/documents.js @@ -18,11 +18,7 @@ $.widget('oc.documentGrid', { }, _load : function (fileId){ - var url = OC.generateUrl('apps/richdocuments/wopi/token/{file_id}', {file_id: fileId}); - $.get( - url, - documentsMain.initSession - ); + documentsMain.initSession(); }, _render : function (data){ @@ -65,7 +61,6 @@ var documentsMain = { isEditorMode : false, isViewerMode: false, isGuest : false, - memberId : false, esId : false, ready :false, fileName: null, @@ -306,6 +301,7 @@ var documentsMain = { console.log('Waiting for page to render ...'); return; } + parent.postMessage('loading', '*'); $(document.body).addClass("claro"); $(document.body).prepend(documentsMain.UI.container); @@ -428,7 +424,7 @@ var documentsMain = { documentsMain.UI.init(); // Does anything indicate that we need to autostart a session? - fileId = parent.location.hash.replace(/^\W*/, ''); + fileId = getURLParameter('fileid').replace(/^\W*/, ''); if (fileId.indexOf('_') >= 0) { documentsMain.returnToDir = unescape(fileId.replace(/^[^_]*_/, '')); @@ -460,42 +456,28 @@ var documentsMain = { prepareSession : function(){ documentsMain.isEditorMode = true; documentsMain.overlay.documentOverlay('show'); - $(window).on("unload", documentsMain.onTerminate); }, - initSession: function(response) { - documentsMain.urlsrc = response.documents[0].urlsrc; - documentsMain.fullPath = response.documents[0].path; - documentsMain.token = response.documents[0].token; + initSession: function() { + documentsMain.urlsrc = richdocuments_urlsrc; + documentsMain.fullPath = richdocuments_path; + documentsMain.token = richdocuments_token; $('footer,nav').hide(); $(documentsMain.toolbar).appendTo('#header'); - if (!response) { - documentsMain.onEditorShutdown(t('richdocuments', 'Failed to load this document. Please check if it can be opened with an external editor. This might also mean it has been unshared or deleted recently.')); - return; - } - - //Wait for 3 sec if editor is still loading - if (!documentsMain.ready){ - setTimeout(function(){ documentsMain.initSession(response); }, 3000); - console.log('Waiting for the editor to start...'); - return; - } - documentsMain.canShare = !documentsMain.isGuest - && typeof OC.Share !== 'undefined' && response.permissions & OC.PERMISSION_SHARE; + && typeof OC.Share !== 'undefined' && richdocuments_permissions & OC.PERMISSION_SHARE; // fade out file list and show the cloudsuite $('#content-wrapper').fadeOut('fast').promise().done(function() { - documentsMain.fileId = response.file_id; - documentsMain.fileName = response.title; + documentsMain.fileId = richdocuments_fileId; + documentsMain.fileName = richdocuments_title; - documentsMain.memberId = response.member_id; - documentsMain.canEdit = Boolean(response.permissions & OC.PERMISSION_UPDATE); + documentsMain.canEdit = Boolean(richdocuments_permissions & OC.PERMISSION_UPDATE); - documentsMain.loadDocument(response); + documentsMain.loadDocument(documentsMain.fileName, documentsMain.fileId); if (documentsMain.isGuest){ $('#odf-close').text(t('richdocuments', 'Save') ); @@ -514,8 +496,8 @@ var documentsMain = { }); }, - loadDocument: function(response) { - documentsMain.UI.showEditor(response.title, response.file_id, 'write'); + loadDocument: function(title, fileId) { + documentsMain.UI.showEditor(title, fileId, 'write'); }, onEditorShutdown : function (message){ @@ -537,9 +519,6 @@ var documentsMain = { onClose: function() { - if (!documentsMain.isEditorMode){ - return; - } documentsMain.isEditorMode = false; $(window).off('beforeunload'); $(window).off('unload'); @@ -549,11 +528,7 @@ var documentsMain = { documentsMain.UI.hideEditor(); $('#ocToolbar').remove(); - if (documentsMain.returnToDir) { - window.location = OC.generateUrl('apps/files?dir={dir}', {dir: documentsMain.returnToDir}); - } else { - documentsMain.show(); - } + parent.postMessage('close', '*'); }, onCloseViewer: function() { @@ -567,26 +542,6 @@ var documentsMain = { $('#loleafletframe').focus(); }, - onTerminate: function(){ - var url = ''; - if (documentsMain.isGuest){ - url = OC.generateUrl('apps/richdocuments/ajax/user/disconnectGuest/{member_id}', {member_id: documentsMain.memberId}); - } else { - url = OC.generateUrl('apps/richdocuments/ajax/user/disconnect/{member_id}', {member_id: documentsMain.memberId}); - } - $.ajax({ - type: "POST", - url: url, - data: {esId: documentsMain.esId}, - dataType: "json", - async: false // Should be sync to complete before the page is closed - }); - - if (documentsMain.isGuest){ - $('footer,nav').show(); - } - }, - show: function(fileId){ if (documentsMain.isGuest){ return; diff --git a/js/viewer/viewer.js b/js/viewer/viewer.js index 9ec81bd6..3ade286b 100644 --- a/js/viewer/viewer.js +++ b/js/viewer/viewer.js @@ -1,9 +1,6 @@ /* globals FileList, OCA.Files.fileActions, oc_debug */ var odfViewer = { isDocuments : false, - supportedMimesReadOnly: [ - ], - supportedMimesReadWrite: [ 'application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.spreadsheet', @@ -36,20 +33,14 @@ var odfViewer = { 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' ], - register : function(response){ + register : function() { var i, mimeReadOnly, mimeReadWrite; - if (response && response.mimes){ - jQuery.each(response.mimes, function(i, mime){ - odfViewer.supportedMimesReadOnly.push(mime); - odfViewer.supportedMimesReadWrite.push(mime); - }); - } - for (i = 0; i < odfViewer.supportedMimesReadOnly.length; ++i) { - mimeReadOnly = odfViewer.supportedMimesReadOnly[i]; - OCA.Files.fileActions.register(mimeReadOnly, 'View', OC.PERMISSION_READ, '', odfViewer.onView); + for (i = 0; i < odfViewer.supportedMimesReadWrite.length; ++i) { + mimeReadOnly = odfViewer.supportedMimesReadWrite[i]; + OCA.Files.fileActions.register(mimeReadOnly, 'View', OC.PERMISSION_READ, '', odfViewer.onEdit); OCA.Files.fileActions.setDefault(mimeReadOnly, 'View'); } for (i = 0; i < odfViewer.supportedMimesReadWrite.length; ++i) { @@ -62,40 +53,82 @@ var odfViewer = { odfViewer.onEdit, t('richdocuments', 'Edit') ); + OCA.Files.fileActions.register( + mimeReadWrite, + 'View', + OC.PERMISSION_READ, + OC.imagePath('core', 'actions/rename'), + odfViewer.onEdit, + t('richdocuments', 'View') + ); + OCA.Files.fileActions.setDefault(mimeReadWrite, 'View'); OCA.Files.fileActions.setDefault(mimeReadWrite, 'Edit'); } }, dispatch : function(filename){ - if (odfViewer.supportedMimesReadWrite.indexOf(OCA.Files.fileActions.getCurrentMimeType()) !== -1 - && OCA.Files.fileActions.getCurrentPermissions() & OC.PERMISSION_UPDATE - ){ - odfViewer.onEdit(filename); - } else { - odfViewer.onView(filename); - } + odfViewer.onEdit(filename); }, - onEdit : function(fileName, context){ - var fileId = context.$file.attr('data-id'); - var fileDir = context.dir; + onEdit : function(fileName, context) { + if(context) { + var fileDir = context.dir; + var fileId = context.$file.attr('data-id'); + } - if (fileDir) { - window.location = OC.generateUrl('apps/richdocuments/index#{file_id}_{dir}', {file_id: fileId, dir: fileDir}); + var viewer; + if($('#isPublic').val() === '1') { + viewer = OC.generateUrl( + 'apps/richdocuments/public?shareToken={shareToken}&fileName={fileName}&requesttoken={requesttoken}', + { + shareToken: $('#sharingToken').val(), + fileName: fileName, + dir: fileDir, + requesttoken: OC.requestToken + } + ); } else { - window.location = OC.generateUrl('apps/richdocuments/index#{file_id}', {file_id: fileId}); + viewer = OC.generateUrl( + 'apps/richdocuments/index?fileId={fileId}_{dir}&requesttoken={requesttoken}', + { + fileId: fileId, + dir: fileDir, + requesttoken: OC.requestToken + } + ); } - }, - onView: function(filename, context) { - var attachTo = odfViewer.isDocuments ? '#documents-content' : '#controls'; + if(context) { + FileList.setViewerMode(true); + } + + var $iframe = $('