mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
MDL-75316 core_moodlenet: Add setting to control sharing
Originally implemented as MDL-75319
This commit is contained in:
parent
d9a6577410
commit
ef2a1934a0
55
admin/settings/moodlenet.php
Normal file
55
admin/settings/moodlenet.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* This file gives information about MoodleNet.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2023 Huong Nguyen <huongnv13@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
if ($hassiteconfig) {
|
||||
if (!empty($CFG->enablesharingtomoodlenet)) {
|
||||
if (!$ADMIN->locate('moodlenet')) {
|
||||
$ADMIN->add('root', new admin_category('moodlenet', get_string('pluginname', 'tool_moodlenet')));
|
||||
}
|
||||
|
||||
// Outbound settings page.
|
||||
$settings = new admin_settingpage('moodlenetoutbound', new lang_string('moodlenet:outboundsettings', 'moodle'));
|
||||
$ADMIN->add('moodlenet', $settings);
|
||||
|
||||
// Get all the issuers.
|
||||
$issuers = \core\oauth2\api::get_all_issuers();
|
||||
$oauth2services = [
|
||||
'' => new lang_string('none', 'admin'),
|
||||
];
|
||||
foreach ($issuers as $issuer) {
|
||||
// Get the enabled issuer with the service type is MoodleNet only.
|
||||
if ($issuer->get('servicetype') == 'moodlenet' && $issuer->get('enabled')) {
|
||||
$oauth2services[$issuer->get('id')] = s($issuer->get('name'));
|
||||
}
|
||||
}
|
||||
|
||||
$url = new \moodle_url('/admin/tool/oauth2/issuers.php');
|
||||
|
||||
$settings->add(new admin_setting_configselect('moodlenet/oauthservice', new lang_string('issuer', 'auth_oauth2'),
|
||||
new lang_string('moodlenet:configoauthservice', 'moodle', $url->out()), '', $oauth2services));
|
||||
|
||||
}
|
||||
}
|
52
admin/tests/behat/moodlenet_outbound.feature
Normal file
52
admin/tests/behat/moodlenet_outbound.feature
Normal file
@ -0,0 +1,52 @@
|
||||
@core @core_admin
|
||||
Feature: MoodleNet outbound configuration
|
||||
In order to send activity/resource to MoodleNet
|
||||
As a Moodle administrator
|
||||
I need to set outbound configuration
|
||||
|
||||
Background:
|
||||
Given I log in as "admin"
|
||||
|
||||
Scenario: Share to MoodleNet experimental flag
|
||||
Given I navigate to "Development > Experimental" in site administration
|
||||
Then "Enable sharing to MoodleNet" "field" should exist
|
||||
And the field "Enable sharing to MoodleNet" matches value "0"
|
||||
|
||||
Scenario: Outbound configuration without experimental flag enable yet
|
||||
Given I navigate to "MoodleNet" in site administration
|
||||
Then I should not see "MoodleNet outbound settings"
|
||||
|
||||
Scenario: Outbound configuration without OAuth 2 service setup yet
|
||||
Given the following config values are set as admin:
|
||||
| enablesharingtomoodlenet | 1 |
|
||||
When I navigate to "MoodleNet" in site administration
|
||||
Then I should see "MoodleNet outbound settings"
|
||||
And I click on "MoodleNet outbound settings" "link"
|
||||
And the field "OAuth 2 service" matches value "None"
|
||||
And I should see "Select the OAuth 2 service that is configured to talk to the MoodleNet server. If the service doesn't exist yet, you will need to create it."
|
||||
And I click on "create" "link"
|
||||
And I should see "OAuth 2 services"
|
||||
|
||||
Scenario: Outbound configuration with OAuth 2 service setup
|
||||
Given a MoodleNet mock server is configured
|
||||
And the following config values are set as admin:
|
||||
| enablesharingtomoodlenet | 1 |
|
||||
And I navigate to "Server > OAuth 2 services" in site administration
|
||||
And I press "Custom"
|
||||
And I should see "Create new service: Custom"
|
||||
And I set the following fields to these values:
|
||||
| Name | Testing custom service |
|
||||
| Client ID | thisistheclientid |
|
||||
| Client secret | supersecret |
|
||||
And I press "Save changes"
|
||||
When I navigate to "MoodleNet > MoodleNet outbound settings" in site administration
|
||||
Then the field "OAuth 2 service" matches value "None"
|
||||
And I navigate to "Server > OAuth 2 services" in site administration
|
||||
And I press "MoodleNet"
|
||||
And I should see "Create new service: MoodleNet"
|
||||
And I change the MoodleNet field "Service base URL" to mock server
|
||||
And I press "Save changes"
|
||||
And I navigate to "MoodleNet > MoodleNet outbound settings" in site administration
|
||||
And the "OAuth 2 service" "field" should be enabled
|
||||
And I should see "MoodleNet" in the "OAuth 2 service" "select"
|
||||
And I should not see "Testing custom service" in the "OAuth 2 service" "select"
|
@ -35,7 +35,9 @@ if ($hassiteconfig) {
|
||||
|
||||
// Create a MoodleNet category.
|
||||
if (get_config('tool_moodlenet', 'enablemoodlenet')) {
|
||||
$ADMIN->add('root', new admin_category('moodlenet', get_string('pluginname', 'tool_moodlenet')));
|
||||
if (!$ADMIN->locate('moodlenet')) {
|
||||
$ADMIN->add('root', new admin_category('moodlenet', get_string('pluginname', 'tool_moodlenet')));
|
||||
}
|
||||
// Our settings page.
|
||||
$settings = new admin_settingpage('tool_moodlenet', get_string('moodlenetsettings', 'tool_moodlenet'));
|
||||
$ADMIN->add('moodlenet', $settings);
|
||||
|
@ -1365,6 +1365,8 @@ $string['moodledocslink'] = 'Help and documentation';
|
||||
$string['moodleversion'] = 'Moodle version';
|
||||
$string['moodlerelease'] = 'Moodle release';
|
||||
$string['moodleservicesandsupport'] = 'Services and support';
|
||||
$string['moodlenet:configoauthservice'] = 'Select the OAuth 2 service that is configured to talk to the MoodleNet server. If the service doesn\'t exist yet, you will need to <a href="{$a}">create</a> it.';
|
||||
$string['moodlenet:outboundsettings'] = 'MoodleNet outbound settings';
|
||||
$string['more'] = 'more';
|
||||
$string['morehelp'] = 'More help';
|
||||
$string['morehelpaboutmodule'] = 'More help about the {$a} activity';
|
||||
|
56
lib/tests/behat/behat_moodlenet.php
Normal file
56
lib/tests/behat/behat_moodlenet.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?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/>.
|
||||
|
||||
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
|
||||
|
||||
use Moodle\BehatExtension\Exception\SkippedException;
|
||||
|
||||
require_once(__DIR__ . '/../../behat/behat_base.php');
|
||||
|
||||
/**
|
||||
* Steps definitions related to MoodleNet.
|
||||
*
|
||||
* @package core
|
||||
* @category test
|
||||
* @copyright 2023 Huong Nguyen <huongnv13@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class behat_moodlenet extends behat_base {
|
||||
|
||||
/**
|
||||
* Check that the TEST_MOODLENET_MOCK_SERVER is defined, so we can connect to the mock server.
|
||||
*
|
||||
* @Given /^a MoodleNet mock server is configured$/
|
||||
*/
|
||||
public function mock_is_configured(): void {
|
||||
if (!defined('TEST_MOODLENET_MOCK_SERVER')) {
|
||||
throw new SkippedException(
|
||||
'The TEST_MOODLENET_MOCK_SERVER constant must be defined to run MoodleNet tests'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the service base url to the TEST_MOODLENET_MOCK_SERVER url.
|
||||
*
|
||||
* @Given /^I change the MoodleNet field "(?P<field_string>(?:[^"]|\\")*)" to mock server$/
|
||||
* @param string $field Field name
|
||||
*/
|
||||
public function change_service_base_url_to_mock_url(string $field): void {
|
||||
$field = behat_field_manager::get_form_field_from_label($field, $this);
|
||||
$field->set_value(TEST_MOODLENET_MOCK_SERVER);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user