Commit 596b0bb2 authored by David Mudrák's avatar David Mudrák
Browse files

MDL-67748 admin: Improve the display of missing capabilities

The patch improves the display of the missing capabilities on the Manage
tokens page and the Select authorised users page. The list of
capabilities is rendered in a collapsible area and does not occupy too
much space by default.

Additionally on the later page, the patch improves the display of the
list of existing authorised users so that it respects the configured
identity fields.
parent c07f15d7
......@@ -108,7 +108,7 @@ $usersmissingcaps = $webservicemanager->get_missing_capabilities_by_users($allow
//add the missing capabilities to the allowed users object to be displayed by renderer
foreach ($allowedusers as &$alloweduser) {
if (!is_siteadmin($alloweduser->id) and array_key_exists($alloweduser->id, $usersmissingcaps)) {
$alloweduser->missingcapabilities = implode(', ', $usersmissingcaps[$alloweduser->id]);
$alloweduser->missingcapabilities = $usersmissingcaps[$alloweduser->id];
}
}
......
......@@ -142,12 +142,14 @@ class token_table extends \table_sql {
$usermissingcaps = $webservicemanager->get_missing_capabilities_by_users([['id' => $data->userid]], $data->serviceid);
if (!is_siteadmin($data->userid) && array_key_exists($data->userid, $usermissingcaps)) {
$missingcapabilities = implode(', ', $usermissingcaps[$data->userid]);
if (!empty($missingcapabilities)) {
$capabilitiesstring = get_string('usermissingcaps', 'webservice', $missingcapabilities) . ' ' .
$OUTPUT->help_icon('missingcaps', 'webservice');
$content .= \html_writer::div($capabilitiesstring, 'missingcaps');
}
$count = \html_writer::span(count($usermissingcaps[$data->userid]), 'badge badge-danger');
$links = array_map(function($capname) {
return get_capability_docs_link((object)['name' => $capname]) . \html_writer::div($capname, 'text-muted');
}, $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',
\html_writer::random_id('usermissingcaps'), get_string('usermissingcaps', 'webservice', $count), '', true, true);
}
return $content;
......
......@@ -285,9 +285,16 @@ class webservice {
*/
public function get_ws_authorised_users($serviceid) {
global $DB, $CFG;
$params = array($CFG->siteguest, $serviceid);
$sql = " SELECT u.id as id, esu.id as serviceuserid, u.email as email, u.firstname as firstname,
u.lastname as lastname,
$namefields = get_all_user_name_fields(true, 'u');
foreach (get_extra_user_fields(context_system::instance()) as $extrafield) {
$namefields .= ',u.' . $extrafield;
}
$sql = " SELECT u.id as id, esu.id as serviceuserid, {$namefields},
esu.iprestriction as iprestriction, esu.validuntil as validuntil,
esu.timecreated as timecreated
FROM {user} u, {external_services_users} esu
......@@ -296,6 +303,7 @@ class webservice {
AND esu.externalserviceid = ?";
$users = $DB->get_records_sql($sql, $params);
return $users;
}
......
......@@ -96,7 +96,7 @@ class core_webservice_renderer extends plugin_renderer_base {
}
/**
* Display list of authorised users
* Display list of authorised users for the given external service.
*
* @param array $users authorised users
* @param int $serviceid service id
......@@ -104,25 +104,43 @@ class core_webservice_renderer extends plugin_renderer_base {
*/
public function admin_authorised_user_list($users, $serviceid) {
global $CFG;
$html = $this->output->box_start('generalbox', 'alloweduserlist');
$listitems = [];
$extrafields = get_extra_user_fields(context_system::instance());
foreach ($users as $user) {
$modifiedauthoriseduserurl = new moodle_url('/' . $CFG->admin . '/webservice/service_user_settings.php',
array('userid' => $user->id, 'serviceid' => $serviceid));
$html .= html_writer::tag('a', $user->firstname . " "
. $user->lastname . ", " . s($user->email),
array('href' => $modifiedauthoriseduserurl));
//add missing capabilities
$settingsurl = new moodle_url('/admin/webservice/service_user_settings.php',
['userid' => $user->id, 'serviceid' => $serviceid]);
$identity = [];
foreach ($extrafields as $extrafield) {
if (isset($user->{$extrafield})) {
$identity[] = s($user->{$extrafield});
}
}
$identity = $identity ? html_writer::div(implode(', ', $identity), 'small') : '';
$link = html_writer::link($settingsurl, fullname($user));
if (!empty($user->missingcapabilities)) {
$html .= html_writer::tag('div',
get_string('usermissingcaps', 'webservice', $user->missingcapabilities)
. ' ' . $this->output->help_icon('missingcaps', 'webservice'),
array('class' => 'missingcaps', 'id' => 'usermissingcaps'));
$html .= html_writer::empty_tag('br');
$count = html_writer::span(count($user->missingcapabilities), 'badge badge-danger');
$links = array_map(function($capname) {
return get_capability_docs_link((object)['name' => $capname]) . html_writer::div($capname, 'text-muted');
}, $user->missingcapabilities);
$list = html_writer::alist($links);
$help = $this->output->help_icon('missingcaps', 'webservice');
$missingcaps = print_collapsible_region(html_writer::div($list . $help, 'missingcaps'), 'small',
html_writer::random_id('usermissingcaps'), get_string('usermissingcaps', 'webservice', $count), '', true, true);
} else {
$html .= html_writer::empty_tag('br') . html_writer::empty_tag('br');
$missingcaps = '';
}
$listitems[] = $link . $identity . $missingcaps;
}
$html .= $this->output->box_end();
$html = html_writer::div(html_writer::alist($listitems), 'alloweduserlist');
return $html;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment