MDL-83959 webservice: relax retrieval of token external service info.

The report performs a `LEFT JOIN` on the external service table/entity
so we need to account for that in column callbacks and actions.

Also the shortname field is nullable, so account for that too.
This commit is contained in:
Paul Holden 2024-12-09 16:44:49 +00:00
parent 0888a6d324
commit 074eca0726
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
3 changed files with 12 additions and 9 deletions

View File

@ -91,10 +91,9 @@ class service extends base {
))
->add_joins($this->get_joins())
->set_type(column::TYPE_TEXT)
->add_field("{$tokenalias}.name")
->add_field("{$tokenalias}.shortname")
->add_fields("{$tokenalias}.name, {$tokenalias}.shortname")
->set_is_sortable(true)
->add_callback(static function(string $value, \stdClass $row): string {
->add_callback(static function(?string $value, \stdClass $row): string {
$output = $value;
$output .= \html_writer::tag('div', format_text($row->shortname), [
'class' => 'small text-muted',

View File

@ -141,9 +141,10 @@ class tokens extends system_report {
"{$entityservicealias}.id",
"{$entityservicealias}.shortname",
]))
->add_callback(static function(string $value, \stdClass $row): string {
->add_callback(static function($value, \stdClass $row): string {
global $OUTPUT;
$missingcapabilities = self::get_missing_capabilities((int)$row->userid, (int)$row->id, $row->shortname);
$missingcapabilities = self::get_missing_capabilities((int) $row->userid, (int) $row->id, (string) $row->shortname);
if (empty($missingcapabilities)) {
return '';
}

View File

@ -454,11 +454,14 @@ class webservice {
*/
public function get_token_by_id_with_details($tokenid) {
global $DB;
$sql = "SELECT t.id, t.token, u.id AS userid, u.firstname, u.lastname, s.name, t.creatorid
FROM {external_tokens} t, {user} u, {external_services} s
WHERE t.id=? AND t.tokentype = ? AND s.id = t.externalserviceid AND t.userid = u.id";
$token = $DB->get_record_sql($sql, array($tokenid, EXTERNAL_TOKEN_PERMANENT), MUST_EXIST);
return $token;
FROM {external_tokens} t
LEFT JOIN {user} u ON u.id = t.userid
LEFT JOIN {external_services} s ON s.id = t.externalserviceid
WHERE t.id = ? AND t.tokentype = ?";
return $DB->get_record_sql($sql, [$tokenid, EXTERNAL_TOKEN_PERMANENT], MUST_EXIST);
}
/**