Commit 3ed6f339 authored by Richard Mansfield's avatar Richard Mansfield Committed by Richard Mansfield
Browse files

Hide upload,create folder form when user lacks edit permission on parent folder



Bug #751123

Change-Id: If83a04b724b8f15e9b36f845905ebc5a1838be78
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
Reviewed-on: https://reviews.mahara.org/13

Reviewed-by: default avatarFrancois Marier <francois@catalyst.net.nz>
Tested-by: default avatarRichard Mansfield <richardm@mahara.org>
parent 3056240b
......@@ -115,6 +115,9 @@ function pieform_element_filebrowser(Pieform $form, $element) {
$maxuploadsize = display_size(get_max_upload_size(!$institution && !$group));
$smarty->assign('maxuploadsize', $maxuploadsize);
$smarty->assign('phpmaxfilesize', get_max_upload_size(false));
if ($group) {
$smarty->assign('uploaddisabled', !pieform_element_filebrowser_edit_group_folder($group, $folder));
}
}
if (!empty($element['browsehelp'])) {
......@@ -1070,6 +1073,7 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) {
'changedfolder' => true,
'tabupload' => $newtabdata['upload'],
'folder' => $folder,
'disableedit' => $group && !pieform_element_filebrowser_edit_group_folder($group, $folder),
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder, null, $user, $group, $institution),
'newpath' => pieform_element_filebrowser_build_path($form, $element, $folder, $newtabdata['owner'], $newtabdata['ownerid']),
'newtabs' => $newtabhtml,
......@@ -1100,10 +1104,16 @@ function pieform_element_filebrowser_changefolder(Pieform $form, $element, $fold
}
}
// If changing to a group folder, check whether the user can edit it
if ($g = ($owner ? $group : $form->get_property('group'))) {
$editgroupfolder = pieform_element_filebrowser_edit_group_folder($g, $folder);
}
return array(
'error' => false,
'changedfolder' => true,
'folder' => $folder,
'disableedit' => isset($editgroupfolder) && $editgroupfolder == false,
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder, null, $user, $group, $institution),
'newpath' => pieform_element_filebrowser_build_path($form, $element, $folder, $owner, $ownerid),
);
......
......@@ -616,6 +616,22 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
addElementClass(self.id + '_upload_container', 'hidden');
}
}
if (self.config.upload) {
if (data.disableedit && !hasElementClass(self.id + '_upload_container', 'hidden')) {
addElementClass(self.id + '_upload_container', 'hidden');
if ($('createfolder')) {
addElementClass('createfolder', 'hidden');
}
removeElementClass(self.id + '_upload_disabled', 'hidden');
}
else if (hasElementClass(self.id + '_upload_container', 'hidden') && !data.disableedit) {
removeElementClass(self.id + '_upload_container', 'hidden');
if ($('createfolder')) {
removeElementClass('createfolder', 'hidden');
}
addElementClass(self.id + '_upload_disabled', 'hidden');
}
}
}
else if (data.uploaded && self.config.select && data.highlight) {
// Newly uploaded files should be automatically selected
......
......@@ -35,7 +35,7 @@
</div>
{/if}
<table id="{$prefix}_upload_container" class="fileupload{if $tabs && !$tabs.upload} hidden{/if}">
<table id="{$prefix}_upload_container" class="fileupload{if ($tabs && !$tabs.upload) || $uploaddisabled} hidden{/if}">
<tbody>
{if $config.upload}
{* config.uploadagreement: disable the file chooser unless the agreement is checked *}
......@@ -73,6 +73,9 @@
{/if}
</tbody>
</table>
{if $config.upload}
<div id="{$prefix}_upload_disabled" class="uploaddisabled{if !$uploaddisabled} hidden{/if}">{str tag="cannoteditfolder" section=artefact.file}</div>
{/if}
{if $config.edit}
<input type="hidden" name="{$prefix}_move" id="{$prefix}_move" value="" />
......@@ -84,7 +87,7 @@
</div>
{if $config.createfolder}
<div id="createfolder"><div id="{$prefix}_createfolder_messages" class="createfolder-message"></div>
<div id="createfolder"{if $uploaddisabled} class="hidden"{/if}><div id="{$prefix}_createfolder_messages" class="createfolder-message"></div>
<input type="text" class="text" name="{$prefix}_createfolder_name" id="{$prefix}_createfolder_name" size="40" />
<input type="submit" class="submit" name="{$prefix}_createfolder" id="{$prefix}_createfolder" value="{str tag=createfolder section=artefact.file}" /></div>
{/if}
......
......@@ -25,6 +25,12 @@
margin-bottom: 10px;
width: 100%;
}
.uploaddisabled {
background: #eee;
border: 1px solid #d1d1d1;
margin-bottom: 10px;
padding: .25em;
}
* html .fileupload {
width: 98%;
}
......@@ -49,7 +55,6 @@
background-color: #EEE;
border: 1px solid #D1D1D1;
padding: 3px 5px;
display: block;
margin: 10px 0 5px 0;
}
#upload {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment