Commit 9f8cf990 authored by Richard Mansfield's avatar Richard Mansfield

Hide member counts when user can't list members

When the logged-in user can't get to the member listing for a group
(bug #845287, bug #504830), it seems like a good idea to also hide
the number of members.

Member counts are hidden in the group info block and copy a view page
by moving member & view counting into the group_get_groupinfo_data
function, and performing the permission check in one place for both
pages.

Member counts are hidden on My Groups and Find Groups inside the
group_prepare_usergroups_for_display function.

Change-Id: Ibe5675861040cedf67c2ddff7647117cd155722a
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent a015acde
......@@ -63,13 +63,7 @@ class PluginBlocktypeGroupInfo extends SystemBlocktype {
$data = self::get_data($groupid);
$dwoo = smarty_core();
$dwoo->assign('group', $data['group']);
$dwoo->assign('groupid', $data['group']->id);
$dwoo->assign('membercount', count_records('group_member', 'group', $data['group']->id));
$dwoo->assign('viewcount', count_records('view', 'group', $data['group']->id));
$dwoo->assign('filecount', $data['filecounts']->files);
$dwoo->assign('foldercount', $data['filecounts']->folders);
$dwoo->assign('group', $data);
return $dwoo->fetch('blocktype:groupinfo:groupinfo.tpl');
}
......@@ -96,8 +90,6 @@ class PluginBlocktypeGroupInfo extends SystemBlocktype {
throw new AccessDeniedException();
}
list($group, $filecounts) = group_get_groupinfo_data($group);
return array('group'=>$group, 'filecounts'=>$filecounts);
return group_get_groupinfo_data($group);
}
}
......@@ -92,12 +92,12 @@ if ($groups['data']) {
foreach ($groups['data'] as $group) {
$groupids[] = $group->id;
}
$groups['data'] = get_records_sql_array(
"SELECT g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.role, g1.membershiptype,
g1.submittableto, g1.membercount, COUNT(gmr.member) AS requests
$groups['data'] = get_records_sql_array("
SELECT g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.hidemembers, g1.hidemembersfrommembers, g1.role, g1.membershiptype, g1.membercount, COUNT(gmr.member) AS requests
FROM (
SELECT g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto, t.role,
t.membershiptype, COUNT(gm.member) AS membercount
SELECT g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, t.role, t.membershiptype, COUNT(gm.member) AS membercount
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)
LEFT JOIN (
......@@ -118,12 +118,12 @@ if ($groups['data']) {
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id
WHERE g.id IN (" . implode($groupids, ',') . ')
GROUP BY g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto, t.role,
t.membershiptype
GROUP BY g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, t.role, t.membershiptype
) g1
LEFT JOIN {group_member_request} gmr ON (gmr.group = g1.id)
GROUP BY g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.role, g1.membershiptype,
g1.submittableto, g1.membercount
GROUP BY g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.hidemembers, g1.hidemembersfrommembers, g1.role, g1.membershiptype, g1.membercount
ORDER BY g1.name',
array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'))
);
......
......@@ -33,14 +33,10 @@ require_once(get_config('libroot') . 'group.php');
$id = param_integer('id');
$group = get_record('group', 'id', $id);
list($group, $filecounts) = group_get_groupinfo_data($group);
$group = group_get_groupinfo_data($group);
$smarty = smarty_core();
$smarty->assign('group', $group);
$smarty->assign('membercount', count_records('group_member', 'group', $group->id));
$smarty->assign('viewcount', count_records('view', 'group', $group->id));
$smarty->assign('filecount', $filecounts->files);
$smarty->assign('foldercount', $filecounts->folders);
ob_start();
$smarty->display('group/groupdata.tpl');
$html = ob_get_contents();
......
......@@ -1297,6 +1297,15 @@ function group_prepare_usergroups_for_display($groups, $returnto='mygroups') {
else if ($group->jointype == 'open') {
$group->groupjoin = group_get_join_form('joingroup' . $i++, $group->id);
}
$showmembercount = !$group->hidemembersfrommembers && !$group->hidemembers
|| $group->membershiptype == 'member' && !$group->hidemembersfrommembers
|| $group->membershiptype == 'admin';
if (!$showmembercount) {
unset($group->membercount);
}
$group->settingsdescription = group_display_settings($group);
}
}
......@@ -1485,6 +1494,12 @@ function group_get_editroles_options() {
);
}
function group_can_list_members($group, $role) {
return !$group->hidemembersfrommembers && !$group->hidemembers
|| $role && !$group->hidemembersfrommembers
|| $role == 'admin';
}
/**
* Returns a datastructure describing the tabs that appear on a group page
*
......@@ -1510,11 +1525,7 @@ function group_get_menu_tabs() {
),
);
$memberstab = !$group->hidemembersfrommembers && !$group->hidemembers
|| $role && !$group->hidemembersfrommembers
|| $role == 'admin';
if ($memberstab) {
if (group_can_list_members($group, $role)) {
$menu['members'] = array(
'path' => 'groups/members',
'url' => 'group/members.php?id='.$group->id,
......@@ -1769,21 +1780,23 @@ function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=
$sql = '
SELECT g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.membershiptype, g1.reason, g1.role, g1.membercount, COUNT(gmr.member) AS requests
g1.hidemembers, g1.hidemembersfrommembers, g1.membershiptype, g1.reason, g1.role, g1.membercount,
COUNT(gmr.member) AS requests
FROM (
SELECT g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
t.membershiptype, t.reason, t.role, COUNT(gm.member) AS membercount
g.hidemembers, g.hidemembersfrommembers, t.membershiptype, t.reason, t.role,
COUNT(gm.member) AS membercount
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)' .
$sql . '
WHERE g.deleted = ?' .
$catsql . '
GROUP BY g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
t.membershiptype, t.reason, t.role
g.hidemembers, g.hidemembersfrommembers, t.membershiptype, t.reason, t.role
) g1
LEFT JOIN {group_member_request} gmr ON (gmr.group = g1.id)
GROUP BY g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.membershiptype, g1.reason, g1.role, g1.membercount
g1.hidemembers, g1.hidemembersfrommembers, g1.membershiptype, g1.reason, g1.role, g1.membercount
ORDER BY g1.name';
$groups = get_records_sql_array($sql, $values, $offset, $limit);
......@@ -1913,9 +1926,15 @@ function group_get_groupinfo_data($group) {
$group->categorytitle = ($group->category) ? get_field('group_category', 'title', 'id', $group->category) : '';
}
$filecounts = ArtefactTypeFileBase::count_user_files(null, $group->id, null);
if (group_can_list_members($group, group_user_access($group->id))) {
$group->membercount = count_records('group_member', 'group', $group->id);
}
return array($group, $filecounts);
$group->viewcount = count_records('view', 'group', $group->id);
$group->filecounts = ArtefactTypeFileBase::count_user_files(null, $group->id, null);
return $group;
}
/**
......
......@@ -6,8 +6,10 @@
<li><label class="groupinfolabel">{str tag=grouptype section=group}:</label> {$group->settingsdescription}</li>
{if $group->categorytitle}<li><label>{str tag=groupcategory section=group}:</label> {$group->categorytitle}</li>{/if}
<li><label class="groupinfolabel">{str tag=Created section=group}:</label> {$group->ctime}</li>
<li class="last"><span><label>{str tag=Members section=group}:</label> {$membercount}&nbsp;</span>
<span><label>{str tag=Views section=view}:</label> {$viewcount}&nbsp;</span>
<span><label>{str tag=Files section=artefact.file}:</label> {$filecount}&nbsp;</span>
<span><label>{str tag=Folders section=artefact.file}:</label> {$foldercount}</span></li>
<li class="last">
{if $group->membercount}<span><label>{str tag=Members section=group}:</label> {$group->membercount}&nbsp;</span>{/if}
<span><label>{str tag=Views section=view}:</label> {$group->viewcount}&nbsp;</span>
<span><label>{str tag=Files section=artefact.file}:</label> {$group->filecounts->files}&nbsp;</span>
<span><label>{str tag=Folders section=artefact.file}:</label> {$group->filecounts->folders}</span>
</li>
</ul>
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