MDL-78503 webservice: include token last access time in reports.

This commit is contained in:
Paul Holden
2023-07-18 09:19:24 +01:00
parent e77452220b
commit ad06206508
4 changed files with 30 additions and 8 deletions
+3 -2
View File
@@ -24,8 +24,9 @@ Feature: Manage external services tokens
And I set the field "Service" to "Moodle mobile web service"
And I set the field "IP restriction" to "127.0.0.1"
When I press "Save changes"
Then I should see "Firstname1 Lastname1" in the "Webservice1" "table_row"
And I should see "127.0.0.1" in the "Webservice1" "table_row"
Then the following should exist in the "generaltable" table:
| Name | First name | Service | IP restriction | Last access |
| Webservice1 | Firstname1 Lastname1 | Moodle mobile web service | 127.0.0.1 | Never |
# Verify the message and the "Copy to clipboard" button.
And I should see "Copy the token now. It won't be shown again once you leave this page."
+17 -1
View File
@@ -89,6 +89,8 @@ class token_table extends \table_sql {
$columns[] = 'iprestriction';
$headers[] = get_string('validuntil', 'webservice');
$columns[] = 'validuntil';
$headers[] = get_string('lastaccess');
$columns[] = 'lastaccess';
if ($this->showalltokens) {
// Only need to show creator if you can see tokens created by other people.
$headers[] = get_string('tokencreator', 'webservice');
@@ -138,6 +140,20 @@ class token_table extends \table_sql {
}
}
/**
* Generate the last access column
*
* @param \stdClass $data
* @return string
*/
public function col_lastaccess(\stdClass $data): string {
if (empty($data->lastaccess)) {
return get_string('never');
} else {
return userdate($data->lastaccess, get_string('strftimedatetime', 'langconfig'));
}
}
/**
* Generate the fullname column. Also includes capabilities the user is missing for the webservice (if any)
*
@@ -282,7 +298,7 @@ class token_table extends \table_sql {
$params = ['tokenmode' => EXTERNAL_TOKEN_PERMANENT];
$selectfields = "SELECT t.id, t.name, t.iprestriction, t.validuntil, t.creatorid,
$selectfields = "SELECT t.id, t.name, t.iprestriction, t.validuntil, t.creatorid, t.lastaccess,
u.id AS userid, $usernamefields,
s.id AS serviceid, s.name AS servicename, s.shortname AS serviceshortname,
$creatorfields ";
+1 -1
View File
@@ -397,7 +397,7 @@ class webservice {
//here retrieve token list (including linked users firstname/lastname and linked services name)
$sql = "SELECT
t.id, t.creatorid, t.name as tokenname, u.firstname, u.lastname,
s.id as wsid, s.name as servicename, s.enabled, s.restrictedusers, t.validuntil
s.id as wsid, s.name as servicename, s.enabled, s.restrictedusers, t.validuntil, t.lastaccess
FROM
{external_tokens} t, {user} u, {external_services} s
WHERE
+9 -4
View File
@@ -293,8 +293,8 @@ class core_webservice_renderer extends plugin_renderer_base {
$strtoken = get_string('tokenname', 'webservice');
$strservice = get_string('service', 'webservice');
$strcreator = get_string('tokencreator', 'webservice');
$strcontext = get_string('context', 'webservice');
$strvaliduntil = get_string('validuntil', 'webservice');
$strlastaccess = get_string('lastaccess');
$return = $this->output->heading(get_string('securitykeys', 'webservice'), 3, 'main', true);
$return .= $this->output->box_start('generalbox webservicestokenui');
@@ -302,8 +302,8 @@ class core_webservice_renderer extends plugin_renderer_base {
$return .= get_string('keyshelp', 'webservice');
$table = new html_table();
$table->head = array($strtoken, $strservice, $strvaliduntil, $strcreator, $stroperation);
$table->align = array('left', 'left', 'left', 'center', 'left', 'center');
$table->head = array($strtoken, $strservice, $strvaliduntil, $strlastaccess, $strcreator, $stroperation);
$table->align = array('left', 'left', 'left', 'center', 'center', 'left', 'center');
$table->width = '100%';
$table->data = array();
@@ -338,11 +338,16 @@ class core_webservice_renderer extends plugin_renderer_base {
$validuntil = userdate($token->validuntil, get_string('strftimedatetime', 'langconfig'));
}
$lastaccess = '';
if (!empty($token->lastaccess)) {
$lastaccess = userdate($token->lastaccess, get_string('strftimedatetime', 'langconfig'));
}
$servicename = $token->servicename;
if (!$token->enabled) { // That is the (1 token-1ws) related ws is not enabled.
$servicename = '<span class="dimmed_text">'.$token->servicename.'</span>';
}
$row = array($token->tokenname, $servicename, $validuntil, $creatoratag, $reset);
$row = array($token->tokenname, $servicename, $validuntil, $lastaccess, $creatoratag, $reset);
if ($documentation) {
$doclink = new moodle_url('/webservice/wsdoc.php',