Skip to content

Commit

Permalink
MDL-67748 admin: Show user identity fields on the manage tokens page
Browse files Browse the repository at this point in the history
On sites with many users, the fullname itself may not be unique
identifier of users. Display the user identity fields below the token
owner's name.
  • Loading branch information
mudrd8mz committed Mar 15, 2021
1 parent c4ad1bf commit 6ea3588
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion webservice/classes/token_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class token_table extends \table_sql {
/** @var bool $hasviewfullnames Does the user have the viewfullnames capability. */
protected $hasviewfullnames;

/** @var array */
protected $userextrafields;

/** @var object */
protected $filterdata;

Expand All @@ -66,6 +69,9 @@ public function __construct($id, $filterdata = null) {
$this->showalltokens = has_capability('moodle/webservice:managealltokens', $context);
$this->hasviewfullnames = has_capability('moodle/site:viewfullnames', $context);

// List of user identity fields.
$this->userextrafields = \core\user_fields::get_identity_fields(\context_system::instance(), false);

// Filter form values.
$this->filterdata = $filterdata;

Expand Down Expand Up @@ -142,9 +148,19 @@ public function col_validuntil($data) {
public function col_fullname($data) {
global $OUTPUT;

$identity = [];

foreach ($this->userextrafields as $userextrafield) {
$identity[] = $data->$userextrafield;
}

$userprofilurl = new \moodle_url('/user/profile.php', ['id' => $data->userid]);
$content = \html_writer::link($userprofilurl, fullname($data, $this->hasviewfullnames));

if ($identity) {
$content .= \html_writer::div('<small>' . implode(', ', $identity) . '</small>', 'useridentity text-muted');
}

// Make up list of capabilities that the user is missing for the given webservice.
$webservicemanager = new \webservice();
$usermissingcaps = $webservicemanager->get_missing_capabilities_by_users([['id' => $data->userid]], $data->serviceid);
Expand All @@ -156,7 +172,7 @@ public function col_fullname($data) {
}, $usermissingcaps[$data->userid]);
$list = \html_writer::alist($links);
$help = $OUTPUT->help_icon('missingcaps', 'webservice');
$content .= print_collapsible_region(\html_writer::div($list . $help, 'missingcaps'), 'small',
$content .= print_collapsible_region(\html_writer::div($list . $help, 'missingcaps'), 'small mt-2',
\html_writer::random_id('usermissingcaps'), get_string('usermissingcaps', 'webservice', $count), '', true, true);
}

Expand Down Expand Up @@ -235,6 +251,10 @@ public function query_db($pagesize, $useinitialsbar = false) {
$usernamefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
$creatorfields = $userfieldsapi->get_sql('c', false, 'creator', '', false)->selects;

if (!empty($this->userextrafields)) {
$usernamefields .= ',u.' . implode(',u.', $this->userextrafields);
}

$params = ['tokenmode' => EXTERNAL_TOKEN_PERMANENT];

$selectfields = "SELECT t.id, t.token, t.iprestriction, t.validuntil, t.creatorid,
Expand Down

0 comments on commit 6ea3588

Please sign in to comment.