Skip to content

Commit

Permalink
Merge branch 'WP-2770' into 'master'
Browse files Browse the repository at this point in the history
WP-2770 exclude profile fields from user search

See merge request workplace/moodle-tool_certificate!15
  • Loading branch information
paulholden committed Jul 20, 2021
2 parents 4615573 + 52ccb49 commit 5e12c05
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions classes/external/issues.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static function potential_users_selector(string $search, int $itemid): ar
$where = \tool_certificate\certificate::get_users_subquery();
$where .= ' AND (ci.id IS NULL OR (ci.expires > 0 AND ci.expires < :now))';
} else {
throw new required_capability_exception(context_system::instance(), 'tool/certificate:issue', 'nopermissions', 'error');
throw new \required_capability_exception($context, 'tool/certificate:issue', 'nopermissions', 'error');
}

$join = ' LEFT JOIN {tool_certificate_issues} ci ON u.id = ci.userid AND ci.templateid = :templateid';
Expand All @@ -185,15 +185,17 @@ public static function potential_users_selector(string $search, int $itemid): ar
if ($CFG->version < 2021050700) {
// Moodle 3.9-3.10.
$fields = get_all_user_name_fields(true, 'u');
$extrasearchfields = [];
if (!empty($CFG->showuseridentity) && has_capability('moodle/site:viewuseridentity', $context)) {
$extrasearchfields = explode(',', $CFG->showuseridentity);
}
} else {
// Moodle 3.11 and above.
$fields = \core_user\fields::for_name()->get_sql('u', false, '', '', false)->selects;
// TODO Does not support custom user profile fields (MDL-70456).
$extrasearchfields = \core_user\fields::get_identity_fields($context, false);
}

$extrasearchfields = array();
if (!empty($CFG->showuseridentity) && has_capability('moodle/site:viewuseridentity', $context)) {
$extrasearchfields = explode(',', $CFG->showuseridentity);
}
if (in_array('email', $extrasearchfields)) {
$fields .= ', u.email';
} else {
Expand Down

0 comments on commit 5e12c05

Please sign in to comment.