mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-71836 core_enrol: Cannot search for users by username
This commit is contained in:
parent
30b8ad51f4
commit
171313781d
@ -392,9 +392,13 @@ class course_enrolment_manager {
|
||||
['selects' => $fieldselects, 'joins' => $fieldjoins, 'params' => $params, 'mappings' => $mappings] =
|
||||
(array)$userfields->get_sql('u', true, '', '', false);
|
||||
|
||||
// Searchable fields are only the identity and name ones (not userpic).
|
||||
$searchable = array_fill_keys($userfields->get_required_fields(
|
||||
[fields::PURPOSE_IDENTITY, fields::PURPOSE_NAME]), true);
|
||||
// Searchable fields are only the identity and name ones (not userpic, and without exclusions).
|
||||
$searchablefields = fields::for_identity($this->context)->with_name();
|
||||
$searchable = array_fill_keys($searchablefields->get_required_fields(), true);
|
||||
if (array_key_exists('username', $searchable)) {
|
||||
// Add the username into the mappings list from the other query, because it was excluded.
|
||||
$mappings['username'] = 'u.username';
|
||||
}
|
||||
|
||||
// Add some additional sensible conditions
|
||||
$tests = array("u.id <> :guestid", 'u.deleted = 0', 'u.confirmed = 1');
|
||||
|
@ -461,6 +461,12 @@ class core_course_enrolment_manager_testcase extends advanced_testcase {
|
||||
$this->assertEquals([], array_keys($users[0]));
|
||||
$users = array_values($manager->get_potential_users($enrolid, 'Frogs'));
|
||||
$this->assertEquals([], array_keys($users[0]));
|
||||
|
||||
// Search for username field (there is special handling for this one field).
|
||||
set_config('showuseridentity', 'username');
|
||||
$this->setAdminUser();
|
||||
$users = array_values($manager->get_potential_users($enrolid, 'newuse'));
|
||||
$this->assertEquals([$newuser->id], array_keys($users[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user