diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2016-10-11 10:30:20 +0300 |
---|---|---|
committer | Pranav Kant <pranavk@collabora.co.uk> | 2016-10-11 10:51:35 +0300 |
commit | c24c5a04396f452e1a9be1fa5c304fb5597b684e (patch) | |
tree | d60d4ab81c9194f3d4144abbd7fc7cae36448b12 /js | |
parent | 11741054021c42072362c23a7fd2868be56be10b (diff) |
Only allow users to edit documents if part of edit groups
If edit group setting is not set in Collabora Online settings,
then allow all users.
Diffstat (limited to 'js')
-rw-r--r-- | js/admin.js | 12 | ||||
-rw-r--r-- | js/documents.js | 28 |
2 files changed, 37 insertions, 3 deletions
diff --git a/js/admin.js b/js/admin.js index c54e5761..627c2615 100644 --- a/js/admin.js +++ b/js/admin.js @@ -33,13 +33,21 @@ var documentsSettings = { }, initEditGroups: function() { - var groups = $('#edit_group_select').val().split('|'); - if (groups.length) { + 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); } + + $.get( + OC.generateUrl('/settings/users/users'), + { limit: 1, pattern: 'admin' }, + function(result) { + console.log(result); + } + ); }, initialize: function() { 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"; } |