mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
Merge branch 'MDL-78750-master-int' of https://github.com/stevandoMoodle/moodle
This commit is contained in:
commit
9739399741
@ -34,4 +34,12 @@ interface communication_provider {
|
||||
* @param processor $communication The communication object
|
||||
*/
|
||||
public static function load_for_instance(processor $communication): self;
|
||||
|
||||
/**
|
||||
* Check if the provider is configured or not.
|
||||
*
|
||||
* This method is intended to check if the plugin have got any settings and if all the settings are set properly.
|
||||
* This checking helps to reduce errors in future when a communication instance is added for the provider and not configured.
|
||||
*/
|
||||
public static function is_configured(): bool;
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ class processor {
|
||||
public static function load_by_id(int $id): ?self {
|
||||
global $DB;
|
||||
$record = $DB->get_record('communication', ['id' => $id]);
|
||||
if ($record && self::is_provider_enabled($record->provider)) {
|
||||
if ($record && self::is_provider_available($record->provider)) {
|
||||
return new self($record);
|
||||
}
|
||||
|
||||
@ -376,7 +376,7 @@ class processor {
|
||||
'instancetype' => $instancetype,
|
||||
]);
|
||||
|
||||
if ($record && self::is_provider_enabled($record->provider)) {
|
||||
if ($record && self::is_provider_available($record->provider)) {
|
||||
return new self($record);
|
||||
}
|
||||
|
||||
@ -671,12 +671,16 @@ class processor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is communication provider enabled/disabled.
|
||||
* Is the communication provider enabled and configured, or disabled.
|
||||
*
|
||||
* @param string $provider provider component name
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_provider_enabled(string $provider): bool {
|
||||
return \core\plugininfo\communication::is_plugin_enabled($provider);
|
||||
public static function is_provider_available(string $provider): bool {
|
||||
if (\core\plugininfo\communication::is_plugin_enabled($provider)) {
|
||||
$providerclass = "{$provider}\\communication_feature";
|
||||
return $providerclass::is_configured();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -170,4 +170,8 @@ class communication_feature implements
|
||||
'addcommunicationoptionshere'
|
||||
), 'addcommunicationoptionshere');
|
||||
}
|
||||
|
||||
public static function is_configured(): bool {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -113,4 +113,14 @@ class communication_feature_test extends \advanced_testcase {
|
||||
|
||||
return $communicationprocessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the selected provider is configured.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_is_configured() {
|
||||
$communicationprocessor = $this->get_test_communication_processor();
|
||||
$this->assertTrue($communicationprocessor->get_form_provider()->is_configured());
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ class communication_feature implements
|
||||
$this->homeserverurl = get_config('communication_matrix', 'matrixhomeserverurl');
|
||||
$this->webclienturl = get_config('communication_matrix', 'matrixelementurl');
|
||||
|
||||
if ($this->homeserverurl) {
|
||||
if ($processor::is_provider_available('communication_matrix')) {
|
||||
// Generate the API instance.
|
||||
$this->matrixapi = matrix_client::instance(
|
||||
serverurl: $this->homeserverurl,
|
||||
@ -751,4 +751,25 @@ class communication_feature implements
|
||||
|
||||
return $powerlevel;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if matrix settings are configured
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function is_configured(): bool {
|
||||
// Matrix communication settings.
|
||||
$matrixhomeserverurl = get_config('communication_matrix', 'matrixhomeserverurl');
|
||||
$matrixaccesstoken = get_config('communication_matrix', 'matrixaccesstoken');
|
||||
$matrixelementurl = get_config('communication_matrix', 'matrixelementurl');
|
||||
|
||||
if (
|
||||
!empty($matrixhomeserverurl) &&
|
||||
!empty($matrixaccesstoken) &&
|
||||
(PHPUNIT_TEST || BEHAT_SITE_RUNNING || !empty($matrixelementurl))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -28,19 +28,14 @@ if ($hassiteconfig) {
|
||||
// Home server URL.
|
||||
$name = new lang_string('matrixhomeserverurl', 'communication_matrix');
|
||||
$desc = new lang_string('matrixhomeserverurl_desc', 'communication_matrix');
|
||||
$settings->add(new admin_setting_requiredtext('communication_matrix/matrixhomeserverurl', $name, $desc, ''));
|
||||
$settings->add(new admin_setting_configtext('communication_matrix/matrixhomeserverurl', $name, $desc, ''));
|
||||
|
||||
// Access token.
|
||||
$name = new lang_string('matrixaccesstoken', 'communication_matrix');
|
||||
$desc = new lang_string('matrixaccesstoken_desc', 'communication_matrix');
|
||||
$settings->add(new admin_setting_requiredpasswordunmask('communication_matrix/matrixaccesstoken', $name, $desc, ''));
|
||||
|
||||
// Refresh token.
|
||||
$name = new lang_string('matrixrefreshtoken', 'communication_matrix');
|
||||
$desc = new lang_string('matrixrefreshtoken_desc', 'communication_matrix');
|
||||
$settings->add(new admin_setting_requiredpasswordunmask('communication_matrix/matrixrefreshtoken', $name, $desc, ''));
|
||||
$settings->add(new admin_setting_configpasswordunmask('communication_matrix/matrixaccesstoken', $name, $desc, ''));
|
||||
|
||||
// Element web URL.
|
||||
$name = new lang_string('matrixelementurl', 'communication_matrix');
|
||||
$settings->add(new admin_setting_requiredtext('communication_matrix/matrixelementurl', $name, '', ''));
|
||||
$settings->add(new admin_setting_configtext('communication_matrix/matrixelementurl', $name, '', ''));
|
||||
}
|
||||
|
@ -539,4 +539,24 @@ class communication_feature_test extends \advanced_testcase {
|
||||
$communication->reload();
|
||||
return $communication;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the selected provider is configured.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_is_configured() {
|
||||
$course = $this->get_course();
|
||||
$communicationprocessor = processor::load_by_instance(
|
||||
component: 'core_course',
|
||||
instancetype: 'coursecommunication',
|
||||
instanceid: $course->id
|
||||
);
|
||||
$this->assertTrue($communicationprocessor->get_room_provider()->is_configured());
|
||||
|
||||
// Unset communication_matrix settings.
|
||||
unset_config('matrixhomeserverurl', 'communication_matrix');
|
||||
unset_config('matrixaccesstoken', 'communication_matrix');
|
||||
$this->assertFalse($communicationprocessor->get_room_provider()->is_configured());
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,6 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'communication_matrix';
|
||||
$plugin->version = 2023090600;
|
||||
$plugin->version = 2023092300;
|
||||
$plugin->requires = 2023011300;
|
||||
$plugin->maturity = MATURITY_ALPHA;
|
||||
|
@ -18,8 +18,11 @@ namespace core_communication;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/../provider/matrix/tests/matrix_test_helper_trait.php');
|
||||
require_once(__DIR__ . '/communication_test_helper_trait.php');
|
||||
|
||||
use \communication_matrix\matrix_test_helper_trait;
|
||||
|
||||
/**
|
||||
* Class api_test to test the communication public api and its associated methods.
|
||||
*
|
||||
@ -30,12 +33,15 @@ require_once(__DIR__ . '/communication_test_helper_trait.php');
|
||||
* @covers \core_communication\api
|
||||
*/
|
||||
class api_test extends \advanced_testcase {
|
||||
|
||||
use matrix_test_helper_trait;
|
||||
use communication_test_helper_trait;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->resetAfterTest();
|
||||
$this->setup_communication_configs();
|
||||
$this->initialise_mock_server();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,8 +18,11 @@ namespace core_communication;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/../provider/matrix/tests/matrix_test_helper_trait.php');
|
||||
require_once(__DIR__ . '/communication_test_helper_trait.php');
|
||||
|
||||
use \communication_matrix\matrix_test_helper_trait;
|
||||
|
||||
/**
|
||||
* Class processor_test to test the communication internal api and its associated methods.
|
||||
*
|
||||
@ -30,8 +33,17 @@ require_once(__DIR__ . '/communication_test_helper_trait.php');
|
||||
* @coversDefaultClass \core_communication\processor
|
||||
*/
|
||||
class processor_test extends \advanced_testcase {
|
||||
|
||||
use matrix_test_helper_trait;
|
||||
use communication_test_helper_trait;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->resetAfterTest();
|
||||
$this->setup_communication_configs();
|
||||
$this->initialise_mock_server();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create instance.
|
||||
*
|
||||
@ -417,18 +429,18 @@ class processor_test extends \advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the provider is enabled or disabled.
|
||||
* Test if the provider is enabled and configured, or disabled.
|
||||
*
|
||||
* @covers ::is_provider_enabled
|
||||
* @covers ::is_provider_available
|
||||
*/
|
||||
public function test_is_provider_enabled(): void {
|
||||
public function test_is_provider_available(): void {
|
||||
$this->resetAfterTest();
|
||||
$communicationprovider = 'communication_matrix';
|
||||
$this->assertTrue(processor::is_provider_enabled($communicationprovider));
|
||||
$this->assertTrue(processor::is_provider_available($communicationprovider));
|
||||
|
||||
// Now test is disabling the plugin returns false.
|
||||
set_config('disabled', 1, $communicationprovider);
|
||||
$this->assertFalse(processor::is_provider_enabled($communicationprovider));
|
||||
$this->assertFalse(processor::is_provider_available($communicationprovider));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user