Commit 457e2f19 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow users to put their own files into group views (bug 3283)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent d4f0e071
...@@ -189,7 +189,7 @@ function pieform_element_filebrowser_build_path($form, $element, $folder, $owner ...@@ -189,7 +189,7 @@ function pieform_element_filebrowser_build_path($form, $element, $folder, $owner
} }
function pieform_element_filebrowser_build_filelist($form, $element, $folder, $highlight=null, $group=null, $institution=null) { function pieform_element_filebrowser_build_filelist($form, $element, $folder, $highlight=null, $user=null, $group=null, $institution=null) {
if (!$form->submitted_by_js()) { if (!$form->submitted_by_js()) {
// We're going to rebuild the page from scratch anyway. // We're going to rebuild the page from scratch anyway.
return; return;
...@@ -199,7 +199,7 @@ function pieform_element_filebrowser_build_filelist($form, $element, $folder, $h ...@@ -199,7 +199,7 @@ function pieform_element_filebrowser_build_filelist($form, $element, $folder, $h
$smarty = smarty_core(); $smarty = smarty_core();
if (is_null($group)) { if (is_null($group) && is_null($user)) {
$group = $form->get_property('group'); $group = $form->get_property('group');
} }
else { else {
...@@ -260,6 +260,7 @@ function pieform_element_filebrowser_configure_tabs($viewowner) { ...@@ -260,6 +260,7 @@ function pieform_element_filebrowser_configure_tabs($viewowner) {
else if ($viewowner['type'] == 'group') { else if ($viewowner['type'] == 'group') {
$selectedtab = param_variable('owner', 'group'); $selectedtab = param_variable('owner', 'group');
$upload = $selectedtab == 'group'; $upload = $selectedtab == 'group';
$tabs['user'] = get_string('myfiles', 'artefact.file');
$tabs['group'] = get_string('groupfiles', 'artefact.file'); $tabs['group'] = get_string('groupfiles', 'artefact.file');
} }
else { // $viewowner['type'] == 'user' else { // $viewowner['type'] == 'user'
...@@ -924,6 +925,7 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) { ...@@ -924,6 +925,7 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) {
$group = null; $group = null;
$institution = null; $institution = null;
$user = null;
$folder = 0; $folder = 0;
if ($newtabdata['owner'] == 'site') { if ($newtabdata['owner'] == 'site') {
global $USER; global $USER;
...@@ -938,6 +940,9 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) { ...@@ -938,6 +940,9 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) {
else if ($newtabdata['owner'] == 'group') { else if ($newtabdata['owner'] == 'group') {
$group = $newtabdata['ownerid']; $group = $newtabdata['ownerid'];
} }
else if ($newtabdata['owner'] == 'user') {
$user = true;
}
return array( return array(
'error' => false, 'error' => false,
...@@ -945,7 +950,7 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) { ...@@ -945,7 +950,7 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) {
'changedfolder' => true, 'changedfolder' => true,
'tabupload' => $newtabdata['upload'], 'tabupload' => $newtabdata['upload'],
'folder' => $folder, 'folder' => $folder,
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder, null, $group, $institution), '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']), 'newpath' => pieform_element_filebrowser_build_path($form, $element, $folder, $newtabdata['owner'], $newtabdata['ownerid']),
'newtabs' => $newtabhtml, 'newtabs' => $newtabhtml,
'newsubtabs' => $newsubtabhtml, 'newsubtabs' => $newsubtabhtml,
...@@ -954,7 +959,7 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) { ...@@ -954,7 +959,7 @@ function pieform_element_filebrowser_changeowner(Pieform $form, $element) {
function pieform_element_filebrowser_changefolder(Pieform $form, $element, $folder) { function pieform_element_filebrowser_changefolder(Pieform $form, $element, $folder) {
$owner = $ownerid = $group = $institution = null; $owner = $ownerid = $group = $institution = $user = null;
if (isset($element['tabs'])) { if (isset($element['tabs'])) {
if ($owner = param_variable('owner', null)) { if ($owner = param_variable('owner', null)) {
...@@ -964,9 +969,13 @@ function pieform_element_filebrowser_changefolder(Pieform $form, $element, $fold ...@@ -964,9 +969,13 @@ function pieform_element_filebrowser_changefolder(Pieform $form, $element, $fold
} else if ($ownerid = param_variable('ownerid', null)) { } else if ($ownerid = param_variable('ownerid', null)) {
if ($owner == 'group') { if ($owner == 'group') {
$group = (int) $ownerid; $group = (int) $ownerid;
} else if ($owner == 'institution') { }
else if ($owner == 'institution') {
$institution = $ownerid; $institution = $ownerid;
} }
else if ($owner == 'user') {
$user = true;
}
} }
} }
} }
...@@ -975,7 +984,7 @@ function pieform_element_filebrowser_changefolder(Pieform $form, $element, $fold ...@@ -975,7 +984,7 @@ function pieform_element_filebrowser_changefolder(Pieform $form, $element, $fold
'error' => false, 'error' => false,
'changedfolder' => true, 'changedfolder' => true,
'folder' => $folder, 'folder' => $folder,
'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder, null, $group, $institution), 'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder, null, $user, $group, $institution),
'newpath' => pieform_element_filebrowser_build_path($form, $element, $folder, $owner, $ownerid), 'newpath' => pieform_element_filebrowser_build_path($form, $element, $folder, $owner, $ownerid),
); );
} }
......
...@@ -807,6 +807,11 @@ class BlockInstance { ...@@ -807,6 +807,11 @@ class BlockInstance {
public function rebuild_artefact_list() { public function rebuild_artefact_list() {
db_begin(); db_begin();
// Remember what was in this block before saving, and always allow those artefacts to remain
// in it, regardless of the user's current permissions.
$old = get_records_assoc('view_artefact', 'block', $this->id, '', 'artefact, id');
delete_records('view_artefact', 'block', $this->id); delete_records('view_artefact', 'block', $this->id);
safe_require('blocktype', $this->get('blocktype')); safe_require('blocktype', $this->get('blocktype'));
if (!$artefacts = call_static_method( if (!$artefacts = call_static_method(
...@@ -831,7 +836,8 @@ class BlockInstance { ...@@ -831,7 +836,8 @@ class BlockInstance {
// Get list of allowed artefacts // Get list of allowed artefacts
require_once('view.php'); require_once('view.php');
$searchdata = array( $searchdata = array(
'extraselect' => 'id IN (' . join(',', $artefacts) . ')', 'extraselect' => 'id IN (' . join(',', $artefacts) . ')',
'userartefactsallowed' => true, // If this is a group view, the user can add personally owned artefacts
); );
list($allowed, $count) = View::get_artefactchooser_artefacts( list($allowed, $count) = View::get_artefactchooser_artefacts(
$searchdata, $searchdata,
...@@ -846,7 +852,7 @@ class BlockInstance { ...@@ -846,7 +852,7 @@ class BlockInstance {
$va->block = $this->id; $va->block = $this->id;
foreach ($artefacts as $id) { foreach ($artefacts as $id) {
if (isset($allowed[$id])) { if (isset($allowed[$id]) || isset($old[$id])) {
$va->artefact = $id; $va->artefact = $id;
insert_record('view_artefact', $va); insert_record('view_artefact', $va);
} }
......
...@@ -1849,7 +1849,11 @@ class View { ...@@ -1849,7 +1849,11 @@ class View {
AND m.member = ' . $user->get('id') . ' AND m.member = ' . $user->get('id') . '
AND r.can_view = 1 AND r.can_view = 1
) ga ON (ga.group = a.group AND a.id = ga.artefact)'; ) ga ON (ga.group = a.group AND a.id = ga.artefact)';
$select = "(a.institution = 'mahara' OR ga.can_view = 1)"; $select = "(a.institution = 'mahara' OR ga.can_view = 1";
if (!empty($data['userartefactsallowed'])) {
$select .= ' OR owner = ' . $user->get('id');
}
$select .= ')';
} }
else if ($institution) { else if ($institution) {
// Site artefacts & artefacts owned by this institution // Site artefacts & artefacts owned by this institution
......
Supports Markdown
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