Commit 50db739e authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Fix list of invited & requested groups on user profile



The group jointype changes from bug #610690 (which allow invitations
to any group) resulted in incorrect lists of invited/requested groups
on the user profile.  Groups the user is already a member of are
listed under 'invited to join', and controlled groups are listed under
'requested membership of'.  This change fixes these lists, and merges
the two queries that find the groups for which the logged-in user is an
admin.

Change-Id: Iff675790391ef1ada22b6e9bb5930772fd2c3bf3
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 77c45fa7
......@@ -117,20 +117,40 @@ if (!empty($loggedinid) && $loggedinid != $userid) {
$invitedlist = array(); // Groups admin'ed by the logged in user that the displayed user has been invited to
$requestedlist = array(); // Groups admin'ed by the logged in user that the displayed user has requested membership of
// Get the logged in user's "invite only" groups
// Get all groups that the logged in user is an admin of, or where the logged in user
// has a role in the list of roles who are allowed to assess submitted views for the
// group's grouptype
if ($groups = get_records_sql_array("SELECT g.*
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
JOIN {grouptype_roles} gtr ON gtr.grouptype = g.grouptype AND gtr.role = gm.role
WHERE gm.member = ?
AND gm.role = 'admin'
AND (gm.role = 'admin' OR gtr.see_submitted_views = 1)
AND g.deleted = 0", array($loggedinid))) {
$invitelist = array();
$invitelist = array(); // List of groups the displayed user can be invited to join
$controlledlist = array(); // List of groups the displayed user can be directly added to
foreach ($groups as $group) {
if (array_key_exists($group->id, $allusergroups)) {
$invitedlist[$group->id] = $group->name;
continue;
if ($allusergroups[$group->id]->type == 'invite') {
$invitedlist[$group->id] = $group->name;
}
else if ($allusergroups[$group->id]->type == 'request') {
$requestedlist[$group->id] = $group->name;
$controlledlist[$group->id] = $group->name;
continue;
}
else {
continue; // Already a member
}
}
if ($group->jointype == 'controlled') {
$controlledlist[$group->id] = $group->name;
}
if (!isset($invitedlist[$group->id])) {
$invitelist[$group->id] = $group->name;
}
$invitelist[$group->id] = $group->name;
}
$smarty->assign('invitedlist', join(', ', $invitedlist));
if (count($invitelist) > 0) {
......@@ -160,34 +180,7 @@ if (!empty($loggedinid) && $loggedinid != $userid) {
));
$smarty->assign('inviteform',$inviteform);
}
}
// Get (a) controlled membership groups,
// (b) request membership groups where the displayed user has requested membership,
// where the logged in user either:
// 1. is a group admin, or;
// 2. has a role in the list of roles who are allowed to assess submitted views for the given grouptype
if ($groups = get_records_sql_array("SELECT g.*, gm.ctime
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
JOIN {grouptype_roles} gtr ON (gtr.grouptype = g.grouptype AND gtr.role = gm.role)
LEFT JOIN {group_member_request} gmr ON (gmr.member = ? AND gmr.group = g.id)
WHERE gm.member = ?
AND (g.jointype = 'controlled' OR (g.request = 1 AND gmr.member = ?))
AND (gm.role = 'admin' OR gtr.see_submitted_views = 1)
AND g.deleted = 0", array($userid,$loggedinid,$userid))) {
$controlledlist = array();
foreach ($groups as $group) {
if (array_key_exists($group->id, $allusergroups)) {
continue;
}
if ($group->request) {
$requestedlist[$group->id] = $group->name;
}
if ($group->jointype == 'controlled') {
$controlledlist[$group->id] = $group->name;
}
}
$smarty->assign('requestedlist', join(', ', $requestedlist));
if (count($controlledlist) > 0) {
$default = array_keys($controlledlist);
......
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