diff --git a/message/output/airnotifier/classes/manager.php b/message/output/airnotifier/classes/manager.php index 8cf0e8e861bd6..806384886072f 100644 --- a/message/output/airnotifier/classes/manager.php +++ b/message/output/airnotifier/classes/manager.php @@ -235,6 +235,15 @@ public function check_configuration(): array { $results[] = new core\check\result(core\check\result::OK, $summary, get_string('enabled', 'admin')); } + // Check message outputs are not disabled in config.php. + $summary = get_string('noemailevernotset', 'message_airnotifier'); + if (!empty($CFG->noemailever)) { + $results[] = new core\check\result(core\check\result::CRITICAL, $summary, + get_string('noemaileverset', 'message_airnotifier')); + } else { + $results[] = new core\check\result(core\check\result::OK, $summary, get_string('disabled', 'admin')); + } + // Check Mobile notifications enabled. require_once($CFG->dirroot . '/message/lib.php'); $processors = get_message_processors(); diff --git a/message/output/airnotifier/lang/en/message_airnotifier.php b/message/output/airnotifier/lang/en/message_airnotifier.php index bb41e7310f66a..1f1f553639157 100644 --- a/message/output/airnotifier/lang/en/message_airnotifier.php +++ b/message/output/airnotifier/lang/en/message_airnotifier.php @@ -45,6 +45,8 @@ $string['messageproviderslow'] = 'Only a few mobile notifications are enabled in default notification preferences.'; $string['moodleappsportallimitswarning'] = 'Please note that the number of user devices allowed to receive notifications depends on your Moodle app subscription. For details, visit the Moodle Apps Portal.'; $string['nodevices'] = 'No registered devices. Devices will automatically appear after you install the Moodle app and add this site.'; +$string['noemailevernotset'] = '$CFG->noemailever disabled'; +$string['noemaileverset'] = '$CFG->noemailever is enabled in config.php. You need to set this setting to false or remove it.'; $string['nopermissiontomanagedevices'] = 'You don\'t have permission to manage devices.'; $string['notconfigured'] = 'The Airnotifier server has not been configured so push notifications cannot be sent.'; $string['notificationsserverconfiguration'] = 'Notifications server (Airnotifier) configuration'; diff --git a/message/output/airnotifier/tests/manager_test.php b/message/output/airnotifier/tests/manager_test.php index 9d524c36cf83c..778f8155e1404 100644 --- a/message/output/airnotifier/tests/manager_test.php +++ b/message/output/airnotifier/tests/manager_test.php @@ -38,12 +38,13 @@ public function test_check_configuration_default() { $checks = $manager->check_configuration(); $this->assertEquals(core\check\result::OK, $checks[0]->get_status()); // Mobile service enabled. - $this->assertEquals(core\check\result::OK, $checks[1]->get_status()); // Mobile notifications enabled. - $this->assertEquals(core\check\result::ERROR, $checks[2]->get_status()); // Airnotifier NOT configured, missing key. - $this->assertEquals(core\check\result::OK, $checks[3]->get_status()); // Airnotifier URL available. - $this->assertEquals(core\check\result::ERROR, $checks[4]->get_status()); // Missing access key. - $this->assertEquals(core\check\result::WARNING, $checks[5]->get_status()); // Only a few of default mobile notifications. - $this->assertEquals(core\check\result::ERROR, $checks[6]->get_status()); // No registered devices yet. + $this->assertEquals(core\check\result::OK, $checks[1]->get_status()); // Message output not disabled in config.php. + $this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Mobile notifications enabled. + $this->assertEquals(core\check\result::ERROR, $checks[3]->get_status()); // Airnotifier NOT configured, missing key. + $this->assertEquals(core\check\result::OK, $checks[4]->get_status()); // Airnotifier URL available. + $this->assertEquals(core\check\result::ERROR, $checks[5]->get_status()); // Missing access key. + $this->assertEquals(core\check\result::WARNING, $checks[6]->get_status()); // Only a few of default mobile notifications. + $this->assertEquals(core\check\result::ERROR, $checks[7]->get_status()); // No registered devices yet. } /** Test check_configuration with token **/ @@ -61,12 +62,13 @@ public function test_check_configuration_with_token() { $checks = $manager->check_configuration(); $this->assertEquals(core\check\result::OK, $checks[0]->get_status()); // Mobile service enabled. - $this->assertEquals(core\check\result::OK, $checks[1]->get_status()); // Mobile notifications enabled. - $this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Airnotifier configured. - $this->assertEquals(core\check\result::OK, $checks[3]->get_status()); // Airnotifier URL available. + $this->assertEquals(core\check\result::OK, $checks[1]->get_status()); // Message output not disabled in config.php. + $this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Mobile notifications enabled. + $this->assertEquals(core\check\result::OK, $checks[3]->get_status()); // Airnotifier configured. + $this->assertEquals(core\check\result::OK, $checks[4]->get_status()); // Airnotifier URL available. // The original function fourth check (access key valid in the remote Airnotifier server) is not mockable. - $this->assertEquals(core\check\result::WARNING, $checks[4]->get_status()); // Only a few of default mobile notifications. - $this->assertEquals(core\check\result::ERROR, $checks[5]->get_status()); // No registered devices yet. + $this->assertEquals(core\check\result::WARNING, $checks[5]->get_status()); // Only a few of default mobile notifications. + $this->assertEquals(core\check\result::ERROR, $checks[6]->get_status()); // No registered devices yet. } /** Test check_configuration bad settings **/ @@ -82,16 +84,19 @@ public function test_check_configuration_incorrect_settings() { curl::mock_response(json_encode(['error' => 'Invalid access key'])); // Mock second request to check acces key. $CFG->airnotifieraccesskey = 'test'; // For enabling Airnotifier. $CFG->airnotifierappname .= ' '; + + $CFG->noemailever = true; $checks = $manager->check_configuration(); $this->assertEquals(core\check\result::OK, $checks[0]->get_status()); // Mobile service enabled. - $this->assertEquals(core\check\result::OK, $checks[1]->get_status()); // Mobile notifications enabled. - $this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Airnotifier configured. - $this->assertEquals(core\check\result::ERROR, $checks[3]->get_status()); // Airnotifier URL available. - $this->assertEquals(core\check\result::OK, $checks[4]->get_status()); // Invalid setting (empty space). + $this->assertEquals(core\check\result::CRITICAL, $checks[1]->get_status()); // Message output disabled in config.php. + $this->assertEquals(core\check\result::OK, $checks[2]->get_status()); // Mobile notifications enabled. + $this->assertEquals(core\check\result::OK, $checks[3]->get_status()); // Airnotifier configured. + $this->assertEquals(core\check\result::ERROR, $checks[4]->get_status()); // Airnotifier URL available. + $this->assertEquals(core\check\result::OK, $checks[5]->get_status()); // Invalid setting (empty space). // The original function fifth check (access key valid in the remote Airnotifier server) is not mockable. - $this->assertEquals(core\check\result::WARNING, $checks[5]->get_status()); // Only a few of default mobile notifications. - $this->assertEquals(core\check\result::ERROR, $checks[6]->get_status()); // No registered devices yet. + $this->assertEquals(core\check\result::WARNING, $checks[6]->get_status()); // Only a few of default mobile notifications. + $this->assertEquals(core\check\result::ERROR, $checks[7]->get_status()); // No registered devices yet. } /** Test has_enabled_devices **/