diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php index 9e310ec3..f4303475 100644 --- a/controller/documentcontroller.php +++ b/controller/documentcontroller.php @@ -269,7 +269,8 @@ class DocumentController extends Controller { 'uploadMaxFilesize' => $maxUploadFilesize, 'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize), 'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'), - 'wopi_url' => $webSocket, + 'wopi_url' => $webSocket, + 'edit_groups' => $this->appConfig->getAppValue('edit_groups') ]); $policy = new ContentSecurityPolicy(); diff --git a/controller/settingscontroller.php b/controller/settingscontroller.php index 5a5e9897..8bf3289b 100644 --- a/controller/settingscontroller.php +++ b/controller/settingscontroller.php @@ -63,16 +63,21 @@ class SettingsController extends Controller{ 'admin', [ 'wopi_url' => $this->appConfig->getAppValue('wopi_url'), + 'edit_groups' => $this->appConfig->getAppValue('edit_groups') ], 'blank' ); } - public function setSettings($wopi_url){ + public function setSettings($wopi_url, $edit_groups){ if (!is_null($wopi_url)){ $this->appConfig->setAppValue('wopi_url', $wopi_url); } + if (!is_null($edit_groups)){ + $this->appConfig->setAppValue('edit_groups', $edit_groups); + } + $richMemCache = \OC::$server->getMemCacheFactory()->create('richdocuments'); $richMemCache->clear('discovery.xml'); diff --git a/js/admin.js b/js/admin.js index f398a12d..627c2615 100644 --- a/js/admin.js +++ b/js/admin.js @@ -1,27 +1,88 @@ /*global OC, $ */ -$(document).ready(function(){ +var documentsSettings = { + save : function() { + $('#wopi_apply').attr('disabled', true); + var data = { + wopi_url : $('#wopi_url').val() + }; + + OC.msg.startAction('#documents-admin-msg', t('richdocuments', 'Saving...')); + $.post( + OC.filePath('richdocuments', 'ajax', 'admin.php'), + data, + documentsSettings.afterSave + ); + }, + + saveGroups: function(groups) { + var data = { + 'edit_groups': groups.join('|') + }; + + console.log('posting to setSettings'); + $.post( + OC.filePath('richdocuments', 'ajax', 'admin.php'), + data + ); + }, - var documentsSettings = { - save : function() { - $('#wopi_apply').attr('disabled', true); - var data = { - wopi_url : $('#wopi_url').val() - }; - - OC.msg.startAction('#documents-admin-msg', t('richdocuments', 'Saving...')); - $.post( - OC.filePath('richdocuments', 'ajax', 'admin.php'), - data, - documentsSettings.afterSave - ); - }, - - afterSave : function(response){ - $('#wopi_apply').attr('disabled', false); - OC.msg.finishedAction('#documents-admin-msg', response); + afterSave : function(response){ + $('#wopi_apply').attr('disabled', false); + OC.msg.finishedAction('#documents-admin-msg', response); + }, + + initEditGroups: function() { + var groups = $('#edit_group_select').val(); + if (groups !== '') { + OC.Settings.setupGroupsSelect($('#edit_group_select')); + $('.edit-groups-enable').attr('checked', 'checked'); + } else { + $('.edit-groups-enable').attr('checked', null); } - }; - $('#wopi_apply').on('click', documentsSettings.save); + $.get( + OC.generateUrl('/settings/users/users'), + { limit: 1, pattern: 'admin' }, + function(result) { + console.log(result); + } + ); + }, + + initialize: function() { + $('#wopi_apply').on('click', documentsSettings.save); + documentsSettings.initEditGroups(); + + $(document).on('change', '#edit_group_select', function() { + var element = $(this).parent().find('input.edit-groups-enable'); + var groups = $(this).val(); + if (groups && groups !== '') { + groups = groups.split('|'); + } else { + groups = []; + } + + documentsSettings.saveGroups(groups); + }); + + $(document).on('change', '.edit-groups-enable', function() { + var $select = $(this).parent().find('#edit_group_select'); + $select.val(''); + + if (this.checked) { + OC.Settings.setupGroupsSelect($select, { + placeholder: t('core', 'All') + }); + } else { + $select.select2('destroy'); + } + + $select.change(); + }); + } +}; + +$(document).ready(function(){ + documentsSettings.initialize(); }); diff --git a/js/documents.js b/js/documents.js index 105926ba..7179389c 100644 --- a/js/documents.js +++ b/js/documents.js @@ -17,6 +17,31 @@ $.widget('oc.documentGrid', { jQuery.when(this._load(fileId)) .then(function(){ 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; + } + } + } + }, + error: function() { + console.log('Error fetching information about current user.'); + } + }); + } + documentsMain.renderComplete = true; }); }, @@ -188,6 +213,7 @@ var documentsMain = { fileName: null, baseName: null, canShare : false, + canEdit: false, loadError : false, loadErrorMessage : '', loadErrorHint : '', @@ -455,7 +481,7 @@ var documentsMain = { "&lang=" + $('li[data-id='+ documentsMain.fileId +']>a').attr('lolang') + "&closebutton=1" + "&revisionhistory=1"; - if (action === "view") { + if (!documentsMain.canEdit || action === "view") { urlsrc += "&permission=readonly"; } diff --git a/templates/admin.php b/templates/admin.php index fa1d5738..7a82d418 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -8,4 +8,9 @@ script('richdocuments', 'admin');
t('URL (and port) of the Collabora Online server that provides the editing functionality as a WOPI client.')) ?>
+
+ + +
+ diff --git a/templates/documents.php b/templates/documents.php index 2019fbae..75594590 100644 --- a/templates/documents.php +++ b/templates/documents.php @@ -52,3 +52,4 @@ script('files', 'jquery.fileupload'); +