mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
Merge branch 'MDL-79496-main' of https://github.com/roland04/moodle
This commit is contained in:
commit
4e881c2595
7
.upgradenotes/MDL-79496-2024060310555668.yml
Normal file
7
.upgradenotes/MDL-79496-2024060310555668.yml
Normal file
@ -0,0 +1,7 @@
|
||||
issueNumber: MDL-79496
|
||||
notes:
|
||||
core_webservice:
|
||||
- message: >-
|
||||
The `token_table` and `token_filter` classes have been deprecated, in
|
||||
favour of new report builder implementation.
|
||||
type: deprecated
|
@ -23,6 +23,9 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core_reportbuilder\system_report_factory;
|
||||
use core_webservice\reportbuilder\local\systemreports\tokens;
|
||||
|
||||
require(__DIR__ . '/../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->dirroot . '/webservice/lib.php');
|
||||
@ -125,31 +128,12 @@ if ($action === 'delete') {
|
||||
die();
|
||||
}
|
||||
|
||||
// Pre-populate the form with the values that come as a part of the URL - typically when using the table_sql control
|
||||
// links.
|
||||
$filterdata = (object)[
|
||||
'name' => $fname,
|
||||
'users' => $fusers,
|
||||
'services' => $fservices,
|
||||
];
|
||||
|
||||
$filter = new \core_webservice\token_filter($PAGE->url, $filterdata);
|
||||
|
||||
$filter->set_data($filterdata);
|
||||
|
||||
if ($filter->is_submitted()) {
|
||||
$filterdata = $filter->get_data();
|
||||
|
||||
if (isset($filterdata->resetbutton)) {
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->container_start('d-flex flex-wrap');
|
||||
echo $OUTPUT->heading(get_string('managetokens', 'core_webservice'));
|
||||
|
||||
echo html_writer::div($OUTPUT->render(new single_button(new moodle_url($PAGE->url, ['action' => 'create']),
|
||||
get_string('createtoken', 'core_webservice'), 'get', single_button::BUTTON_PRIMARY)), 'my-3');
|
||||
get_string('createtoken', 'core_webservice'), 'get', single_button::BUTTON_PRIMARY)), 'ml-auto');
|
||||
echo $OUTPUT->container_end();
|
||||
|
||||
if (!empty($SESSION->webservicenewlycreatedtoken)) {
|
||||
$webservicemanager = new webservice();
|
||||
@ -167,24 +151,7 @@ if (!empty($SESSION->webservicenewlycreatedtoken)) {
|
||||
}
|
||||
}
|
||||
|
||||
$filter->display();
|
||||
|
||||
$table = new \core_webservice\token_table('webservicetokens', $filterdata);
|
||||
|
||||
// In order to not lose the filter form values by clicking the table control links, make them part of the table's baseurl.
|
||||
$baseurl = new moodle_url($PAGE->url, ['fname' => $filterdata->name]);
|
||||
|
||||
foreach ($filterdata->users as $i => $userid) {
|
||||
$baseurl->param("fusers[{$i}]", $userid);
|
||||
}
|
||||
|
||||
foreach ($filterdata->services as $i => $serviceid) {
|
||||
$baseurl->param("fservices[{$i}]", $serviceid);
|
||||
}
|
||||
|
||||
$table->define_baseurl($baseurl);
|
||||
|
||||
$table->attributes['class'] = 'admintable generaltable';
|
||||
$table->out(30, false);
|
||||
$report = system_report_factory::create(tokens::class, context_system::instance());
|
||||
echo $report->output();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
142
webservice/classes/reportbuilder/local/entities/service.php
Normal file
142
webservice/classes/reportbuilder/local/entities/service.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_webservice\reportbuilder\local\entities;
|
||||
|
||||
use core_collator;
|
||||
use lang_string;
|
||||
use core_reportbuilder\local\entities\base;
|
||||
use core_reportbuilder\local\filters\autocomplete;
|
||||
use core_reportbuilder\local\report\column;
|
||||
use core_reportbuilder\local\report\filter;
|
||||
|
||||
/**
|
||||
* External service report builder entity
|
||||
*
|
||||
* @package core_webservice
|
||||
* @copyright 2023 Mikel Martín <mikel@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class service extends base {
|
||||
|
||||
/**
|
||||
* Database tables that this entity uses and their default aliases
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_default_tables(): array {
|
||||
return [
|
||||
'external_services',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The default title for this entity in the list of columns/conditions/filters in the report builder
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
protected function get_default_entity_title(): lang_string {
|
||||
return new lang_string('service', 'core_webservice');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the entity
|
||||
*
|
||||
* @return base
|
||||
*/
|
||||
public function initialise(): base {
|
||||
$columns = $this->get_all_columns();
|
||||
foreach ($columns as $column) {
|
||||
$this->add_column($column);
|
||||
}
|
||||
// All the filters defined by the entity can also be used as conditions.
|
||||
$filters = $this->get_all_filters();
|
||||
foreach ($filters as $filter) {
|
||||
$this
|
||||
->add_filter($filter)
|
||||
->add_condition($filter);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of all available columns
|
||||
*
|
||||
* @return column[]
|
||||
*/
|
||||
protected function get_all_columns(): array {
|
||||
$tokenalias = $this->get_table_alias('external_services');
|
||||
|
||||
// Service name column.
|
||||
$columnns[] = (new column(
|
||||
'name',
|
||||
new lang_string('name'),
|
||||
$this->get_entity_name()
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_TEXT)
|
||||
->add_field("{$tokenalias}.name")
|
||||
->add_field("{$tokenalias}.shortname")
|
||||
->set_is_sortable(true)
|
||||
->add_callback(static function(string $value, \stdClass $row): string {
|
||||
$output = $value;
|
||||
$output .= \html_writer::tag('div', format_text($row->shortname), [
|
||||
'class' => 'small text-muted',
|
||||
]);
|
||||
return $output;
|
||||
});
|
||||
|
||||
return $columnns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of all available filters
|
||||
*
|
||||
* @return filter[]
|
||||
*/
|
||||
protected function get_all_filters(): array {
|
||||
global $DB;
|
||||
|
||||
$tablealias = $this->get_table_alias('external_services');
|
||||
|
||||
// Service Name filter.
|
||||
$filters[] = (new filter(
|
||||
autocomplete::class,
|
||||
'name',
|
||||
new lang_string('name'),
|
||||
$this->get_entity_name(),
|
||||
"{$tablealias}.name"
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_options_callback(static function(): array {
|
||||
global $DB;
|
||||
$names = $DB->get_fieldset_sql('SELECT DISTINCT name FROM {external_services} ORDER BY name ASC');
|
||||
|
||||
$options = [];
|
||||
foreach ($names as $name) {
|
||||
$options[$name] = $name;
|
||||
}
|
||||
|
||||
core_collator::asort($options);
|
||||
return $options;
|
||||
});
|
||||
|
||||
return $filters;
|
||||
}
|
||||
}
|
168
webservice/classes/reportbuilder/local/entities/token.php
Normal file
168
webservice/classes/reportbuilder/local/entities/token.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_webservice\reportbuilder\local\entities;
|
||||
|
||||
use lang_string;
|
||||
use core_reportbuilder\local\entities\base;
|
||||
use core_reportbuilder\local\filters\{text, date};
|
||||
use core_reportbuilder\local\helpers\format;
|
||||
use core_reportbuilder\local\report\{column, filter};
|
||||
|
||||
/**
|
||||
* External token report builder entity
|
||||
*
|
||||
* @package core_webservice
|
||||
* @copyright 2023 Mikel Martín <mikel@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class token extends base {
|
||||
|
||||
/**
|
||||
* Database tables that this entity uses and their default aliases
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_default_tables(): array {
|
||||
return [
|
||||
'external_tokens',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The default title for this entity in the list of columns/conditions/filters in the report builder
|
||||
*
|
||||
* @return lang_string
|
||||
*/
|
||||
protected function get_default_entity_title(): lang_string {
|
||||
return new lang_string('token', 'core_webservice');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the entity
|
||||
*
|
||||
* @return base
|
||||
*/
|
||||
public function initialise(): base {
|
||||
$columns = $this->get_all_columns();
|
||||
foreach ($columns as $column) {
|
||||
$this->add_column($column);
|
||||
}
|
||||
|
||||
// All the filters defined by the entity can also be used as conditions.
|
||||
$filters = $this->get_all_filters();
|
||||
foreach ($filters as $filter) {
|
||||
$this
|
||||
->add_filter($filter)
|
||||
->add_condition($filter);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of all available columns
|
||||
*
|
||||
* @return column[]
|
||||
*/
|
||||
protected function get_all_columns(): array {
|
||||
$tokenalias = $this->get_table_alias('external_tokens');
|
||||
|
||||
// Token name column.
|
||||
$columnns[] = (new column(
|
||||
'name',
|
||||
new lang_string('name'),
|
||||
$this->get_entity_name()
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_TEXT)
|
||||
->add_field("{$tokenalias}.name")
|
||||
->set_is_sortable(true);
|
||||
|
||||
// IP restriction column.
|
||||
$columnns[] = (new column(
|
||||
'iprestriction',
|
||||
new lang_string('iprestriction', 'core_webservice'),
|
||||
$this->get_entity_name()
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_TEXT)
|
||||
->add_field("{$tokenalias}.iprestriction");
|
||||
|
||||
// Valid until column.
|
||||
$columnns[] = (new column(
|
||||
'validuntil',
|
||||
new lang_string('validuntil', 'core_webservice'),
|
||||
$this->get_entity_name()
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_TIMESTAMP)
|
||||
->add_field("{$tokenalias}.validuntil")
|
||||
->set_is_sortable(true)
|
||||
->add_callback([format::class, 'userdate'], get_string('strftimedatetime', 'core_langconfig'))
|
||||
->add_callback(fn($value) => $value ?: get_string('validuntil_empty', 'core_webservice'));
|
||||
|
||||
// Last access column.
|
||||
$columnns[] = (new column(
|
||||
'lastaccess',
|
||||
new lang_string('lastaccess'),
|
||||
$this->get_entity_name()
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_TIMESTAMP)
|
||||
->add_field("{$tokenalias}.lastaccess")
|
||||
->set_is_sortable(true)
|
||||
->add_callback([format::class, 'userdate'])
|
||||
->add_callback(fn($value) => $value ?: get_string('never'));
|
||||
|
||||
return $columnns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of all available filters
|
||||
*
|
||||
* @return filter[]
|
||||
*/
|
||||
protected function get_all_filters(): array {
|
||||
global $DB;
|
||||
|
||||
$tokenalias = $this->get_table_alias('external_tokens');
|
||||
|
||||
// Name filter.
|
||||
$filters[] = (new filter(
|
||||
text::class,
|
||||
'name',
|
||||
new lang_string('tokenname', 'core_webservice'),
|
||||
$this->get_entity_name(),
|
||||
"{$tokenalias}.name"
|
||||
))
|
||||
->add_joins($this->get_joins());
|
||||
|
||||
// Valid until filter.
|
||||
$filters[] = (new filter(
|
||||
date::class,
|
||||
'validuntil',
|
||||
new lang_string('validuntil', 'core_webservice'),
|
||||
$this->get_entity_name(),
|
||||
"{$tokenalias}.validuntil"
|
||||
))
|
||||
->add_joins($this->get_joins());
|
||||
|
||||
return $filters;
|
||||
}
|
||||
}
|
225
webservice/classes/reportbuilder/local/systemreports/tokens.php
Normal file
225
webservice/classes/reportbuilder/local/systemreports/tokens.php
Normal file
@ -0,0 +1,225 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_webservice\reportbuilder\local\systemreports;
|
||||
|
||||
use context_system;
|
||||
use core_reportbuilder\local\entities\user;
|
||||
use core_reportbuilder\local\report\{action, column};
|
||||
use core_reportbuilder\system_report;
|
||||
use core_webservice\reportbuilder\local\entities\{token, service};
|
||||
use lang_string;
|
||||
use moodle_url;
|
||||
use pix_icon;
|
||||
|
||||
/**
|
||||
* Tokens system report
|
||||
*
|
||||
* @package core_webservice
|
||||
* @copyright 2023 Mikel Martín <mikel@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tokens extends system_report {
|
||||
|
||||
/**
|
||||
* Initialise report, we need to set the main table, load our entities and set columns/filters
|
||||
*/
|
||||
protected function initialise(): void {
|
||||
global $USER;
|
||||
|
||||
$entitytoken = new token();
|
||||
$entitytokenalias = $entitytoken->get_table_alias('external_tokens');
|
||||
|
||||
$this->set_main_table('external_tokens', $entitytokenalias);
|
||||
$this->add_entity($entitytoken);
|
||||
|
||||
$entityservice = new service();
|
||||
$entityservicealias = $entityservice->get_table_alias('external_services');
|
||||
$this->add_entity($entityservice->add_join(
|
||||
"LEFT JOIN {external_services} {$entityservicealias}
|
||||
ON {$entityservicealias}.id = {$entitytokenalias}.externalserviceid"
|
||||
));
|
||||
|
||||
$entityuser = new user();
|
||||
$entityuseralias = $entityuser->get_table_alias('user');
|
||||
$this->add_entity($entityuser->add_join(
|
||||
"LEFT JOIN {user} {$entityuseralias} ON {$entityuseralias}.id = {$entitytokenalias}.userid"
|
||||
));
|
||||
|
||||
$entitycreator = new user();
|
||||
$entitycreator->set_entity_name('creator');
|
||||
$entitycreatoralias = $entitycreator->get_table_alias('user');
|
||||
$this->add_entity($entitycreator->add_join(
|
||||
"LEFT JOIN {user} {$entitycreatoralias} ON {$entitycreatoralias}.id = {$entitytokenalias}.creatorid"
|
||||
));
|
||||
|
||||
// Any columns required by actions should be defined here to ensure they're always available.
|
||||
$this->add_base_fields("{$entitytokenalias}.id");
|
||||
|
||||
// Only show tokens created by the current user for non-manager users.
|
||||
if (!has_capability('moodle/webservice:managealltokens', context_system::instance())) {
|
||||
$this->add_base_condition_simple("{$entitycreatoralias}.userid", $USER->id);
|
||||
}
|
||||
|
||||
$this->add_columns($entityuseralias, $entityservicealias);
|
||||
$this->add_filters();
|
||||
$this->add_actions();
|
||||
|
||||
$this->set_initial_sort_column('token:validuntil', SORT_ASC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates access to view this report
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function can_view(): bool {
|
||||
return has_capability('moodle/site:config', context_system::instance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the columns we want to display in the report
|
||||
*
|
||||
* They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their
|
||||
* unique identifier
|
||||
*
|
||||
* @param string $entityuseralias
|
||||
* @param string $entityservicealias
|
||||
*/
|
||||
public function add_columns(string $entityuseralias, string $entityservicealias): void {
|
||||
$this->add_columns_from_entities([
|
||||
'token:name',
|
||||
'user:fullnamewithlink',
|
||||
]);
|
||||
|
||||
// Include all identity field columns.
|
||||
$identitycolumns = $this->get_entity('user')->get_identity_columns($this->get_context());
|
||||
foreach ($identitycolumns as $identitycolumn) {
|
||||
$this->add_column($identitycolumn);
|
||||
}
|
||||
|
||||
$this->add_columns_from_entities([
|
||||
'service:name',
|
||||
'token:iprestriction',
|
||||
'token:validuntil',
|
||||
'token:lastaccess',
|
||||
'creator:fullnamewithlink',
|
||||
]);
|
||||
|
||||
$this->get_column('user:fullnamewithlink')
|
||||
->set_title(new lang_string('user'));
|
||||
$this->get_column('service:name')
|
||||
->set_title(new lang_string('service', 'core_webservice'));
|
||||
$this->get_column('creator:fullnamewithlink')
|
||||
->set_title(new lang_string('tokencreator', 'core_webservice'))
|
||||
->set_is_available(has_capability('moodle/webservice:managealltokens', context_system::instance()));
|
||||
|
||||
$this->add_column((new column(
|
||||
'missingcapabilities',
|
||||
new lang_string('missingcaps', 'webservice'),
|
||||
'user'
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_TEXT)
|
||||
->add_field("{$entityuseralias}.id", 'userid')
|
||||
->add_fields(implode(', ', [
|
||||
"{$entityservicealias}.id",
|
||||
"{$entityservicealias}.shortname",
|
||||
]))
|
||||
->add_callback(static function(string $value, \stdClass $row): string {
|
||||
global $OUTPUT;
|
||||
$missingcapabilities = self::get_missing_capabilities((int)$row->userid, (int)$row->id, $row->shortname);
|
||||
if (empty($missingcapabilities)) {
|
||||
return '';
|
||||
}
|
||||
$missingcapabilities = array_map(function($missingcapability) {
|
||||
return (object)[
|
||||
'name' => $missingcapability,
|
||||
'link' => get_capability_docs_link((object)['name' => $missingcapability]),
|
||||
];
|
||||
}, $missingcapabilities);
|
||||
return $OUTPUT->render_from_template('core_webservice/missing_capabilities', [
|
||||
'missingcapabilities' => $missingcapabilities,
|
||||
'helpicon' => $OUTPUT->help_icon('missingcaps', 'webservice'),
|
||||
]);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the filters we want to display in the report
|
||||
*
|
||||
* They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their
|
||||
* unique identifier
|
||||
*/
|
||||
protected function add_filters(): void {
|
||||
$filters = [
|
||||
'token:name',
|
||||
'user:fullname',
|
||||
'service:name',
|
||||
'token:validuntil',
|
||||
];
|
||||
|
||||
$this->add_filters_from_entities($filters);
|
||||
|
||||
$this->get_filter('user:fullname')
|
||||
->set_header(new lang_string('user'));
|
||||
$this->get_filter('service:name')
|
||||
->set_header(new lang_string('service', 'core_webservice'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the system report actions. An extra column will be appended to each row, containing all actions added here
|
||||
*
|
||||
* Note the use of ":id" placeholder which will be substituted according to actual values in the row
|
||||
*/
|
||||
protected function add_actions(): void {
|
||||
|
||||
// Action to delete token.
|
||||
$this->add_action((new action(
|
||||
new moodle_url('/admin/webservice/tokens.php', [
|
||||
'action' => 'delete',
|
||||
'tokenid' => ':id',
|
||||
]),
|
||||
new pix_icon('t/delete', '', 'core'),
|
||||
['class' => 'text-danger'],
|
||||
false,
|
||||
new lang_string('delete', 'core')
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the missing capabilities for a user
|
||||
*
|
||||
* @param int $userid
|
||||
* @param int $serviceid
|
||||
* @param string $serviceshortname
|
||||
* @return array
|
||||
*/
|
||||
protected static function get_missing_capabilities(int $userid, int $serviceid, string $serviceshortname): array {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/webservice/lib.php');
|
||||
|
||||
$webservicemanager = new \webservice();
|
||||
$usermissingcaps = $webservicemanager->get_missing_capabilities_by_users([['id' => $userid]], $serviceid);
|
||||
if ($serviceshortname != MOODLE_OFFICIAL_MOBILE_SERVICE && !is_siteadmin($userid)) {
|
||||
return $usermissingcaps[$userid] ?? [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
@ -31,7 +31,16 @@ use moodleform;
|
||||
*
|
||||
* @copyright 2020 David Mudrák <david@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
* @deprecated since 4.5 MDL-79496. Table replaced with a report builder system report.
|
||||
* @todo MDL-79909 This will be deleted in Moodle 6.0.
|
||||
*/
|
||||
#[\core\attribute\deprecated(
|
||||
replacement: null,
|
||||
since: '4.5',
|
||||
reason: 'Filters replaced with a report builder system report',
|
||||
mdl: 'MDL-79496',
|
||||
)]
|
||||
class token_filter extends moodleform {
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,16 @@ require_once($CFG->dirroot . '/user/lib.php');
|
||||
* @package core_webservice
|
||||
* @copyright 2017 John Okely <john@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
* @deprecated since 4.5 MDL-79496. Table replaced with a report builder system report.
|
||||
* @todo MDL-79909 This will be deleted in Moodle 6.0.
|
||||
*/
|
||||
#[\core\attribute\deprecated(
|
||||
replacement: null,
|
||||
since: '4.5',
|
||||
reason: 'Table replaced with a report builder system report',
|
||||
mdl: 'MDL-79496',
|
||||
)]
|
||||
class token_table extends \table_sql {
|
||||
|
||||
/**
|
||||
|
43
webservice/templates/missing_capabilities.mustache
Normal file
43
webservice/templates/missing_capabilities.mustache
Normal file
@ -0,0 +1,43 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core_webservice/missing_capabilities
|
||||
|
||||
Display missing capabilities in Manage tokens system report
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"missingcapabilities": [
|
||||
{
|
||||
"capabilityname": "capabilityname",
|
||||
"capabilitylink": "<a href='capabilitylink'>capabilityname</a>"
|
||||
}
|
||||
],
|
||||
"helpicon": "<a class='btn'><i class='icon fa fa-question-circle'></i></a>"
|
||||
}
|
||||
}}
|
||||
<div class="d-flex missingcaps">
|
||||
<ul class="list-unstyled">
|
||||
{{#missingcapabilities}}
|
||||
<li class="mb-1">
|
||||
{{{link}}}
|
||||
<div class="text-muted">{{name}}</div>
|
||||
</li>
|
||||
{{/missingcapabilities}}
|
||||
</ul>
|
||||
<div>{{{helpicon}}}</div>
|
||||
</div>
|
@ -1,4 +1,4 @@
|
||||
@core @core_admin
|
||||
@core @core_admin @core_webservice
|
||||
Feature: Manage external services tokens
|
||||
In order to manage external service usage
|
||||
As an admin
|
||||
@ -11,7 +11,6 @@ Feature: Manage external services tokens
|
||||
| user2 | user2 | Firstname2 | Lastname2 |
|
||||
| user3 | user3 | Firstname3 | Lastname3 |
|
||||
| user4 | user4 | Firstname4 | Lastname4 |
|
||||
And I change window size to "small"
|
||||
|
||||
@javascript
|
||||
Scenario: Add a token to user identified by name and then delete that token
|
||||
@ -25,7 +24,7 @@ Feature: Manage external services tokens
|
||||
And I set the field "IP restriction" to "127.0.0.1"
|
||||
When I press "Save changes"
|
||||
Then the following should exist in the "generaltable" table:
|
||||
| Name | First name | Service | IP restriction | Last access |
|
||||
| Name | User | 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.
|
||||
@ -38,7 +37,7 @@ Feature: Manage external services tokens
|
||||
And "Copy to clipboard" "button" should not exist
|
||||
|
||||
# Delete token.
|
||||
And I click on "Delete" "link" in the "Webservice1" "table_row"
|
||||
And I press "Delete" action in the "Webservice1" report row
|
||||
And I should see "Do you really want to delete this web service token for Firstname1 Lastname1 on the service Moodle mobile web service?"
|
||||
And I press "Delete"
|
||||
And "Webservice1" "table_row" should not exist
|
||||
@ -53,10 +52,10 @@ Feature: Manage external services tokens
|
||||
| service | siteinfo |
|
||||
| functions | core_webservice_get_site_info |
|
||||
And the following "core_webservice > Tokens" exist:
|
||||
| user | service | name |
|
||||
| user2 | siteinfo | WEBservice1 |
|
||||
| user3 | moodle_mobile_app | webservicE3 |
|
||||
| user4 | siteinfo | New service2 |
|
||||
| user | service | name | validuntil |
|
||||
| user2 | siteinfo | WEBservice1 | ## yesterday ## |
|
||||
| user3 | moodle_mobile_app | webservicE3 | ## +1 year ## |
|
||||
| user4 | siteinfo | New service2 | ## +1 year ## |
|
||||
When I log in as "admin"
|
||||
And I navigate to "Server > Web services > Manage tokens" in site administration
|
||||
|
||||
@ -66,38 +65,70 @@ Feature: Manage external services tokens
|
||||
And I should see "Moodle mobile web service" in the "Firstname3 Lastname3" "table_row"
|
||||
And I should see "Site information" in the "Firstname4 Lastname4" "table_row"
|
||||
|
||||
# Filter tokens by by name (case-insensitive).
|
||||
And I click on "Tokens filter" "link"
|
||||
And I set the field "Name" to "webservice"
|
||||
And I press "Show only matching tokens"
|
||||
# Filter tokens by by name.
|
||||
And I click on "Filters" "button"
|
||||
And I set the following fields in the "Name" "core_reportbuilder > Filter" to these values:
|
||||
| Name operator | Contains |
|
||||
| Name value | webservice |
|
||||
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
|
||||
And I should see "Site information" in the "Firstname2 Lastname2" "table_row"
|
||||
And I should see "Moodle mobile web service" in the "Firstname3 Lastname3" "table_row"
|
||||
And "Firstname4 Lastname4" "table_row" should not exist
|
||||
And I click on "Reset all" "button" in the "[data-region='report-filters']" "css_element"
|
||||
|
||||
# Reset the filter.
|
||||
And I press "Show all tokens"
|
||||
# Filter tokens by user.
|
||||
And I set the following fields in the "User" "core_reportbuilder > Filter" to these values:
|
||||
| User operator | Contains |
|
||||
| User value | Firstname2 |
|
||||
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
|
||||
Then "Firstname3 Lastname3" "table_row" should not exist
|
||||
And "Firstname4 Lastname4" "table_row" should not exist
|
||||
And I should see "Site information" in the "Firstname2 Lastname2" "table_row"
|
||||
And I should see "Moodle mobile web service" in the "Firstname3 Lastname3" "table_row"
|
||||
And I should see "Site information" in the "Firstname4 Lastname4" "table_row"
|
||||
And I click on "Reset all" "button" in the "[data-region='report-filters']" "css_element"
|
||||
|
||||
# Filter tokens by user (note we can select the user by the identity field here).
|
||||
When I click on "Tokens filter" "link"
|
||||
And I set the field "User" to "user2@example.com"
|
||||
And I press "Show only matching tokens"
|
||||
# Filter tokens by service.
|
||||
And I set the following fields in the "Service" "core_reportbuilder > Filter" to these values:
|
||||
| Service value | Site information |
|
||||
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
|
||||
And I should see "Site information" in the "Firstname2 Lastname2" "table_row"
|
||||
And I should see "Site information" in the "Firstname4 Lastname4" "table_row"
|
||||
And "Firstname3 Lastname3" "table_row" should not exist
|
||||
And I click on "Reset all" "button" in the "[data-region='report-filters']" "css_element"
|
||||
|
||||
# Filter tokens by valid date.
|
||||
And I set the following fields in the "Valid until" "core_reportbuilder > Filter" to these values:
|
||||
| Valid until operator | Last |
|
||||
| Valid until value | 2 |
|
||||
| Valid until unit | day(s) |
|
||||
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
|
||||
Then "Firstname3 Lastname3" "table_row" should not exist
|
||||
And "Firstname4 Lastname4" "table_row" should not exist
|
||||
And I should see "Site information" in the "Firstname2 Lastname2" "table_row"
|
||||
|
||||
# Reset the filter.
|
||||
And I press "Show all tokens"
|
||||
# Reset the filters.
|
||||
And I click on "Reset all" "button" in the "[data-region='report-filters']" "css_element"
|
||||
And I should see "Site information" in the "Firstname2 Lastname2" "table_row"
|
||||
And I should see "Moodle mobile web service" in the "Firstname3 Lastname3" "table_row"
|
||||
And I should see "Site information" in the "Firstname4 Lastname4" "table_row"
|
||||
|
||||
# Filter tokens by service.
|
||||
And I click on "Tokens filter" "link"
|
||||
And I set the field "Service" to "Site information"
|
||||
And I press "Show only matching tokens"
|
||||
And I should see "Site information" in the "Firstname2 Lastname2" "table_row"
|
||||
And I should see "Site information" in the "Firstname4 Lastname4" "table_row"
|
||||
And "Firstname3 Lastname3" "table_row" should not exist
|
||||
@javascript
|
||||
Scenario: Tokens table should display missing capabilities
|
||||
Given the following "core_webservice > Services" exist:
|
||||
| name | shortname | enabled |
|
||||
| Test Service 1 | testservice1 | 1 |
|
||||
| Test Service 2 | testservice2 | 1 |
|
||||
And the following "core_webservice > Service functions" exist:
|
||||
| service | functions |
|
||||
| testservice1 | block_accessreview_get_module_data |
|
||||
| testservice2 | core_block_fetch_addable_blocks |
|
||||
And the following "core_webservice > Tokens" exist:
|
||||
| user | service | name |
|
||||
| user1 | testservice1 | Token 01 |
|
||||
| user2 | testservice2 | Token 02 |
|
||||
When I log in as "admin"
|
||||
And I navigate to "Server > Web services > Manage tokens" in site administration
|
||||
# Check the missing capabilities.
|
||||
Then I should see "View the accessibility review" in the "Token 01" "table_row"
|
||||
And I should see "block/accessreview:view" in the "Token 01" "table_row"
|
||||
Then I should see "Manage blocks on a page" in the "Token 02" "table_row"
|
||||
And I should see "moodle/site:manageblocks" in the "Token 02" "table_row"
|
@ -1,4 +1,4 @@
|
||||
@core @core_admin @javascript
|
||||
@core @core_admin @core_webservice @javascript
|
||||
Feature: Verify the breadcrumbs in external webservice site administration pages
|
||||
Whenever I navigate to external webservice page in site administration
|
||||
As an admin
|
@ -1,4 +1,4 @@
|
||||
@core @core_admin @javascript
|
||||
@core @core_admin @core_webservice @javascript
|
||||
Feature: Verify the breadcrumbs in webservice tokens site administration pages
|
||||
Whenever I navigate to manage tokens page in site administration
|
||||
As an admin
|
||||
@ -19,7 +19,7 @@ Feature: Verify the breadcrumbs in webservice tokens site administration pages
|
||||
And "Web services" "link" should exist in the ".breadcrumb" "css_element"
|
||||
And I set the field "User" to "John Doe"
|
||||
And I press "Save changes"
|
||||
When I click on "Delete" "link"
|
||||
When I press "Delete" action in the "John Doe" report row
|
||||
Then "Delete token" "text" should exist in the ".breadcrumb" "css_element"
|
||||
And "Manage tokens" "link" should exist in the ".breadcrumb" "css_element"
|
||||
And "Web services" "link" should exist in the ".breadcrumb" "css_element"
|
Loading…
x
Reference in New Issue
Block a user