MDL-80693 core_user: search() fails if no standard identify fields
This commit is contained in:
+19
-16
@@ -266,29 +266,32 @@ class core_user {
|
||||
$index++;
|
||||
}
|
||||
|
||||
$identitysystem = has_capability('moodle/site:viewuseridentity', $systemcontext);
|
||||
$usingshowidentity = false;
|
||||
if ($identitysystem) {
|
||||
// They have permission everywhere so just add the extra query to the normal query.
|
||||
$where .= ' OR ' . $extrasql;
|
||||
$whereparams = array_merge($whereparams, $extraparams);
|
||||
} else {
|
||||
// Get all courses where user can view full user identity.
|
||||
list($sql, $params) = self::get_enrolled_sql_on_courses_with_capability(
|
||||
// Only do this code if there actually are some identity fields being searched.
|
||||
if ($extrasql) {
|
||||
$identitysystem = has_capability('moodle/site:viewuseridentity', $systemcontext);
|
||||
if ($identitysystem) {
|
||||
// They have permission everywhere so just add the extra query to the normal query.
|
||||
$where .= ' OR ' . $extrasql;
|
||||
$whereparams = array_merge($whereparams, $extraparams);
|
||||
} else {
|
||||
// Get all courses where user can view full user identity.
|
||||
list($sql, $params) = self::get_enrolled_sql_on_courses_with_capability(
|
||||
'moodle/site:viewuseridentity');
|
||||
if ($sql) {
|
||||
// Join that with the user query to get an extra field indicating if we can.
|
||||
$userquery = "
|
||||
if ($sql) {
|
||||
// Join that with the user query to get an extra field indicating if we can.
|
||||
$userquery = "
|
||||
SELECT innerusers.id, COUNT(identityusers.id) AS showidentity
|
||||
FROM ($userquery) innerusers
|
||||
LEFT JOIN ($sql) identityusers ON identityusers.id = innerusers.id
|
||||
GROUP BY innerusers.id";
|
||||
$userparams = array_merge($userparams, $params);
|
||||
$usingshowidentity = true;
|
||||
$userparams = array_merge($userparams, $params);
|
||||
$usingshowidentity = true;
|
||||
|
||||
// Query on the extra fields only in those places.
|
||||
$where .= ' OR (users.showidentity > 0 AND (' . $extrasql . '))';
|
||||
$whereparams = array_merge($whereparams, $extraparams);
|
||||
// Query on the extra fields only in those places.
|
||||
$where .= ' OR (users.showidentity > 0 AND (' . $extrasql . '))';
|
||||
$whereparams = array_merge($whereparams, $extraparams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user