Commit 024403f5 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow institutional admins access to suspended users page

parent ed2f5455
......@@ -25,7 +25,7 @@
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('INSTITUTIONALADMIN', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
......@@ -35,24 +35,54 @@ json_headers();
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
// Filter for institutional admins:
$instsql = $USER->get('admin') ? '' : '
AND ui.institution IN (' . join(',', array_map('db_quote', array_keys($USER->get('institutions')))) . ')';
// NOTE: the check is not done on the 'active' column here, since suspended
// users are by definition not active. However deleted users are filtered out.
$count = get_field_sql('SELECT COUNT(*) FROM {usr} WHERE suspendedcusr IS NOT NULL AND deleted = 0');
$data = get_records_sql_array('SELECT DISTINCT ON (u.suspendedctime, u.id) u.id, u.firstname, u.lastname, u.studentid, u.suspendedreason AS reason,
i.displayname AS institution, ua.firstname AS cusrfirstname, ua.lastname AS cusrlastname
$count = get_field_sql('
SELECT COUNT(*)
FROM (
SELECT u.id
FROM {usr} u
LEFT OUTER JOIN {usr_institution} ui ON (ui.usr = u.id)
WHERE suspendedcusr IS NOT NULL
AND deleted = 0 ' . $instsql . '
GROUP BY u.id
) AS a');
$data = get_records_sql_assoc('
SELECT
u.id, u.firstname, u.lastname, u.studentid, u.suspendedctime, u.suspendedreason AS reason,
ua.firstname AS cusrfirstname, ua.lastname AS cusrlastname
FROM {usr} u
LEFT OUTER JOIN {usr_institution} ui ON (ui.usr = u.id)
LEFT OUTER JOIN {institution} i ON (ui.institution = i.name)
LEFT JOIN {usr} ua on (ua.id = u.suspendedcusr)
LEFT OUTER JOIN {usr_institution} ui ON (ui.usr = u.id)
WHERE u.suspendedcusr IS NOT NULL
AND u.deleted = 0
AND u.deleted = 0 ' . $instsql . '
GROUP BY
u.id, u.firstname, u.lastname, u.studentid, u.suspendedctime, u.suspendedreason,
ua.firstname, ua.lastname
ORDER BY u.suspendedctime, u.id
LIMIT ?
OFFSET ?', array($limit, $offset));
if (!$data) {
$data = array();
}
else {
$institutions = get_records_sql_array('
SELECT ui.usr, ui.studentid, i.displayname
FROM {usr_institution} ui INNER JOIN {institution} i ON ui.institution = i.name
WHERE ui.usr IN (' . join(',', array_keys($data)) . ')', null);
if ($institutions) {
foreach ($institutions as &$i) {
$data[$i->usr]->institutions[] = $i->displayname;
$data[$i->usr]->institutionids[] = $i->studentid;
}
}
$data = array_values($data);
foreach ($data as &$record) {
$record->name = full_name($record);
$record->firstname = $record->cusrfirstname;
......
......@@ -25,7 +25,7 @@
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('INSTITUTIONALADMIN', 1);
define('MENUITEM', 'configusers/suspendedusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('suspendedusers', 'admin'));
......@@ -42,8 +42,12 @@ var suspendedlist = new TableRenderer(
'suspended.json.php',
[
'name',
'studentid',
'institution',
function (r) {
return TD(null, r.institutions ? map(partial(DIV, null), r.institutions) : null);
},
function (r) {
return TD(null, r.institutions ? map(partial(DIV, null), r.institutionids) : r.studentid);
},
'cusrname',
'reason',
function (rowdata) { return TD(null, INPUT({'type': 'checkbox', 'name': 'usr_' + rowdata.id})); }
......
......@@ -1317,41 +1317,47 @@ function admin_nav() {
'title' => get_string('usersearch', 'admin'),
'weight' => 10,
),
array(
'path' => 'configusers/suspendedusers',
'url' => 'admin/users/suspended.php',
'title' => get_string('suspendedusers', 'admin'),
'weight' => 20,
),
array(
'path' => 'configusers/institutionusers',
'url' => 'admin/users/institutionusers.php',
'title' => get_string('institutionmembers', 'admin'),
'weight' => 20,
'weight' => 30,
),
array(
'path' => 'configusers/institutionstaff',
'url' => 'admin/users/institutionstaff.php',
'title' => get_string('staffusers', 'admin'),
'weight' => 30,
'weight' => 40,
),
array(
'path' => 'configusers/institutionadmins',
'url' => 'admin/users/institutionadmins.php',
'title' => get_string('adminusers', 'admin'),
'weight' => 40,
'weight' => 50,
),
array(
'path' => 'configusers/institutions',
'url' => 'admin/users/institutions.php',
'title' => get_string('institutionsettings', 'admin'),
'weight' => 50,
'weight' => 60,
),
array(
'path' => 'configusers/adminnotifications',
'url' => 'admin/users/notifications.php',
'title' => get_string('adminnotifications', 'admin'),
'weight' => 60,
'weight' => 70,
),
array(
'path' => 'configusers/uploadcsv',
'url' => 'admin/users/uploadcsv.php',
'title' => get_string('uploadcsv', 'admin'),
'weight' => 70,
'weight' => 80,
),
);
}
......
......@@ -9,8 +9,8 @@
<thead>
<tr>
<th>{str tag=fullname}</th>
<th>{str tag=studentid}</th>
<th>{str tag=institution}</th>
<th>{str tag=studentid}</th>
<th>{str tag=suspendingadmin section=admin}</th>
<th>{str tag=suspensionreason section=admin}</th>
<th>{str tag=select}</th>
......
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