Commit 0041c510 authored by RafGDev's avatar RafGDev Committed by Robert Lyon
Browse files

Bug 1033073 Change ability to hide tutors from group membership display.

This patch changes the current toggle options for group membership display
to a dropdown that allows a group admin to choose whether tutors are
displayed or not.

Change-Id: I173f29a10d1ee51036282770b35e5c93a679b1d8
parent 23e00618
......@@ -362,7 +362,7 @@ $grouptypes .= get_string('uploadgroupcsveditrolesdescription', 'admin', get_hel
$fields = "<ul class='fieldslist column-list'>\n";
foreach ($ALLOWEDKEYS as $type) {
$helplink = '';
if ($type == 'public' || $type == 'usersautoadded') {
if ($type == 'public' || $type == 'usersautoadded' || $type == 'hidemembers') {
$helplink = get_help_icon('core', 'groups', 'editgroup', $type);
}
$fields .= '<li>' . hsc($type) . $helplink . "</li>\n";
......
......@@ -60,15 +60,18 @@ class PluginBlocktypeGroupMembers extends MaharaCoreBlocktype {
// If the group has hidden membership, display nothing
$usergroups = $USER->get('grouproles');
$group = defined('GROUP') && $groupid == GROUP ? group_current_group() : get_record('group', 'id', $groupid);
if ($group->hidemembersfrommembers && (!isset($usergroups[$groupid]) || $usergroups[$groupid] != 'admin')) {
if ($group->hidemembersfrommembers === '1' && (!isset($usergroups[$groupid]) || $usergroups[$groupid] != 'admin')) {
return '';
}
if ($group->hidemembers && !isset($usergroups[$groupid])) {
if ($group->hidemembers === '1' && !isset($usergroups[$groupid])) {
return '';
}
require_once('searchlib.php');
$groupmembers = get_group_user_search_results($groupid, '', 0, $numtoshow, '', $order);
$role = group_user_access($group->id);
$hidetutors = ( (!$USER->get('admin') && !$USER->get('staff') && !$role && $group->hidemembers === '2') ||
(!$USER->get('admin') && !$USER->get('staff') && $role == 'member' && $group->hidemembersfrommembers === '2') ) ? true : false;
$groupmembers = get_group_user_search_results($groupid, '', 0, $numtoshow, '', $order, null, null, $hidetutors);
if ($groupmembers['count']) {
$smarty = smarty_core();
......
......@@ -59,8 +59,6 @@ else {
'allowarchives' => 0,
'editroles' => 'all',
'hidden' => 0,
'hidemembers' => 0,
'hidemembersfrommembers' => 0,
'groupparticipationreports' => 0,
'invitefriends' => 0,
'suggestfriends' => 0,
......@@ -69,6 +67,8 @@ else {
'editwindowend' => null,
'sendnow' => 0,
'feedbacknotify' => GROUP_ROLES_ALL,
'hidemembers' => GROUP_HIDE_NONE,
'hidemembersfrommembers' => GROUP_HIDE_NONE,
);
}
......@@ -284,14 +284,17 @@ if ($cancreatecontrolled) {
'defaultvalue' => $group_data->hidden,
);
$elements['hidemembers'] = array(
'type' => 'switchbox',
'type' => 'select',
'options' => group_hide_members_options(),
'title' => get_string('hidemembers', 'group'),
'description' => get_string('hidemembersdescription', 'group'),
'defaultvalue' => $group_data->hidemembers || $group_data->hidemembersfrommembers,
'defaultvalue' => ($group_data->hidemembersfrommembers ? $group_data->hidemembersfrommembers : ($group_data->hidemembers ? $group_data->hidemembers : 0)),
'disabled' => $group_data->hidemembersfrommembers,
'help' => true,
);
$elements['hidemembersfrommembers'] = array(
'type' => 'switchbox',
'type' => 'select',
'options' => group_hide_members_options(),
'title' => get_string('hidemembersfrommembers', 'group'),
'description' => get_string('hidemembersfrommembersdescription1', 'group'),
'defaultvalue' => $group_data->hidemembersfrommembers,
......@@ -304,7 +307,7 @@ else {
);
$form['elements']['hidemembers'] = array(
'type' => 'hidden',
'value' => $group_data->hidemembers || $group_data->hidemembersfrommembers,
'value' => ($group_data->hidemembersfrommembers ? $group_data->hidemembersfrommembers : ($group_data->hidemembers ? $group_data->hidemembers : 0)),
);
$form['elements']['hidemembersfrommembers'] = array(
'type' => 'hidden',
......@@ -499,7 +502,7 @@ function editgroup_submit(Pieform $form, $values) {
'allowarchives' => intval(!empty($values['allowarchives']) ? $values['allowarchives'] : 0),
'editroles' => $values['editroles'],
'hidden' => intval($values['hidden']),
'hidemembers' => intval(!empty($values['hidemembersfrommembers']) || !empty($values['hidemembers'])),
'hidemembers' => (!empty($values['hidemembersfrommembers']) ? $values['hidemembersfrommembers'] : $values['hidemembers']),
'hidemembersfrommembers' => intval($values['hidemembersfrommembers']),
'groupparticipationreports' => intval($values['groupparticipationreports']),
'invitefriends' => intval($values['invitefriends']),
......@@ -599,13 +602,13 @@ jQuery(function($) {
$("#editgroup_invitefriends").removeAttr("checked");
}
});
$("#editgroup_hidemembersfrommembers").click(function() {
if (this.checked) {
$("#editgroup_hidemembers").attr("checked", true);
$("#editgroup_hidemembers").attr("disabled", true);
$("#editgroup_hidemembersfrommembers").change(function() {
if ($("#editgroup_hidemembersfrommembers option:selected").val() != "0") {
$("#editgroup_hidemembers").prop("selectedIndex", $("#editgroup_hidemembersfrommembers option:selected").val());
$("#editgroup_hidemembers").prop("disabled", "disabled");
}
else {
$("#editgroup_hidemembers").removeAttr("disabled");
$("#editgroup_hidemembers").prop("disabled", false);
}
});
$("#editgroup_submittableto").click(function() {
......
......@@ -31,10 +31,10 @@ define('TITLE', $group->name . ' - ' . get_string('Members', 'group'));
$role = group_user_access($group->id);
if (!$USER->get('admin') && !$USER->get('staff')) {
if (!$role && ($group->hidemembers || $group->hidemembersfrommembers)) {
if (!$role && ((int) $group->hidemembers === GROUP_HIDE_MEMBERS || (int) $group->hidemembersfrommembers === GROUP_HIDE_MEMBERS)) {
throw new AccessDeniedException();
}
if ($role != 'admin' && $group->hidemembersfrommembers) {
if ($role != 'admin' && (int) $group->hidemembersfrommembers === GROUP_HIDE_MEMBERS) {
throw new AccessDeniedException();
}
}
......@@ -80,7 +80,9 @@ if ($membershiptype == 'request') {
$sortoptionidx = param_alpha('sortoption', 'nameatoz');
}
$results = get_group_user_search_results($group->id, $query, $offset, $limit, $membershiptype, null, null, $sortoptionidx);
$hidetutors = ( (!$USER->get('admin') && !$USER->get('staff') && !$role && (int) $group->hidemembers === GROUP_HIDE_TUTORS) ||
(!$USER->get('admin') && !$USER->get('staff') && $role == 'member' && (int) $group->hidemembersfrommembers === GROUP_HIDE_TUTORS) ) ? true : false;
$results = get_group_user_search_results($group->id, $query, $offset, $limit, $membershiptype, null, null, $sortoptionidx, $hidetutors);
list($html, $pagination, $count, $offset, $membershiptype) = group_get_membersearch_data($results, $group->id, $query, $membershiptype, $setlimit, $sortoptionidx);
// Type-specific instructions
......
......@@ -32,10 +32,10 @@ if (!is_logged_in() && !$group->public) {
$role = group_user_access($group->id);
if (!$USER->get('admin') && !$USER->get('staff')) {
if (!$role && ($group->hidemembers || $group->hidemembersfrommembers)) {
if (!$role && ((int) $group->hidemembers === GROUP_HIDE_MEMBERS || (int) $group->hidemembersfrommembers === GROUP_HIDE_MEMBERS)) {
json_reply('local', get_string('accessdenied', 'error'));
}
if ($role != 'admin' && $group->hidemembersfrommembers) {
if ($role != 'admin' && (int) $group->hidemembersfrommembers === GROUP_HIDE_MEMBERS) {
json_reply('local', get_string('accessdenied', 'error'));
}
}
......@@ -55,7 +55,7 @@ if (!empty($membershiptype)) {
$results = get_group_user_search_results(
$group->id, $query, $offset, $limit, $membershiptype, null,
$friends ? $USER->get('id') : null,
$sortoptionidx
$sortoptionidx, (((int) $group->hidemembers === GROUP_HIDE_TUTORS || (int) $group->hidemembersfrommembers === GROUP_HIDE_TUTORS) ? true : false)
);
if (!param_integer('html', 1)) {
foreach ($results['data'] as &$result) {
......
......@@ -229,6 +229,8 @@ $string['notpublic'] = 'This group is not public.';
$string['moregroups'] = 'More groups';
$string['deletegroupnotificationsubject'] = 'The group "%s" was deleted';
$string['deletegroupnotificationmessage'] = 'You were a member of the group %s on %s. This group has now been deleted.';
$string['hidegroupmembers'] = 'Hide members';
$string['hideonlygrouptutors'] = 'Hide tutors';
// Bulk add, invite
$string['addmembers'] = 'Add members';
......
......@@ -16,6 +16,11 @@ define('GROUP_ROLES_ALL', 1);
define('GROUP_ROLES_NONMEMBER', 2);
define('GROUP_ROLES_ADMIN', 3);
// Constants for the different group roles
define('GROUP_HIDE_NONE', 0);
define('GROUP_HIDE_MEMBERS', 1);
define('GROUP_HIDE_TUTORS', 2);
// Role related functions
/**
......@@ -1834,9 +1839,25 @@ function group_get_editroles_options($intkeys = false) {
return $options;
}
/**
* Select dropdown options for showing/hiding group membership
*
* @return $options
*/
function group_hide_members_options() {
$options = array(
GROUP_HIDE_NONE => get_string('no', 'mahara'),
GROUP_HIDE_MEMBERS => get_string('hidegroupmembers', 'group'),
GROUP_HIDE_TUTORS => get_string('hideonlygrouptutors', 'group'),
);
return $options;
}
function group_can_list_members($group, $role) {
return !$group->hidemembersfrommembers && !$group->hidemembers
|| $role && !$group->hidemembersfrommembers
return (!$group->hidemembersfrommembers && !$group->hidemembers)
|| (!$role && ($group->hidemembers == GROUP_HIDE_TUTORS || $group->hidemembersfrommembers == GROUP_HIDE_TUTORS))
|| ($role == 'member' && (int) $group->hidemembersfrommembers !== GROUP_HIDE_MEMBERS)
|| ($role == 'tutor' && (int) $group->hidemembersfrommembers === GROUP_HIDE_TUTORS)
|| $role == 'admin';
}
......
......@@ -880,7 +880,7 @@ function get_export_contentdata($item) {
* @param int $friendof Only return friends of this user
*
*/
function get_group_user_search_results($group, $query, $offset, $limit, $membershiptype, $order=null, $friendof=null, $sortoptionidx=null) {
function get_group_user_search_results($group, $query, $offset, $limit, $membershiptype, $order=null, $friendof=null, $sortoptionidx=null, $nontutor=false) {
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
$searchclass = generate_class_name('search', $plugin);
......@@ -925,7 +925,7 @@ function get_group_user_search_results($group, $query, $offset, $limit, $members
$results = call_static_method(
$searchclass,
'group_search_user',
$group, $queries, $constraints, $offset, $limit, $membershiptype, $order, $friendof, $sortoptionidx
$group, $queries, $constraints, $offset, $limit, $membershiptype, $order, $friendof, $sortoptionidx, $nontutor
);
if ($results['count']) {
......
......@@ -560,7 +560,7 @@ class PluginSearchInternal extends PluginSearch {
}
public static function group_search_user($group, $query_string, $constraints, $offset, $limit, $membershiptype, $order, $friendof, $orderbyoptionidx=null) {
public static function group_search_user($group, $query_string, $constraints, $offset, $limit, $membershiptype, $order, $friendof, $orderbyoptionidx=null, $nontutor=false) {
list($searchsql, $values) = self::name_search_sql($query_string);
......@@ -638,9 +638,10 @@ class PluginSearchInternal extends PluginSearch {
$select = '
u.id, u.firstname, u.lastname, u.username, u.preferredname, u.email, u.profileicon,
u.staff, u.urlid, u.preferredname, ' . db_format_tsfield('gm.ctime', 'jointime') . ', gm.role';
$restrict = ($nontutor) ? " AND gm.role != 'tutor'" : "";
$from = '
FROM {usr} u
INNER JOIN {group_member} gm ON (gm.member = u.id)
INNER JOIN {group_member} gm ON (gm.member = u.id' . $restrict . ')
LEFT OUTER JOIN {usr_account_preference} h ON (u.id = h.usr AND h.field = \'hiderealname\')
WHERE u.id > 0 AND u.deleted = 0 ' . $searchsql . '
AND gm.group = ?';
......
@javascript @core @core_group
Feature: Hiding group members options
In order to hide group members from either general public or other members
As an admin
I adjust the 'Hide members' and 'Hide members from members' group config options
Background:
Given the following "users" exist:
| username | password | email | firstname | lastname | institution | authname | role |
| groupmember | randomuser | randomuser@random.com | Group | Member | mahara | internal | member |
| groupadmin | randomteacher | randomteacher@random.com | Super | Teacher | mahara | internal | admin |
| grouptutor | randomtutor | randomtutor@random.com | Diligent | Tutor | mahara | internal | member |
| randomuser | randomuser2 | randomuser2@random.com | Random | Person | mahara | internal | member |
Given the following "groups" exist:
| name | owner | description | grouptype | open | invitefriends | editroles | submittableto | allowarchives | members | staff |
| Test group | groupadmin | My test group | course | ON | ON | all | ON | ON | groupmember | grouptutor |
Scenario: Check if we can hide members of a group based on the 'Hide members' setting
Given I log in as "groupadmin" with password "randomteacher"
And I choose "My groups" in "Groups"
And I follow "Edit \"Test group\" Settings"
And I select "Hide tutors" from "editgroup_hidemembers"
And I press "Save group"
Then I should see "Group saved successfully"
And I log out
When I log in as "randomuser" with password "randomuser2"
And I choose "Find groups" in "Groups"
And I follow "Test group"
Then I should not see "Diligent Tutor"
And I should see "Group Member"
And I log out
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