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.
pull/1/head
Pranav Kant 8 years ago
parent de62725ed2
commit 1ad1f667ee

@ -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();

@ -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;

@ -53,3 +53,4 @@ script('files', 'jquery.fileupload');
<?php endif; ?>
<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']) ?>" />
<input type="hidden" name="usergroups" id="usergroups" value="<?php p($_['usergroups']) ?>" />

Loading…
Cancel
Save