diff --git a/ajax/sessionController.php b/ajax/sessionController.php index ca021d4d..008f1a97 100644 --- a/ajax/sessionController.php +++ b/ajax/sessionController.php @@ -26,7 +26,17 @@ class SessionController extends Controller{ $uid = self::preDispatch(); $fileId = intval(@$args['file_id']); $file = new File($fileId); - self::join($uid, $file); + + if ($file->getPermissions() & \OCP\PERMISSION_UPDATE) { + self::join($uid, $file); + } else { + \OCP\JSON::success(array( + 'permissions' => $file->getPermissions(), + 'id' => $fileId + )); + } + + exit(); } protected static function join($uid, $file){ diff --git a/js/documents.js b/js/documents.js index 60ad9bfa..decb3ff4 100644 --- a/js/documents.js +++ b/js/documents.js @@ -162,10 +162,15 @@ var documentsMain = { initSession: function(response) { "use strict"; - if (!response || !response.es_id || !response.status || response.status==='error'){ + if(response && (response.id && !response.es_id)){ + return documentsMain.view(response.id); + } + + if (!response || !response.status || response.status==='error'){ OC.Notification.show(t('documents', 'Failed to load this document. Please check if it can be opened with an external odt editor. This might also mean it has been unshared or deleted recently.')); documentsMain.prepareGrid(); documentsMain.show(); + $(window).off('beforeunload'); setTimeout(OC.Notification.hide, 7000); return; } @@ -220,6 +225,16 @@ var documentsMain = { documentsMain.initSession ); }, + + view : function(id){ + OC.addScript('documents', 'viewer/viewer', function() { + documentsMain.prepareGrid(); + $(window).off('beforeunload'); + var path = $('li[data-id='+ id +']>a').attr('href'); + odfViewer.isDocuments = true; + odfViewer.onView(path); + }); + }, onCreate: function(event){ event.preventDefault(); diff --git a/js/viewer/viewer.js b/js/viewer/viewer.js index b6d9a3b3..088bafa1 100644 --- a/js/viewer/viewer.js +++ b/js/viewer/viewer.js @@ -1,4 +1,5 @@ var odfViewer = { + isDocuments : false, supportedMimesRead: [ 'application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.spreadsheet', @@ -44,14 +45,22 @@ var odfViewer = { }, onView: function(filename) { - OC.addStyle('documents', 'viewer/webodf'); - OC.addStyle('documents', 'viewer/odfviewer'); + var webodfSource = (oc_debug === true) ? 'webodf-debug' : 'webodf', + attachTo = odfViewer.isDocuments ? '#documents-content' : 'table', + attachToolbarTo = odfViewer.isDocuments ? '#content-wrapper' : '#controls'; + + if (odfViewer.isDocuments){ + //Documents view + var location = filename; + } else { + //Public page, files app, etc + var location = fileDownloadPath($('#dir').val(), filename); + OC.addStyle('documents', 'viewer/webodf'); + } - var webodfSource = (oc_debug === true) ? 'webodf-debug' : 'webodf'; + OC.addStyle('documents', 'viewer/odfviewer'); OC.addScript('documents', '3rdparty/webodf/' + webodfSource, function() { - var location = fileDownloadPath($('#dir').val(), filename); - // fade out files menu and add odf menu $('#controls div').fadeOut('slow').promise().done(function() { // odf action toolbar @@ -59,14 +68,18 @@ var odfViewer = { '
' + '
'; - $('#controls').append(odfToolbarHtml); - + if (odfViewer.isDocuments){ + $(attachToolbarTo).prepend(odfToolbarHtml); + $('#odf-toolbar').css({position:'fixed'}); + } else { + $(attachToolbarTo).append(odfToolbarHtml); + } }); // fade out file list and show pdf canvas - $('table').fadeOut('slow').promise().done(function() { + $('table, #documents-content').fadeOut('slow').promise().done(function() { var canvashtml = '
'; - $('table').after(canvashtml); + $(attachTo).after(canvashtml); // in case we are on the public sharing page we shall display the odf into the preview tag $('#preview').html(canvashtml); @@ -85,7 +98,7 @@ var odfViewer = { $('#odf-toolbar').remove(); $('#odf-canvas').remove(); $('#controls div').not('.hidden').fadeIn('slow'); - $('table').fadeIn('slow'); + $('table, #documents-content').fadeIn('slow'); }); } }; diff --git a/lib/file.php b/lib/file.php index ae585783..265e6c78 100644 --- a/lib/file.php +++ b/lib/file.php @@ -129,6 +129,27 @@ class File { public function setPasswordProtected($value){ $this->passwordProtected = $value; } + + public function getPermissions(){ + if (count($this->sharing)){ + if ($this->isPublicShare()){ + $permissions = \OCP\PERMISSION_READ | \OCP\PERMISSION_UPDATE; + } else { + $permissions = $this->sharing[0]['permissions']; + } + } else { + list($owner, $path) = $this->getOwnerViewAndPath(); + $permissions = 0; + if (\OC\Files\Filesystem::isReadable($path)){ + $permissions |= \OCP\PERMISSION_READ; + } + if (\OC\Files\Filesystem::isUpdatable($path)){ + $permissions |= \OCP\PERMISSION_UPDATE; + } + + } + return $permissions; + } /** *