From 1ad1f667ee1c9dbc3470299bb5b441ffae1d6bc4 Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Thu, 13 Oct 2016 20:50:48 +0530 Subject: [PATCH] Simplify edit group checking algorithm Rather than making a server call, which seems to be not working always anyways, use a foolproof method for this. --- controller/documentcontroller.php | 12 +++++++++--- js/documents.js | 28 +++++++++------------------- templates/documents.php | 1 + 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php index 61b0f20e..ec43bdc2 100644 --- a/controller/documentcontroller.php +++ b/controller/documentcontroller.php @@ -292,16 +292,22 @@ class DocumentController extends Controller { return $this->responseError($this->l10n->t('Collabora Online: Invalid URL "%s".', array($wopiRemote)), $this->l10n->t('Please ask your administrator to check the Collabora Online server setting.')); } + $user = \OC::$server->getUserSession()->getUser(); + $usergroups = array_filter(\OC::$server->getGroupManager()->getUserGroupIds($user)); + $usergroups = join('|', $usergroups); + \OC::$server->getLogger()->debug('User is in groups: {groups}', [ 'app' => $this->appName, 'groups' => $usergroups ]); + \OC::$server->getNavigationManager()->setActiveEntry( 'richdocuments_index' ); $maxUploadFilesize = \OCP\Util::maxUploadFilesize("/"); $response = new TemplateResponse('richdocuments', 'documents', [ - 'enable_previews' => $this->settings->getSystemValue('enable_previews', true), + 'enable_previews' => $this->settings->getSystemValue('enable_previews', true), 'uploadMaxFilesize' => $maxUploadFilesize, 'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize), - 'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'), + 'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'), 'wopi_url' => $webSocket, 'edit_groups' => $this->appConfig->getAppValue('edit_groups'), - 'doc_format' => $this->appConfig->getAppValue('doc_format') + 'doc_format' => $this->appConfig->getAppValue('doc_format'), + 'usergroups' => $usergroups ]); $policy = new ContentSecurityPolicy(); diff --git a/js/documents.js b/js/documents.js index 809c2b0b..a8e81839 100644 --- a/js/documents.js +++ b/js/documents.js @@ -19,27 +19,17 @@ $.widget('oc.documentGrid', { that._render(); if (!documentsMain.isGuest) { - $.ajax({ - url: OC.generateUrl('/settings/users/users'), - type: 'get', - data: { limit: 1, pattern: OC.currentUser }, - async: false, - success: function(result) { - var editGroups = $('#edit_groups').val(); - documentsMain.canEdit = (editGroups === ''); - if (!documentsMain.canEdit && result.length >= 1) { - for (var idx in result[0].groups) { - if (editGroups.indexOf(result[0].groups[idx]) !== -1) { - documentsMain.canEdit = true; - break; - } - } + var editGroups = $('#edit_groups').val().split('|'); + var usergroups = $('#usergroups').val().split('|'); + documentsMain.canEdit = (editGroups.length === 0); + if (!documentsMain.canEdit && usergroups.length >= 1) { + for (var idx in usergroups) { + if (editGroups.indexOf(usergroups[idx]) !== -1) { + documentsMain.canEdit = true; + break; } - }, - error: function() { - console.log('Error fetching information about current user.'); } - }); + } } documentsMain.renderComplete = true; diff --git a/templates/documents.php b/templates/documents.php index 898e2219..3840eafd 100644 --- a/templates/documents.php +++ b/templates/documents.php @@ -53,3 +53,4 @@ script('files', 'jquery.fileupload'); +