From 78ba2cabe1fc82f367050f83d8c034e84415192a Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Thu, 19 Sep 2013 22:14:34 +0300 Subject: [PATCH] Hide share button if there are no share permissions --- ajax/sessionController.php | 5 +++++ js/documents.js | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ajax/sessionController.php b/ajax/sessionController.php index dc038684..2b73c14f 100644 --- a/ajax/sessionController.php +++ b/ajax/sessionController.php @@ -35,6 +35,11 @@ class SessionController extends Controller{ $session = Session::add($genesisPath, $hash, $fileId); } + $session['permissions'] = \OCP\PERMISSION_READ; + if (\OC\Files\Filesystem::isSharable($path)) { + $session['permissions'] |= \OCP\PERMISSION_SHARE; + } + $session['member_id'] = (string) Member::add($session['es_id'], $uid, Helper::getRandomColor()); \OCP\JSON::success($session); exit(); diff --git a/js/documents.js b/js/documents.js index 979e3ffb..efa3b88d 100644 --- a/js/documents.js +++ b/js/documents.js @@ -64,8 +64,11 @@ var documentsMain = { $('#documents-overlay,#documents-overlay-below').fadeOut('slow'); }, - showEditor : function(title){ + showEditor : function(title, canShare){ $(document.body).prepend(documentsMain.UI.toolbar.replace(/%title%/g, title)); + if (!canShare){ + $('#odf-invite,#invite-block').remove(); + } $(document.body).addClass("claro"); $(document.body).prepend(documentsMain.UI.container); // in case we are on the public sharing page we shall display the odf into the preview tag @@ -132,7 +135,7 @@ var documentsMain = { "use strict"; - if (!response || !response.status || response.status==='error'){ + if (!response || !response.es_id || !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(); @@ -143,10 +146,13 @@ var documentsMain = { require({ }, ["webodf/editor/server/owncloud/ServerFactory", "webodf/editor/Editor"], function (ServerFactory, Editor) { // fade out file list and show WebODF canvas $('#content').fadeOut('slow').promise().done(function() { - documentsMain.UI.showEditor(documentsMain.getNameByFileid(response.file_id)); + + documentsMain.UI.showEditor( + documentsMain.getNameByFileid(response.file_id), + response.permissions & OC.PERMISSION_SHARE + ); var serverFactory = new ServerFactory(); - - runtime.assert(response.es_id, "invalid session id."); + var memberId = response.member_id; documentsMain.webodfServerInstance = serverFactory.createServer(); documentsMain.webodfServerInstance.setToken(oc_requesttoken);