Commit 27df8377 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Filter admin user search by institution for institutional admins

parent b1ab504a
......@@ -368,7 +368,7 @@ class User {
}
public function set_admin_institutions($institutions) {
$this->set('admininstitutions', array_fill_keys($institutions, true));
$this->set('admininstitutions', array_combine($institutions, $institutions));
}
}
......@@ -470,7 +470,7 @@ class LiveUser extends User {
$admininstitutions = array();
foreach ($institutions as $i) {
if ($i->admin) {
$admininstitutions[$i->institution] = true;
$admininstitutions[$i->institution] = $i->institution;
}
}
$this->institutions = $institutions;
......
......@@ -146,7 +146,23 @@ function build_admin_user_search_results($search, $offset, $limit, $sortby, $sor
'type' => 'starts',
'string' => $search->l);
}
if (!empty($search->institution) && $search->institution != 'all') {
// Filter by viewable institutions:
if (empty($search->institution)) {
$search->institution = 'all';
}
global $USER;
if (!$USER->get('admin')) {
$allowed = $USER->get('admininstitutions');
if ($search->institution == 'all' || !isset($allowed[$search->institution])) {
$constraints[] = array('field' => 'institution',
'type' => 'in',
'list' => $allowed);
} else {
$constraints[] = array('field' => 'institution',
'type' => 'equals',
'string' => $search->institution);
}
} else if ($search->institution != 'all') {
$constraints[] = array('field' => 'institution',
'type' => 'equals',
'string' => $search->institution);
......
......@@ -277,7 +277,9 @@ class PluginSearchInternal extends PluginSearch {
foreach ($constraints as $f) {
if ($f['field'] == 'institution') {
$institutionsearch .= ' LEFT OUTER JOIN {usr_institution} i ON i.usr = u.id ';
if ($f['string'] == 'mahara') {
if ($f['type'] == 'in') {
$where .= " AND i.institution IN ('" . join("','", $f['list']) . "')";
} else if ($f['string'] == 'mahara') {
$where .= ' AND i.institution IS NULL';
} else {
$where .= ' AND i.institution' . $matchtypes[$f['type']];
......
......@@ -228,8 +228,15 @@ END;
}
$terms = array();
foreach ($constraints as $f) {
$terms[] = $solrfields[$f['field']] . ':' . strtolower($f['string'])
. ($f['type'] != 'equals' ? '*' : '');
if ($f['type'] == 'in' && !empty($f['list'])) {
foreach ($f['list'] as &$string) {
$string = $solrfields[$f['field']] . ':' . strtolower($string);
}
$terms[] = '(' . join(' OR ', $f['list']) . ')';
} else {
$terms[] = $solrfields[$f['field']] . ':' . strtolower($f['string'])
. ($f['type'] != 'equals' ? '*' : '');
}
}
$q .= join(' AND ', $terms);
}
......
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