webservice MDL-21351

Manage token page: user should be linked to their user profil
Security keys page: display token created by administrator
Manage service page: rewording :
Authorised user only => user
This commit is contained in:
jerome mouneyrac 2010-02-12 04:14:26 +00:00
parent 1762a2642a
commit 1bd06507df
3 changed files with 22 additions and 8 deletions

View File

@ -13,6 +13,7 @@ $string['addrequiredcapability'] = 'Assign/Unassign the required capability';
$string['addservice'] = 'Add a new service: $a->name (id: $a->id)';
$string['addaservice'] = 'Add service';
$string['actwebserviceshhdr'] = 'Active web service protocols';
$string['allusers'] = 'All users';
$string['apiexplorer'] = 'API explorer';
$string['apiexplorernotavalaible'] = 'API explorer not available yet.';
$string['arguments'] = 'Arguments';
@ -117,6 +118,8 @@ $string['testauserwithtestclientdescription'] = 'Simulate external access to the
$string['testwithtestclientdescription'] = 'Simulate external access to the service using the web service test client. Use an enabled protocol with token authentication. <strong>Warning: the functions that you test WILL BE EXECUTED, be carefull what you choose to test!!!</strong>';
$string['token'] = 'Token';
$string['tokenauthlog'] = 'Token authentication';
$string['tokencreatedbyadmin'] = 'Can only be reset by administrator (*)';
$string['tokencreatedbyadminhelp'] = '(*) Tokens are generally automatically created when you first visit this page. However an administrator could create a token for you. In this special case the token can only be reset by the administrator.';
$string['validuntil'] = 'Valid until';
$string['userasclients'] = 'Users as clients with token';
$string['userasclientsdescription'] = 'The following steps help you to set up the Moodle web service for users as clients. These steps also help to set up the recommended token (security keys) authentication method. In this use case, the user will generate his token from his <strong>Security keys</strong> profile page.';

View File

@ -6218,7 +6218,7 @@ class admin_setting_manageexternalservices extends admin_setting {
$strplugin = get_string('plugin', 'admin');
$stradd = get_string('add');
$strfunctions = get_string('functions', 'webservice');
$strusers = get_string('restrictedusers', 'webservice');
$strusers = get_string('users');
$strserviceusers = get_string('serviceusers', 'webservice');
$esurl = "$CFG->wwwroot/$CFG->admin/webservice/service.php";
@ -6258,7 +6258,7 @@ class admin_setting_manageexternalservices extends admin_setting {
if ($service->restrictedusers) {
$users = "<a href=\"$euurl?id=$service->id\">$strserviceusers</a>";
} else {
$users = '-';
$users = get_string('allusers', 'webservice');
}
$edit = "<a href=\"$esurl?id=$service->id\">$stredit</a>";
@ -6299,7 +6299,7 @@ class admin_setting_manageexternalservices extends admin_setting {
if ($service->restrictedusers) {
$users = "<a href=\"$euurl?id=$service->id\">$strserviceusers</a>";
} else {
$users = '-';
$users = get_string('allusers', 'webservice');
}
$edit = "<a href=\"$esurl?id=$service->id\">$stredit</a>";
@ -6789,7 +6789,7 @@ class admin_setting_managewebservicetokens extends admin_setting {
//TODO: in order to let the administrator delete obsolete token, split this request in multiple request or use LEFT JOIN
//here retrieve token list (including linked users firstname/lastname and linked services name)
$sql = "SELECT t.id, t.token, u.firstname, u.lastname, s.name, t.validuntil
$sql = "SELECT t.id, t.token, u.id AS userid, u.firstname, u.lastname, s.name, t.validuntil
FROM {external_tokens} t, {user} u, {external_services} s
WHERE t.creatorid=? AND t.tokentype = ? AND s.id = t.externalserviceid AND t.userid = u.id";
$tokens = $DB->get_records_sql($sql, array($USER->id, EXTERNAL_TOKEN_PERMANENT));
@ -6814,7 +6814,11 @@ class admin_setting_managewebservicetokens extends admin_setting {
$iprestriction = $token->iprestriction;
}
$table->data[] = array($token->token, $token->firstname." ".$token->lastname, $token->name, '', $iprestriction, $validuntil, $delete);
$userprofilurl = new moodle_url('/user/view.php?id='.$token->userid);
$useratag = html_writer::start_tag('a', array('href' => $userprofilurl));
$useratag .= $token->firstname." ".$token->lastname;
$useratag .= html_writer::end_tag('a');
$table->data[] = array($token->token, $useratag, $token->name, '', $iprestriction, $validuntil, $delete);
}
$return .= $OUTPUT->table($table);

View File

@ -138,11 +138,11 @@ switch ($action) {
//here retrieve token list (including linked users firstname/lastname and linked services name)
$sql = "SELECT
t.id, t.token, u.firstname, u.lastname, s.name, t.validuntil
t.id, t.creatorid, t.token, u.firstname, u.lastname, s.name, t.validuntil
FROM
{external_tokens} t, {user} u, {external_services} s
WHERE
t.creatorid=? AND t.tokentype = ".EXTERNAL_TOKEN_PERMANENT." AND s.id = t.externalserviceid AND t.userid = u.id";
t.userid=? AND t.tokentype = ".EXTERNAL_TOKEN_PERMANENT." AND s.id = t.externalserviceid AND t.userid = u.id";
$tokens = $DB->get_records_sql($sql, array( $USER->id));
if (!empty($tokens)) {
foreach ($tokens as $token) {
@ -156,10 +156,17 @@ switch ($action) {
$validuntil = date("F j, Y"); //TODO: language support (look for moodle function)
}
if ($token->creatorid != $USER->id) {
$reset = get_string('tokencreatedbyadmin', 'webservice');
$admintokeninfo = get_string('tokencreatedbyadminhelp', 'webservice');
}
$table->data[] = array($token->token, $token->name, $validuntil, $reset);
}
$return .= $OUTPUT->table($table);
if (!empty($admintokeninfo)) {
$return .= $admintokeninfo;
}
} else {
$return .= get_string('notoken', 'webservice');
}