first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+166
View File
@@ -0,0 +1,166 @@
<?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/>.
/**
* MNet hosts block.
*
* @package block_mnet_hosts
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_mnet_hosts extends block_list {
function init() {
$this->title = get_string('pluginname','block_mnet_hosts') ;
}
function has_config() {
return false;
}
function applicable_formats() {
if (has_capability('moodle/site:mnetlogintoremote', context_system::instance(), NULL, false)) {
return array('all' => true, 'mod' => false, 'tag' => false);
} else {
return array('site' => true);
}
}
function get_content() {
global $CFG, $USER, $DB, $OUTPUT;
// shortcut - only for logged in users!
if (!isloggedin() || isguestuser()) {
return false;
}
if (\core\session\manager::is_loggedinas()) {
$this->content = new stdClass();
$this->content->footer = html_writer::tag('span',
get_string('notpermittedtojumpas', 'mnet'));
return $this->content;
}
// according to start_jump_session,
// remote users can't on-jump
// so don't show this block to them
if (is_mnet_remote_user($USER)) {
if (debugging() and !empty($CFG->debugdisplay)) {
$this->content = new stdClass();
$this->content->footer = html_writer::tag('span',
get_string('error_localusersonly', 'block_mnet_hosts'),
array('class' => 'error'));
return $this->content;
} else {
return '';
}
}
if (!is_enabled_auth('mnet')) {
if (debugging() and !empty($CFG->debugdisplay)) {
$this->content = new stdClass();
$this->content->footer = html_writer::tag('span',
get_string('error_authmnetneeded', 'block_mnet_hosts'),
array('class' => 'error'));
return $this->content;
} else {
return '';
}
}
if (!has_capability('moodle/site:mnetlogintoremote', context_system::instance(), NULL, false)) {
if (debugging() and !empty($CFG->debugdisplay)) {
$this->content = new stdClass();
$this->content->footer = html_writer::tag('span',
get_string('error_roamcapabilityneeded', 'block_mnet_hosts'),
array('class' => 'error'));
return $this->content;
} else {
return '';
}
}
if ($this->content !== NULL) {
return $this->content;
}
// TODO: Test this query - it's appropriate? It works?
// get the hosts and whether we are doing SSO with them
$sql = "
SELECT DISTINCT
h.id,
h.name,
h.wwwroot,
a.name as application,
a.display_name
FROM
{mnet_host} h,
{mnet_application} a,
{mnet_host2service} h2s_IDP,
{mnet_service} s_IDP,
{mnet_host2service} h2s_SP,
{mnet_service} s_SP
WHERE
h.id <> ? AND
h.id <> ? AND
h.id = h2s_IDP.hostid AND
h.deleted = 0 AND
h.applicationid = a.id AND
h2s_IDP.serviceid = s_IDP.id AND
s_IDP.name = 'sso_idp' AND
h2s_IDP.publish = '1' AND
h.id = h2s_SP.hostid AND
h2s_SP.serviceid = s_SP.id AND
s_SP.name = 'sso_idp' AND
h2s_SP.publish = '1'
ORDER BY
a.display_name,
h.name";
$hosts = $DB->get_records_sql($sql, array($CFG->mnet_localhost_id, $CFG->mnet_all_hosts_id));
$this->content = new stdClass();
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
if ($hosts) {
foreach ($hosts as $host) {
if ($host->id == $USER->mnethostid) {
$url = new \moodle_url($host->wwwroot);
} else {
$url = new \moodle_url('/auth/mnet/jump.php', array('hostid' => $host->id));
}
$this->content->items[] = html_writer::tag('a',
$OUTPUT->pix_icon("i/{$host->application}_host", get_string('server', 'block_mnet_hosts')) . s($host->name),
array('href' => $url->out(), 'title' => s($host->name))
);
}
}
return $this->content;
}
/**
* This block shouldn't be added to a page if the mnet authentication method is disabled.
*
* @param moodle_page $page
* @return bool
*/
public function can_block_be_added(moodle_page $page): bool {
return is_enabled_auth('mnet');
}
}
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for block_mnet_hosts.
*
* @package block_mnet_hosts
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_mnet_hosts\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for block_mnet_hosts implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+51
View File
@@ -0,0 +1,51 @@
<?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/>.
/**
* Mnet hosts block caps.
*
* @package block_mnet_hosts
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'block/mnet_hosts:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/mnet_hosts:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
@@ -0,0 +1,32 @@
<?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/>.
/**
* Strings for component 'block_mnet_hosts', language 'en', branch 'MOODLE_20_STABLE'
*
* @package block_mnet_hosts
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['error_authmnetneeded'] = 'MNet authentication plugin must be enabled to see the list of MNet network servers';
$string['error_localusersonly'] = 'Remote users can not jump to other MNet network servers from this host';
$string['error_roamcapabilityneeded'] = 'Users need the capability \'Roam to a remote application via MNet\' to see the list of MNet network servers';
$string['mnet_hosts:addinstance'] = 'Add a new network servers block';
$string['mnet_hosts:myaddinstance'] = 'Add a new network servers block to Dashboard';
$string['pluginname'] = 'Network servers';
$string['server'] = 'Server';
$string['privacy:metadata'] = 'The Network servers block only allows interaction with Network servers and neither stores or exports data itself.';
@@ -0,0 +1,21 @@
@block @block_mnet_hosts @javascript @addablocklink
Feature: Add the network servers block when main feature is enabled
In order to add the Network servers block to my course
As a teacher
It should be added only if the MNet authentication is enabled.
Scenario: The network servers block can be added when mnet authentication is enabled
Given I log in as "admin"
And I navigate to "Plugins > Authentication > Manage authentication" in site administration
And I click on "Enable" "icon" in the "MNet authentication" "table_row"
And I am on site homepage
And I turn editing mode on
When I click on "Add a block" "link"
Then I should see "Network servers"
Scenario: The network servers block cannot be added when mnet authentication is disabled
Given I log in as "admin"
And I am on site homepage
And I turn editing mode on
When I click on "Add a block" "link"
Then I should not see "Network servers"
@@ -0,0 +1,42 @@
@block @block_mnet_hosts @javascript
Feature: Add the network servers block when main feature is disabled
In order to add the Network servers block to my course
As a teacher
It should be added only if the MNet authentication is enabled.
Scenario: The network servers block is displayed even when mnet authentication is disabled
Given I log in as "admin"
And I navigate to "Plugins > Authentication > Manage authentication" in site administration
And I click on "Enable" "icon" in the "MNet authentication" "table_row"
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| mnet_hosts | System | 1 | site-index | side-pre |
When I navigate to "Plugins > Authentication > Manage authentication" in site administration
And I click on "Disable" "icon" in the "MNet authentication" "table_row"
And I am on site homepage
And I turn editing mode on
Then I should see "Network servers"
Scenario: The network servers block can be removed even when mnet authentication is disabled
Given I log in as "admin"
And I navigate to "Plugins > Authentication > Manage authentication" in site administration
And I click on "Enable" "icon" in the "MNet authentication" "table_row"
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| mnet_hosts | System | 1 | site-index | side-pre |
And I am on site homepage
And I turn editing mode on
And I open the "Network servers" blocks action menu
And I click on "Delete Network servers block" "link" in the "Network servers" "block"
And "Delete block?" "dialogue" should exist
And I click on "Cancel" "button" in the "Delete block?" "dialogue"
And I should see "Network servers"
And I navigate to "Plugins > Authentication > Manage authentication" in site administration
And I click on "Disable" "icon" in the "MNet authentication" "table_row"
And I am on site homepage
And I turn editing mode on
And I open the "Network servers" blocks action menu
And I click on "Delete Network servers block" "link" in the "Network servers" "block"
And "Delete block?" "dialogue" should exist
And I click on "Delete" "button" in the "Delete block?" "dialogue"
Then I should not see "Network servers"
@@ -0,0 +1,64 @@
<?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/>.
namespace block_mnet_hosts;
use advanced_testcase;
use block_mnet_hosts;
use context_course;
/**
* PHPUnit block_mnet_hosts tests
*
* @package block_mnet_hosts
* @category test
* @copyright 2021 Sara Arjona (sara@moodle.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \block_mnet_hosts
*/
class mnet_hosts_test extends advanced_testcase {
public static function setUpBeforeClass(): void {
require_once(__DIR__ . '/../../moodleblock.class.php');
require_once(__DIR__ . '/../block_mnet_hosts.php');
}
/**
* Test the behaviour of can_block_be_added() method.
*
* @covers ::can_block_be_added
*/
public function test_can_block_be_added(): void {
$this->resetAfterTest();
$this->setAdminUser();
// Create a course and prepare the page where the block will be added.
$course = $this->getDataGenerator()->create_course();
$page = new \moodle_page();
$page->set_context(context_course::instance($course->id));
$page->set_pagelayout('course');
$block = new block_mnet_hosts();
$pluginclass = \core_plugin_manager::resolve_plugininfo_class('auth');
// If mnet authentication is enabled, the method should return true.
$pluginclass::enable_plugin('mnet', 1);
$this->assertTrue($block->can_block_be_added($page));
// However, if the mnet authentication is disabled, the method should return false.
$pluginclass::enable_plugin('mnet', 0);
$this->assertFalse($block->can_block_be_added($page));
}
}
+29
View File
@@ -0,0 +1,29 @@
<?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/>.
/**
* Version details
*
* @package block_mnet_hosts
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'block_mnet_hosts'; // Full name of the plugin (used for diagnostics)