Commit 6ba72658 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Remove requested/invited users from the admin search



See bug #799617

This change fixes the pagination on the admin user search page for
institutional admins with more than one institution when users can
belong to multiple institutions.

As part of the fix, the behaviour of the page has been changed so
that requested and invited users are no longer displayed.

Institutional admins are already able to find users with open requests
on the institution members page, and will soon be able to find invited
users on that page too.

Change-Id: I2460bcf54e0e0ca96a51dd592c04aa0a2229cc7d
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent c864af5a
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('INSTITUTIONALADMIN', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('institution.php');
$id = param_integer('id');
$institution = new Institution(param_alpha('institution'));
if (!$USER->get('admin')) {
if (!$USER->is_institutional_admin($institution->name)) {
$SESSION->add_error_msg(get_string('notadminforinstitution', 'admin'));
redirect(get_config('wwwroot').'admin/users/search.php');
}
else if (!get_field('usr_institution_request', 'confirmedusr', 'usr', $id, 'institution', $institution->name)) {
$institution->inviteUser($id);
$SESSION->add_ok_msg(get_string('invitationsent', 'admin'));
redirect(get_config('wwwroot').'admin/users/search.php');
}
}
$institution->addUserAsMember($id);
$SESSION->add_ok_msg(get_string('useradded', 'admin'));
redirect(get_config('wwwroot').'admin/users/edit.php?id='.$id);
......@@ -41,21 +41,15 @@ if ($action == 'search') {
$params->institution = param_alphanum('institution', null);
$params->f = param_alpha('f', null);
$params->l = param_alpha('l', null);
$params->institution_requested = param_alphanum('institution_requested', null);
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
$sortby = param_alpha('sortby', 'firstname');
$sortdir = param_alpha('sortdir', 'asc');
json_headers();
if (param_boolean('raw', false)) {
$data = get_admin_user_search_results($params, $offset, $limit, $sortby, $sortdir);
} else {
$data['data'] = build_admin_user_search_results($params, $offset, $limit, $sortby, $sortdir);
}
$data = array();
$data['data'] = build_admin_user_search_results($params, $offset, $limit, $sortby, $sortdir);
$data['error'] = false;
$data['message'] = null;
echo json_encode($data);
exit;
json_reply(false, $data);
}
......@@ -51,7 +51,6 @@ if ($USER->get('admin')) {
$search->institution = param_alphanum('institution', 'all');
} else {
$institutions = get_records_select_array('institution', "name IN ('" . join("','", array_keys($USER->get('admininstitutions'))) . "')", null, 'displayname');
$search->institution_requested = param_alphanum('institution_requested', 'all');
}
$smarty = smarty(array('adminusersearch'));
......
......@@ -221,22 +221,23 @@ function get_admin_user_search_results($search, $offset, $limit, $sortby, $sortd
// Filter by viewable institutions:
global $USER;
if (!$USER->get('admin')) {
if (empty($search->institution) && empty($search->institution_requested)) {
$search->institution_requested = 'all';
}
$allowed = $USER->get('admininstitutions');
foreach (array('institution', 'institution_requested') as $p) {
if (!empty($search->{$p})) {
if ($search->{$p} == 'all' || !isset($allowed[$search->{$p}])) {
$constraints[] = array('field' => $p,
'type' => 'in',
'string' => $allowed);
} else {
$constraints[] = array('field' => $p,
'type' => 'equals',
'string' => $search->{$p});
}
}
if (empty($search->institution)) {
$search->institution = 'all';
}
if ($search->institution == 'all' || !isset($allowed[$search->institution])) {
$constraints[] = array(
'field' => 'institution',
'type' => 'in',
'string' => $allowed,
);
}
else {
$constraints[] = array(
'field' => 'institution',
'type' => 'equals',
'string' => $search->institution,
);
}
} else if (!empty($search->institution) && $search->institution != 'all') {
$constraints[] = array('field' => 'institution',
......@@ -303,7 +304,7 @@ function build_admin_user_search_results($search, $offset, $limit, $sortby, $sor
if (count($institutions) > 1) {
$cols['institution'] = array(
'name' => get_string('institution'),
'sort' => !get_config('usersallowedmultipleinstitutions'),
'sort' => false,
'template' => 'admin/users/searchinstitutioncolumn.tpl',
);
}
......
......@@ -368,33 +368,18 @@ class PluginSearchInternal extends PluginSearch {
$values = array_pad($values, count($values) + 4, $term);
}
// @todo: Institution stuff is messy and will probably need to
// be rewritten when we get multiple institutions per user
$requested = false;
$institutionsearch = '';
if (!empty($constraints)) {
foreach ($constraints as $f) {
if (strpos($f['field'], 'institution') === 0) {
$institutionsearch .= '
LEFT OUTER JOIN {usr_institution} i ON i.usr = u.id ';
if (strpos($f['field'], 'requested') > 0) {
$institutionsearch .= '
LEFT OUTER JOIN {usr_institution_request} ir ON ir.usr = u.id ';
if ($f['field'] == 'institution') {
if ($f['string'] == 'mahara') {
$where .= ' AND u.id NOT IN (SELECT usr FROM {usr_institution})';
}
if ($f['field'] == 'institution_requested') {
$where .= ' AND ( i.institution ' .
PluginSearchInternal::match_expression($f['type'], $f['string'], $values, $ilike) .
' OR ir.institution ' .
PluginSearchInternal::match_expression($f['type'], $f['string'], $values, $ilike) . ')';
$requested = true;
} else {
if ($f['string'] == 'mahara') {
$where .= ' AND i.institution IS NULL';
} else {
$where .= ' AND i.institution'
. PluginSearchInternal::match_expression($f['type'], $f['string'], $values, $ilike);
}
else {
$where .= '
AND u.id IN (
SELECT usr FROM {usr_institution} WHERE institution '
. PluginSearchInternal::match_expression($f['type'], $f['string'], $values, $ilike) . '
)';
}
} else {
$where .= ' AND u.' . $f['field']
......@@ -402,22 +387,15 @@ class PluginSearchInternal extends PluginSearch {
}
}
}
if (strpos($sort, 'institution') === 0) {
$sort = 'i.' . $sort;
if ($institutionsearch == '') {
$institutionsearch = ' LEFT OUTER JOIN {usr_institution} i ON i.usr = u.id ';
}
}
$count = get_field_sql('SELECT COUNT(*) FROM {usr} u ' . $institutionsearch . $where, $values);
$count = get_field_sql('SELECT COUNT(*) FROM {usr} u ' . $where, $values);
if ($count > 0) {
$data = get_records_sql_assoc('
SELECT
u.id, u.firstname, u.lastname, u.username, u.email, u.staff, u.profileicon,
u.active, NOT u.suspendedcusr IS NULL as suspended
FROM
{usr} u ' . $institutionsearch . $where . '
FROM {usr} u ' . $where . '
ORDER BY ' . $sort . ', u.id',
$values,
$offset,
......@@ -432,21 +410,6 @@ class PluginSearchInternal extends PluginSearch {
$data[$i->usr]->institutions[] = $i->institution;
}
}
if ($requested) {
$inst = get_records_select_array('usr_institution_request',
'usr IN (' . join(',', array_keys($data)) . ')',
null, '', 'usr,institution,confirmedusr,confirmedinstitution');
if ($inst) {
foreach ($inst as $i) {
if ($i->confirmedusr) {
$data[$i->usr]->requested[] = $i->institution;
}
if ($i->confirmedinstitution) {
$data[$i->usr]->invitedby[] = $i->institution;
}
}
}
}
foreach ($data as &$item) {
$item->username = display_username($item);
$item = (array)$item;
......
......@@ -35,11 +35,7 @@
{if count($institutions) > 1}
<span class="institutions">
<label>{str tag='Institution' section='admin'}:</label>
{if $USER->get('admin')}
<select name="institution" id="institution">
{else}
<select name="institution_requested" id="institution_requested">
{/if}
<option value="all"{if !$.request.institution} selected="selected"{/if}>{str tag=All}</option>
{foreach from=$institutions item=i}
<option value="{$i->name}"{if $i->name == $.request.institution}" selected="selected"{/if}>{$i->displayname}</option>
......
......@@ -5,19 +5,3 @@
<div>{$institutions[$i]->displayname}</div>
{/foreach}
{/if}
{if $r.requested}
{foreach from=$r.requested item=i}
<div class="pending">{str tag=requestto section=admin} {$institutions[$i]->displayname}
{if $USER->is_institutional_admin("$i")}
(<a href="{$WWWROOT}admin/users/addtoinstitution.php?id={$r.id}&institution={$i}">{str tag=confirm section=admin}</a>)
{/if}
</div>
{/foreach}
{/if}
{if $r.invitedby}
{foreach from=$r.invitedby item=i}
<div class="pending">{str tag=invitedby section=admin} {$institutions[$i]->displayname}</div>
{/foreach}
{/if}
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