Commit dc05c081 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Set appropriate public/private access permissions on homepage when editing or creating groups


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 703e15e4
......@@ -174,6 +174,20 @@ function editgroup_submit(Pieform $form, $values) {
set_field('group_member', 'role', 'member', 'group', $values['id'], 'role', 'tutor');
}
// When a group changes from public -> private or vice versa, set the
// appropriate access permissions on the group homepage view.
if ($group_data->public != $values['public']) {
$homepageid = get_field('view', 'id', 'type', 'grouphomepage', 'group', $group_data->id);
if ($group_data->public && !$values['public']) {
delete_records('view_access', 'view', $homepageid, 'accesstype', 'public');
insert_record('view_access', (object) array('view' => $homepageid, 'accesstype' => 'loggedin'));
}
else if (!$group_data->public && $values['public']) {
delete_records('view_access', 'view', $homepageid, 'accesstype', 'loggedin');
insert_record('view_access', (object) array('view' => $homepageid, 'accesstype' => 'public'));
}
}
$SESSION->add_ok_msg(get_string('groupsaved', 'group'));
db_commit();
......
......@@ -314,16 +314,20 @@ function group_create($data) {
$data['id'] = $id;
// install the homepage
if ($t = get_record('view', 'type', 'grouphomepage', 'template', 1)) {
if ($t = get_record('view', 'type', 'grouphomepage', 'template', 1, 'owner', 0)) {
require_once('view.php');
$template = new View($t->id, (array)$t);
View::create_from_template(array(
list($homepage) = View::create_from_template(array(
'group' => $id,
'title' => $template->get('title'),
'description' => $template->get('description'),
'type' => 'grouphomepage',
), $t->id, 0, false);
}
insert_record('view_access', (object) array(
'view' => $homepage->get('id'),
'accesstype' => $data['public'] ? 'public' : 'loggedin',
));
handle_event('creategroup', $data);
db_commit();
......
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