diff --git a/communication/classes/processor.php b/communication/classes/processor.php index a0532787e2c..b8d806a396f 100644 --- a/communication/classes/processor.php +++ b/communication/classes/processor.php @@ -51,9 +51,6 @@ class processor { private stdClass $instancedata, ) { $providercomponent = $this->instancedata->provider; - if (!\core\plugininfo\communication::is_plugin_enabled($providercomponent)) { - throw new \moodle_exception('communicationproviderdisabled', 'core_communication', '', $providercomponent); - } $providerclass = $this->get_classname_for_provider($providercomponent); if (!class_exists($providerclass)) { throw new \moodle_exception('communicationproviderclassnotfound', 'core_communication', '', $providerclass); @@ -329,8 +326,8 @@ class processor { */ public static function load_by_id(int $id): ?self { global $DB; - - if ($record = $DB->get_record('communication', ['id' => $id])) { + $record = $DB->get_record('communication', ['id' => $id]); + if ($record && self::is_provider_enabled($record->provider)) { return new self($record); } @@ -359,7 +356,7 @@ class processor { 'instancetype' => $instancetype, ]); - if ($record) { + if ($record && self::is_provider_enabled($record->provider)) { return new self($record); } @@ -600,4 +597,14 @@ class processor { } return null; } + + /** + * Is communication provider enabled/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); + } } diff --git a/communication/provider/matrix/tests/behat/matrix_room_banner.feature b/communication/provider/matrix/tests/behat/matrix_room_banner.feature index 822dc20297c..8ce09191bff 100644 --- a/communication/provider/matrix/tests/behat/matrix_room_banner.feature +++ b/communication/provider/matrix/tests/behat/matrix_room_banner.feature @@ -34,3 +34,19 @@ Feature: Display communication room status banner # Not for students to see. When I am on the "Test course" "Course" page logged in as "student1" Then I should not see "Your Matrix room is ready!" in the "page-content" "region" + + Scenario: Enabling or disabling the matrix plugin hides the banner accordingly + Given I am on the "Test course" "Course" page logged in as "teacher1" + Then I should see "Your Matrix room will be ready soon." in the "page-content" "region" + When I log in as "admin" + And I navigate to "Plugins > Communication > Manage communication providers" in site administration + And I should see "Matrix" + And I click on "Disable" "link" in the "Matrix" "table_row" + And I am on the "Test course" "Course" page logged in as "teacher1" + And I should not see "Your Matrix room will be ready soon." in the "page-content" "region" + And I log in as "admin" + And I navigate to "Plugins > Communication > Manage communication providers" in site administration + And I should see "Matrix" + And I click on "Enable" "link" in the "Matrix" "table_row" + And I am on the "Test course" "Course" page logged in as "teacher1" + Then I should see "Your Matrix room will be ready soon." in the "page-content" "region" diff --git a/communication/tests/processor_test.php b/communication/tests/processor_test.php index eb3263fbe65..9c88a6bb38b 100644 --- a/communication/tests/processor_test.php +++ b/communication/tests/processor_test.php @@ -395,4 +395,19 @@ class processor_test extends \advanced_testcase { $this->assertEquals($avatar->get_filepath(), '/'); $this->assertEquals($avatar->get_filearea(), 'avatar'); } + + /** + * Test if the provider is enabled or disabled. + * + * @covers ::is_provider_enabled + */ + public function test_is_provider_enabled(): void { + $this->resetAfterTest(); + $communicationprovider = 'communication_matrix'; + $this->assertTrue(processor::is_provider_enabled($communicationprovider)); + + // Now test is disabling the plugin returns false. + set_config('disabled', 1, $communicationprovider); + $this->assertFalse(processor::is_provider_enabled($communicationprovider)); + } }