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.
This commit is contained in:
Pranav Kant 2016-10-11 13:00:20 +05:30
parent 1174105402
commit c24c5a0439
4 changed files with 40 additions and 4 deletions

View File

@ -270,6 +270,7 @@ class DocumentController extends Controller {
'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($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, 'wopi_url' => $webSocket,
'edit_groups' => $this->appConfig->getAppValue('edit_groups')
]); ]);
$policy = new ContentSecurityPolicy(); $policy = new ContentSecurityPolicy();

View File

@ -33,13 +33,21 @@ var documentsSettings = {
}, },
initEditGroups: function() { initEditGroups: function() {
var groups = $('#edit_group_select').val().split('|'); var groups = $('#edit_group_select').val();
if (groups.length) { if (groups !== '') {
OC.Settings.setupGroupsSelect($('#edit_group_select')); OC.Settings.setupGroupsSelect($('#edit_group_select'));
$('.edit-groups-enable').attr('checked', 'checked'); $('.edit-groups-enable').attr('checked', 'checked');
} else { } else {
$('.edit-groups-enable').attr('checked', null); $('.edit-groups-enable').attr('checked', null);
} }
$.get(
OC.generateUrl('/settings/users/users'),
{ limit: 1, pattern: 'admin' },
function(result) {
console.log(result);
}
);
}, },
initialize: function() { initialize: function() {

View File

@ -17,6 +17,31 @@ $.widget('oc.documentGrid', {
jQuery.when(this._load(fileId)) jQuery.when(this._load(fileId))
.then(function(){ .then(function(){
that._render(); 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; documentsMain.renderComplete = true;
}); });
}, },
@ -188,6 +213,7 @@ var documentsMain = {
fileName: null, fileName: null,
baseName: null, baseName: null,
canShare : false, canShare : false,
canEdit: false,
loadError : false, loadError : false,
loadErrorMessage : '', loadErrorMessage : '',
loadErrorHint : '', loadErrorHint : '',
@ -455,7 +481,7 @@ var documentsMain = {
"&lang=" + $('li[data-id='+ documentsMain.fileId +']>a').attr('lolang') + "&lang=" + $('li[data-id='+ documentsMain.fileId +']>a').attr('lolang') +
"&closebutton=1" + "&closebutton=1" +
"&revisionhistory=1"; "&revisionhistory=1";
if (action === "view") { if (!documentsMain.canEdit || action === "view") {
urlsrc += "&permission=readonly"; urlsrc += "&permission=readonly";
} }

View File

@ -52,3 +52,4 @@ script('files', 'jquery.fileupload');
<input type="hidden" id="previews_enabled" value="<?php p($_['enable_previews']) ?>" /> <input type="hidden" id="previews_enabled" value="<?php p($_['enable_previews']) ?>" />
<?php endif; ?> <?php endif; ?>
<input type="hidden" name="allowShareWithLink" id="allowShareWithLink" value="<?php p($_['allowShareWithLink']) ?>" /> <input type="hidden" name="allowShareWithLink" id="allowShareWithLink" value="<?php p($_['allowShareWithLink']) ?>" />
<input type="hidden" name="edit_groups" id="edit_groups" value="<?php p($_['edit_groups']) ?>" />