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

Add site option to restrict group creation to admins/staff (bug 3045)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent b148ffe4
......@@ -125,6 +125,17 @@ $siteoptionform = array(
'options' => $yesno,
'help' => true,
),
'creategroups' => array(
'type' => 'select',
'title' => get_string('whocancreategroups', 'admin'),
'description' => get_string('whocancreategroupsdescription', 'admin'),
'defaultvalue' => get_config('creategroups'),
'options' => array(
'admins' => get_string('adminsonly', 'admin'),
'staff' => get_string('adminsandstaffonly', 'admin'),
'all' => get_string('Everyone', 'admin'),
),
),
'createpublicgroups' => array(
'type' => 'select',
'title' => get_string('whocancreatepublicgroups', 'admin'),
......@@ -238,7 +249,7 @@ function siteoptions_submit(Pieform $form, $values) {
$fields = array(
'sitename','lang','theme', 'pathtoclam',
'defaultaccountlifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
'allowpublicviews', 'allowpublicprofiles', 'createpublicgroups', 'searchplugin',
'allowpublicviews', 'allowpublicprofiles', 'creategroups', 'createpublicgroups', 'searchplugin',
'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend',
'captchaonregisterform', 'captchaoncontactform', 'showselfsearchsideblock', 'showtagssideblock',
'tagssideblockmaxtags'
......
......@@ -32,6 +32,10 @@ require_once('pieforms/pieform.php');
require_once('group.php');
define('TITLE', get_string('creategroup', 'group'));
if (!group_can_create_groups()) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
$creategroup = pieform(array(
'name' => 'creategroup',
'method' => 'post',
......@@ -90,9 +94,6 @@ $smarty->display('group/create.tpl');
function creategroup_validate(Pieform $form, $values) {
//global $USER;
//global $SESSION;
if (get_field('group', 'id', 'name', $values['name'])) {
$form->set_error('name', get_string('groupalreadyexists', 'group'));
}
......
......@@ -78,6 +78,7 @@ group_prepare_usergroups_for_display($results['groups'], 'mygroups');
$smarty = smarty();
$smarty->assign('groups', $results['groups']);
$smarty->assign('cancreate', group_can_create_groups());
$smarty->assign('form', $form);
$smarty->assign('filter', $filter);
$smarty->assign('pagination', $pagination['html']);
......
......@@ -141,6 +141,7 @@ $string['reopensitedetail'] = 'Your site is closed. Site administrators may sta
// Site options
$string['adminsonly'] = 'Administrators only';
$string['adminsandstaffonly'] = 'Administrators and Staff only';
$string['allowpublicviews'] = 'Allow public views';
$string['allowpublicviewsdescription'] = 'If set to yes, users will be able to create portfolio Views that are accessable to the public rather than only to logged in users';
$string['allowpublicprofiles'] = 'Allow public profiles';
......@@ -191,8 +192,10 @@ $string['usersallowedmultipleinstitutionsdescription'] = 'If checked, users can
$string['usersseenewthemeonlogin'] = 'Other users will see the new theme the next time they log in.';
$string['viruschecking'] = 'Virus checking';
$string['viruscheckingdescription'] = 'If checked, virus checking will be enabled for all uploaded files using ClamAV';
$string['whocancreategroups'] = 'Who can create Groups';
$string['whocancreategroupsdescription'] = 'Which users will be able to create new groups';
$string['whocancreatepublicgroups'] = 'Who can create Public Groups';
$string['whocancreatepublicgroupsdescription'] = 'If set to yes, users will be able to make groups that are viewable by the general public';
$string['whocancreatepublicgroupsdescription'] = 'Which users will be able to make groups that are viewable by the general public';
// Site content
$string['about'] = 'About';
......
......@@ -1256,6 +1256,10 @@ function xmldb_core_upgrade($oldversion=0) {
drop_field($table, $field);
}
if ($oldversion < 2009110500) {
set_config('creategroups', 'all');
}
return $status;
}
......
......@@ -1141,4 +1141,16 @@ function group_get_member_ids($group, $roles=null) {
array($group)
);
}
function group_can_create_groups() {
global $USER;
$creators = get_config('creategroups');
if ($creators == 'all') {
return true;
}
if ($USER->get('admin') || $USER->is_institutional_admin()) {
return true;
}
return $creators == 'staff' && ($USER->get('staff') || $USER->is_institutional_staff());
}
?>
......@@ -661,6 +661,7 @@ function core_install_firstcoredata_defaults() {
set_config('session_timeout', 86400);
set_config('sitename', 'Mahara');
set_config('defaultaccountinactivewarn', 604800);
set_config('creategroups', 'all');
set_config('createpublicgroups', 'all');
set_config('allowpublicviews', 1);
set_config('allowpublicprofiles', 1);
......
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2009102900;
$config->version = 2009110500;
$config->release = '1.2.0beta5dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
{include file="header.tpl"}
{if $cancreate}
<div class="rbuttons">
<a href="{$WWWROOT}group/create.php" class="btn">{str tag="creategroup" section="group"}</a>
</div>
{/if}
{$form}
{if $groups}
{foreach from=$groups item=group}
......
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