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

Let group admins hide their group in searches (bug #845285)



Adds a 'hidden' checkbox on the group edit form for site &
institutional admins & staff.  Hidden groups are filtered out of
searches on the find groups page, unless the logged-in user is
already a member.

Adds a new 'Visibility' section to the edit group page.

Change-Id: I25e32623f150cb393f126dccdad50d705684b59e
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 1e4f1c55
......@@ -51,6 +51,7 @@ $ALLOWEDKEYS = array(
'public',
'submitpages',
'editroles',
'hidden',
);
if ($USER->get('admin')) {
$ALLOWEDKEYS[] = 'usersautoadded';
......
......@@ -68,6 +68,7 @@ else {
'viewnotify' => 1,
'submittableto' => 0,
'editroles' => 'all',
'hidden' => 0,
);
}
......@@ -209,12 +210,6 @@ else {
);
}
$elements['general'] = array(
'type' => 'html',
'title' => get_string('general'),
'value' => '',
);
$publicallowed = get_config('createpublicgroups') == 'all' || (get_config('createpublicgroups') == 'admins' && $USER->get('admin'));
if (!$id && !param_variable('editgroup_submit', null)) {
......@@ -222,13 +217,44 @@ if (!$id && !param_variable('editgroup_submit', null)) {
$publicparam = param_integer('public', null);
}
$ignorepublic = !$publicallowed || (isset($publicparam) && $publicparam === 0);
if ($cancreatecontrolled || !$ignorepublic) {
$elements['visibility'] = array(
'type' => 'html',
'title' => get_string('Visibility'),
'value' => '',
);
}
$elements['public'] = array(
'type' => 'checkbox',
'title' => get_string('publiclyviewablegroup', 'group'),
'description' => get_string('publiclyviewablegroupdescription', 'group'),
'defaultvalue' => $group_data->public,
'help' => true,
'ignore' => !$publicallowed || (isset($publicparam) && $publicparam === 0),
'ignore' => $ignorepublic,
);
if ($cancreatecontrolled) {
$elements['hidden'] = array(
'type' => 'checkbox',
'title' => get_string('hiddengroup', 'group'),
'description' => get_string('hiddengroupdescription', 'group'),
'defaultvalue' => $group_data->hidden,
);
}
else {
$form['elements']['hidden'] = array(
'type' => 'hidden',
'value' => $group_data->hidden,
);
}
$elements['general'] = array(
'type' => 'html',
'title' => get_string('general'),
'value' => '',
);
if (get_config('allowgroupcategories')
......@@ -310,6 +336,7 @@ function editgroup_submit(Pieform $form, $values) {
'viewnotify' => intval($values['viewnotify']),
'submittableto' => intval($values['submittableto']),
'editroles' => $values['editroles'],
'hidden' => intval($values['hidden']),
);
db_begin();
......
......@@ -96,6 +96,8 @@ $string['groupinvitesfrom'] = 'Invited to join:';
$string['requestedmembershipin'] = 'Requested membership in:';
$string['viewnotify'] = 'Shared page notifications';
$string['viewnotifydescription'] = 'If checked, a notification will be sent to every group member whenever a member shares one of their pages with the group. Enabling this setting in very large groups can produce a lot of notifications.';
$string['hiddengroup'] = 'Hidden group';
$string['hiddengroupdescription'] = 'Do not list this group on the Find Groups page.';
$string['editgroupmembership'] = 'Edit group membership';
$string['editmembershipforuser'] = 'Edit membership for %s';
......
......@@ -932,6 +932,7 @@ $string['Total'] = 'Total';
$string['Visits'] = 'Visits';
$string['after'] = 'after';
$string['before'] = 'before';
$string['Visibility'] = 'Visibility';
// import related strings (maybe separated later)
$string['importedfrom'] = 'Imported from %s';
......
......@@ -344,6 +344,7 @@
<FIELD NAME="request" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="submittableto" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="editroles" TYPE="char" LENGTH="20" NOTNULL="true" ENUM="true" ENUMVALUES="'all', 'notmember', 'admin'" DEFAULT="all" />
<FIELD NAME="hidden" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......
......@@ -2709,6 +2709,12 @@ function xmldb_core_upgrade($oldversion=0) {
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
set_field('view', 'locked', 1, 'type', 'grouphomepage');
// Setting to hide groups from the "Find Groups" listing
$table = new XMLDBTable('group');
$field = new XMLDBField('hidden');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
}
return $status;
......
......@@ -274,6 +274,7 @@ function group_create($data) {
$data['ctime'] = db_format_timestamp($data['ctime']);
$data['public'] = (isset($data['public'])) ? intval($data['public']) : 0;
$data['hidden'] = (isset($data['hidden'])) ? intval($data['hidden']) : 0;
$data['usersautoadded'] = (isset($data['usersautoadded'])) ? intval($data['usersautoadded']) : 0;
$data['quota'] = get_config_plugin('artefact', 'file', 'defaultgroupquota');
......@@ -348,6 +349,7 @@ function group_create($data) {
'request' => isset($data['request']) ? intval($data['request']) : 0,
'submittableto' => intval($data['submittableto']),
'editroles' => $data['editroles'],
'hidden' => $data['hidden'],
),
'id',
true
......@@ -454,7 +456,7 @@ function group_update($new, $create=false) {
unset($new->institution);
unset($new->shortname);
foreach (array('id', 'grouptype', 'public', 'request', 'submittableto', 'editroles') as $f) {
foreach (array('id', 'grouptype', 'public', 'request', 'submittableto', 'editroles', 'hidden') as $f) {
if (!isset($new->$f)) {
$new->$f = $old->$f;
}
......
......@@ -682,12 +682,21 @@ class PluginSearchInternal extends PluginSearch {
$grouproles = '-1';
}
$canseehidden = $USER->get('admin') || $USER->get('staff');
if ($type == 'member') {
$sql .= 'AND id IN (' . $grouproles . ')';
}
else if ($type == 'notmember') {
$sql .= 'AND id NOT IN (' . $grouproles . ')';
if (!$canseehidden) {
$sql .= ' AND hidden = 0';
}
}
else if (!$canseehidden) {
$sql .= ' AND (hidden = 0 OR id IN (' . $grouproles . '))';
}
if (!empty($category)) {
if ($category == -1) { //find unassigned groups
$sql .= " AND category IS NULL";
......
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