mirror of
https://github.com/moodle/moodle.git
synced 2025-08-09 10:56:56 +02:00
Merge branch 'MDL-79496-main' of https://github.com/roland04/moodle
This commit is contained in:
commit
4e881c2595
12 changed files with 674 additions and 73 deletions
|
@ -1,103 +0,0 @@
|
|||
@core @core_admin
|
||||
Feature: Manage external services tokens
|
||||
In order to manage external service usage
|
||||
As an admin
|
||||
I need to be able to create, filter and delete tokens
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | password | firstname | lastname |
|
||||
| user1 | user1 | Firstname1 | Lastname1 |
|
||||
| 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
|
||||
Given I log in as "admin"
|
||||
And I am on site homepage
|
||||
And I navigate to "Server > Web services > Manage tokens" in site administration
|
||||
And I press "Create token"
|
||||
And I set the field "Name" to "Webservice1"
|
||||
And I set the field "User" to "Firstname1 Lastname1"
|
||||
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 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."
|
||||
And "Copy to clipboard" "button" should exist
|
||||
|
||||
# New token can only read once.
|
||||
And I reload the page
|
||||
And I should not see "Copy the token now. It won't be shown again once you leave this page."
|
||||
And "Copy to clipboard" "button" should not exist
|
||||
|
||||
# Delete token.
|
||||
And I click on "Delete" "link" in the "Webservice1" "table_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
|
||||
|
||||
@javascript @skip_chrome_zerosize
|
||||
Scenario: Tokens can be filtered by name (case-insensitive), by user and by service
|
||||
Given the following "core_webservice > Service" exists:
|
||||
| name | Site information |
|
||||
| shortname | siteinfo |
|
||||
| enabled | 1 |
|
||||
And the following "core_webservice > Service function" exists:
|
||||
| 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 |
|
||||
When I log in as "admin"
|
||||
And I navigate to "Server > Web services > Manage tokens" in site administration
|
||||
|
||||
# All created tokens are shown by default.
|
||||
And "Firstname1 Lastname1" "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"
|
||||
|
||||
# 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"
|
||||
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
|
||||
|
||||
# Reset the filter.
|
||||
And I press "Show all tokens"
|
||||
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 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"
|
||||
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"
|
||||
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
|
|
@ -1,31 +0,0 @@
|
|||
@core @core_admin @javascript
|
||||
Feature: Verify the breadcrumbs in external webservice site administration pages
|
||||
Whenever I navigate to external webservice page in site administration
|
||||
As an admin
|
||||
The breadcrumbs should be visible
|
||||
|
||||
Background:
|
||||
Given I log in as "admin"
|
||||
|
||||
Scenario: Verify the breadcrumbs in external services page
|
||||
Given I navigate to "Server > Web services > External services" in site administration
|
||||
And "External services" "text" should exist in the ".breadcrumb" "css_element"
|
||||
And "Web services" "link" should exist in the ".breadcrumb" "css_element"
|
||||
When I click on "Edit" "link"
|
||||
Then "Edit external service" "text" should exist in the ".breadcrumb" "css_element"
|
||||
And "External services" "link" should exist in the ".breadcrumb" "css_element"
|
||||
And "Web services" "link" should exist in the ".breadcrumb" "css_element"
|
||||
And I press "Cancel"
|
||||
And I click on "Add" "link"
|
||||
And I set the field "Name" to "function to test"
|
||||
And "Add external service" "text" should exist in the ".breadcrumb" "css_element"
|
||||
And "External services" "link" should exist in the ".breadcrumb" "css_element"
|
||||
And "Web services" "link" should exist in the ".breadcrumb" "css_element"
|
||||
And I press "Add service"
|
||||
And "Functions" "text" should exist in the ".breadcrumb" "css_element"
|
||||
And "External services" "link" should exist in the ".breadcrumb" "css_element"
|
||||
And "Web services" "link" should exist in the ".breadcrumb" "css_element"
|
||||
And I navigate to "Server > Web services > External services" in site administration
|
||||
And I click on "Delete" "link"
|
||||
And "External services" "text" should exist in the ".breadcrumb" "css_element"
|
||||
And "Web services" "link" should exist in the ".breadcrumb" "css_element"
|
|
@ -1,25 +0,0 @@
|
|||
@core @core_admin @javascript
|
||||
Feature: Verify the breadcrumbs in webservice tokens site administration pages
|
||||
Whenever I navigate to manage tokens page in site administration
|
||||
As an admin
|
||||
The breadcrumbs should be visible
|
||||
|
||||
Background:
|
||||
Given I log in as "admin"
|
||||
|
||||
Scenario: Verify the breadcrumbs in manage tokens page as an admin
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | John | Doe | s1@example.com |
|
||||
And I log in as "admin"
|
||||
And I navigate to "Server > Web services > Manage tokens" in site administration
|
||||
And I click on "Create token" "button"
|
||||
And "Create 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"
|
||||
And I set the field "User" to "John Doe"
|
||||
And I press "Save changes"
|
||||
When I click on "Delete" "link"
|
||||
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"
|
|
@ -1,41 +0,0 @@
|
|||
@core @core_admin @core_webservice
|
||||
Feature: Web service user settings
|
||||
In order to configure authorised users for a web service
|
||||
As an admin
|
||||
I need to use the page that lets you do that
|
||||
|
||||
Background:
|
||||
# Include a custom profile field so we can check it gets displayed
|
||||
Given the following "custom profile fields" exist:
|
||||
| datatype | shortname | name | param2 |
|
||||
| text | frog | Favourite frog | 100 |
|
||||
And the following config values are set as admin:
|
||||
| showuseridentity | email,profile_field_frog |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | profile_field_frog |
|
||||
| user1 | User | One | 1@example.org | Kermit |
|
||||
And the following "core_webservice > Service" exists:
|
||||
| name | Silly service |
|
||||
| shortname | silly |
|
||||
| restrictedusers | 1 |
|
||||
| enabled | 1 |
|
||||
|
||||
Scenario: Add a user to a web service
|
||||
When I log in as "admin"
|
||||
And I navigate to "Server > Web services > External services" in site administration
|
||||
And I click on "Authorised users" "link" in the "Silly service" "table_row"
|
||||
And I set the field "Not authorised users" to "User One"
|
||||
And I press "Add"
|
||||
Then I should see "User One" in the ".alloweduserlist" "css_element"
|
||||
And I should see "1@example.org" in the ".alloweduserlist" "css_element"
|
||||
And I should see "Kermit" in the ".alloweduserlist" "css_element"
|
||||
|
||||
@javascript
|
||||
Scenario: Add a function to a web service
|
||||
When I log in as "admin"
|
||||
And I navigate to "Server > Web services > External services" in site administration
|
||||
And I click on "Functions" "link" in the "Silly service" "table_row"
|
||||
And I follow "Add functions"
|
||||
And I set the field "Name" to "core_blog_get_entries"
|
||||
And I click on "Add functions" "button" in the "#fgroup_id_buttonar" "css_element"
|
||||
Then I should see "core_blog_get_entries" in the "generaltable" "table"
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue