From 4d726630b11ba377d029942ad1fb5701066b0a9d Mon Sep 17 00:00:00 2001 From: Laurent David Date: Tue, 1 Feb 2022 15:39:31 +0100 Subject: [PATCH] MDL-73279 mod_bigbluebuttonbn: Remove notify change option in settings * As 'Send content change notification' is standard in all activities in Moodle 4.0 we should be removing 'Notify this change to users enrolled' * Fix and adjust tests --- mod/bigbluebuttonbn/classes/local/config.php | 2 - .../classes/local/helpers/mod_helper.php | 22 ---- .../classes/setting_validator.php | 10 -- mod/bigbluebuttonbn/classes/settings.php | 35 ----- .../send_instance_update_notification.php | 124 ------------------ .../lang/en/bigbluebuttonbn.php | 10 -- mod/bigbluebuttonbn/mod_form.php | 6 - .../local/helpers/mod_helper_trait_test.php | 38 ++++-- ...send_instance_update_notification_test.php | 106 --------------- 9 files changed, 29 insertions(+), 324 deletions(-) delete mode 100644 mod/bigbluebuttonbn/classes/task/send_instance_update_notification.php delete mode 100644 mod/bigbluebuttonbn/tests/task/send_instance_update_notification_test.php diff --git a/mod/bigbluebuttonbn/classes/local/config.php b/mod/bigbluebuttonbn/classes/local/config.php index ffcca2ea013..ae4dfba9dfb 100644 --- a/mod/bigbluebuttonbn/classes/local/config.php +++ b/mod/bigbluebuttonbn/classes/local/config.php @@ -65,7 +65,6 @@ class config { 'userlimit_default' => '0', 'userlimit_editable' => false, 'preuploadpresentation_enabled' => false, - 'sendnotifications_enabled' => false, 'recordingready_enabled' => false, 'recordingstatus_enabled' => false, 'meetingevents_enabled' => false, @@ -182,7 +181,6 @@ class config { 'userlimit_default' => self::get('userlimit_default'), 'userlimit_editable' => self::get('userlimit_editable'), 'preuploadpresentation_enabled' => self::get('preuploadpresentation_enabled'), - 'sendnotifications_enabled' => self::get('sendnotifications_enabled'), 'recordings_enabled' => self::get('recordings_enabled'), 'meetingevents_enabled' => self::get('meetingevents_enabled'), 'recordings_deleted_default' => self::get('recordings_deleted_default'), diff --git a/mod/bigbluebuttonbn/classes/local/helpers/mod_helper.php b/mod/bigbluebuttonbn/classes/local/helpers/mod_helper.php index 427209f2269..371b9c9f83b 100644 --- a/mod/bigbluebuttonbn/classes/local/helpers/mod_helper.php +++ b/mod/bigbluebuttonbn/classes/local/helpers/mod_helper.php @@ -20,7 +20,6 @@ use calendar_event; use mod_bigbluebuttonbn\instance; use mod_bigbluebuttonbn\logger; use mod_bigbluebuttonbn\plugin; -use mod_bigbluebuttonbn\task\send_instance_update_notification; use stdClass; /** @@ -143,31 +142,10 @@ class mod_helper { * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data **/ public static function process_post_save(stdClass $bigbluebuttonbn): void { - if (isset($bigbluebuttonbn->notification) && $bigbluebuttonbn->notification) { - self::process_post_save_notification($bigbluebuttonbn); - } self::process_post_save_event($bigbluebuttonbn); self::process_post_save_completion($bigbluebuttonbn); } - /** - * Generates a message on insert/update which is sent to all users enrolled. - * - * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data - **/ - protected static function process_post_save_notification(stdClass $bigbluebuttonbn): void { - $task = new send_instance_update_notification(); - $task->set_instance_id($bigbluebuttonbn->id); - - if (isset($bigbluebuttonbn->add) && !empty($bigbluebuttonbn->add)) { - $task->set_update_type(send_instance_update_notification::TYPE_CREATED); - } else { - $task->set_update_type(send_instance_update_notification::TYPE_UPDATED); - } - - \core\task\manager::queue_adhoc_task($task); - } - /** * Generates an event after a bigbluebuttonbn insert/update. * diff --git a/mod/bigbluebuttonbn/classes/setting_validator.php b/mod/bigbluebuttonbn/classes/setting_validator.php index 584742c9239..8dd80c2c420 100644 --- a/mod/bigbluebuttonbn/classes/setting_validator.php +++ b/mod/bigbluebuttonbn/classes/setting_validator.php @@ -139,16 +139,6 @@ class setting_validator { return (!isset($CFG->bigbluebuttonbn['participant_moderator_default'])); } - /** - * Validate if send notification section will be shown. - * - * @return bool - */ - public static function section_send_notifications_shown() { - global $CFG; - return (!isset($CFG->bigbluebuttonbn['sendnotifications_enabled'])); - } - /** * Validate if settings extended section will be shown. * diff --git a/mod/bigbluebuttonbn/classes/settings.php b/mod/bigbluebuttonbn/classes/settings.php index a80d125ce2d..b5f81b22379 100644 --- a/mod/bigbluebuttonbn/classes/settings.php +++ b/mod/bigbluebuttonbn/classes/settings.php @@ -96,7 +96,6 @@ class settings { $this->add_preupload_settings(); $this->add_userlimit_settings(); $this->add_participants_settings(); - $this->add_notifications_settings(); $this->add_muteonstart_settings(); $this->add_locksettings_settings(); // Renders settings for extended capabilities. @@ -712,40 +711,6 @@ class settings { $this->admin->add($this->section, $participantsettings); } - /** - * Helper function renders notification settings if the feature is enabled. - */ - protected function add_notifications_settings(): void { - // Configuration for "send notifications" feature. - $notificationssettings = new admin_settingpage( - "{$this->sectionnameprefix}_notifications", - get_string('config_sendnotifications', 'bigbluebuttonbn'), - 'moodle/site:config', - !((boolean) setting_validator::section_send_notifications_shown()) && ($this->moduleenabled) - ); - - if ($this->admin->fulltree) { - $item = new admin_setting_heading( - 'bigbluebuttonbn_config_sendnotifications', - '', - get_string('config_sendnotifications_description', 'bigbluebuttonbn') - ); - $notificationssettings->add($item); - $item = new admin_setting_configcheckbox( - 'bigbluebuttonbn_sendnotifications_enabled', - get_string('config_sendnotifications_enabled', 'bigbluebuttonbn'), - get_string('config_sendnotifications_enabled_description', 'bigbluebuttonbn'), - 1 - ); - $this->add_conditional_element( - 'sendnotifications_enabled', - $item, - $notificationssettings - ); - } - $this->admin->add($this->section, $notificationssettings); - } - /** * Helper function renders general settings if the feature is enabled. */ diff --git a/mod/bigbluebuttonbn/classes/task/send_instance_update_notification.php b/mod/bigbluebuttonbn/classes/task/send_instance_update_notification.php deleted file mode 100644 index 155f9940377..00000000000 --- a/mod/bigbluebuttonbn/classes/task/send_instance_update_notification.php +++ /dev/null @@ -1,124 +0,0 @@ -. - -namespace mod_bigbluebuttonbn\task; - -use core\task\adhoc_task; -use mod_bigbluebuttonbn\output\instance_updated_message; - -/** - * Class containing the adhoc task to send the notification that an update was updated. - * - * @package mod_bigbluebuttonbn - * @copyright 2021 Andrew Lyons - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class send_instance_update_notification extends send_notification { - - /** @var int The activity was created */ - const TYPE_CREATED = 0; - - /** @var int The activity was updated */ - const TYPE_UPDATED = 1; - - /** - * Set the update type. - * - * @param int $type - */ - public function set_update_type(int $type): void { - $this->append_custom_data(['type' => $type]); - } - - /** - * Get the type of update. - * - * @return null|int - */ - protected function get_update_type(): ?int { - $data = (object) $this->get_custom_data(); - if (property_exists($data, 'type')) { - return $data->type; - } - - return self::TYPE_UPDATED; - } - - /** - * Get the notification type. - * - * @return string - */ - protected function get_notification_type(): string { - return 'instance_updated'; - } - - /** - * Get the subject of the notification. - * - * @return string - */ - protected function get_subject(): string { - $instance = $this->get_instance(); - - if ($this->get_update_type() == self::TYPE_CREATED) { - $key = 'notification_instance_created_subject'; - } else { - $key = 'notification_instance_updated_subject'; - } - return get_string($key, 'mod_bigbluebuttonbn', $this->get_string_vars()); - } - - /** - * Get the HTML message content. - * - * @return string - */ - protected function get_html_message(): string { - global $PAGE; - - $renderer = $PAGE->get_renderer('mod_bigbluebuttonbn', '', RENDERER_TARGET_HTMLEMAIL); - return $renderer->render(new instance_updated_message($this->instance, $this->get_update_type())); - } - - /** - * Get the short summary message. - * - * @return string - */ - protected function get_small_message(): string { - if ($this->get_update_type() == self::TYPE_CREATED) { - $key = 'notification_instance_created_small'; - } else { - $key = 'notification_instance_updated_small'; - } - return get_string($key, 'mod_bigbluebuttonbn', $this->get_string_vars()); - } - - /** - * Get variables to make available to strings. - * - * @return array - */ - protected function get_string_vars(): array { - return [ - 'course_fullname' => $this->instance->get_course()->fullname, - 'course_shortname' => $this->instance->get_course()->shortname, - 'name' => $this->instance->get_cm()->name, - 'link' => $this->instance->get_view_url()->out(), - ]; - } -} diff --git a/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php b/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php index 7d7811a01b3..988914de4fc 100644 --- a/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php +++ b/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php @@ -219,11 +219,6 @@ $string['config_scheduled_description'] = 'These settings define some of the beh $string['config_scheduled_pre_opening'] = 'Accessible before opening time (minutes)'; $string['config_scheduled_pre_opening_description'] = 'The time in minutes for the session to be acceessible before the schedules opening time is due.'; -$string['config_sendnotifications'] = 'Configuration for "Send notifications" feature'; -$string['config_sendnotifications_description'] = 'These settings enable or disable options in the UI and also define default values for these options.'; -$string['config_sendnotifications_enabled'] = 'Send notifications enabled'; -$string['config_sendnotifications_enabled_description'] = 'If enabled the UI for editing the activity includes an option for sending a notification to enrolled user when the activity is added or updated.'; - $string['config_extended_capabilities'] = 'Configuration for extended capabilities'; $string['config_extended_capabilities_description'] = 'Configuration for extended capabilities when the BigBlueButton server offers them.'; $string['config_uidelegation_enabled'] = 'UI delegation is enabled'; @@ -364,11 +359,6 @@ $string['mod_form_field_participant_bbb_role_viewer'] = 'Viewer'; $string['mod_form_field_instanceprofiles'] = 'Instance type'; $string['mod_form_field_instanceprofiles_help'] = 'Select the type for this BigBlueButton instance.'; $string['mod_form_field_muteonstart'] = 'Mute on start'; -$string['mod_form_field_notification'] = 'Notify this change to users enrolled'; -$string['mod_form_field_notification_help'] = 'Send a notification to all users enrolled to let them know that this activity has been added or updated'; -$string['mod_form_field_notification_created_help'] = 'Send a notification to all users enrolled to let them know that this activity has been created'; -$string['mod_form_field_notification_modified_help'] = 'Send a notification to all users enrolled to let them know that this activity has been updated'; -$string['mod_form_field_notification_msg_at'] = 'at'; $string['mod_form_field_recordings_html'] = 'Show the table in plain html'; $string['mod_form_field_recordings_deleted'] = 'Include recordings from deleted activities'; $string['mod_form_field_recordings_imported'] = 'Show only imported links'; diff --git a/mod/bigbluebuttonbn/mod_form.php b/mod/bigbluebuttonbn/mod_form.php index 9be734e3a6a..cff94b2be79 100644 --- a/mod/bigbluebuttonbn/mod_form.php +++ b/mod/bigbluebuttonbn/mod_form.php @@ -307,12 +307,6 @@ class mod_bigbluebuttonbn_mod_form extends moodleform_mod { $this->standard_intro_elements(get_string('mod_form_field_intro', 'bigbluebuttonbn')); $mform->setAdvanced('introeditor'); $mform->setAdvanced('showdescription'); - if ($cfg['sendnotifications_enabled']) { - $field = ['type' => 'checkbox', 'name' => 'notification', 'data_type' => PARAM_INT, - 'description_key' => 'mod_form_field_notification']; - $this->bigbluebuttonbn_mform_add_element($mform, $field['type'], $field['name'], $field['data_type'], - $field['description_key'], 0); - } } /** diff --git a/mod/bigbluebuttonbn/tests/local/helpers/mod_helper_trait_test.php b/mod/bigbluebuttonbn/tests/local/helpers/mod_helper_trait_test.php index 7294efd708b..2d2f7a28f4c 100644 --- a/mod/bigbluebuttonbn/tests/local/helpers/mod_helper_trait_test.php +++ b/mod/bigbluebuttonbn/tests/local/helpers/mod_helper_trait_test.php @@ -114,14 +114,18 @@ class mod_helper_trait_test extends \advanced_testcase { $generator->enrol_user($teacher->id, $this->get_course()->id); // Mark the form to trigger notification. - $bbformdata->notification = true; + $bbformdata->coursecontentnotification = true; + $bbformdata->update = false; $messagesink = $this->redirectMessages(); mod_helper::process_post_save($bbformdata); + edit_module_post_actions($bbformdata, $this->course); // Now run cron. ob_start(); $this->runAdhocTasks(); ob_get_clean(); // Suppress output as it can fail the test. $this->assertEquals(1, $messagesink->count()); + $firstmessage = $messagesink->get_messages()[0]; + $this->assertStringContainsString('is new in', $firstmessage->smallmessage); } /** @@ -135,19 +139,21 @@ class mod_helper_trait_test extends \advanced_testcase { $this->create_instance(null, ['type' => instance::TYPE_RECORDING_ONLY]); $bbformdata = $this->get_form_data_from_instance($bbactivity); - $bbformdata->add = "1"; - + $bbformdata->update = false; $messagesink = $this->redirectMessages(); // Enrol users in a course so he will receive the message. $teacher = $generator->create_user(['role' => 'editingteacher']); $generator->enrol_user($teacher->id, $this->get_course()->id); - $bbformdata->notification = true; + $bbformdata->coursecontentnotification = true; mod_helper::process_post_save($bbformdata); + edit_module_post_actions($bbformdata, $this->course); // Now run cron. ob_start(); $this->runAdhocTasks(); ob_get_clean(); // Suppress output as it can fail the test. $this->assertEquals(1, $messagesink->count()); + $firstmessage = $messagesink->get_messages()[0]; + $this->assertStringContainsString('is new in', $firstmessage->smallmessage); } /** @@ -170,20 +176,34 @@ class mod_helper_trait_test extends \advanced_testcase { $bbformdata->openingtime = time() - 1000; $bbformdata->closing = time() + 1000; // Enrol users in a course so he will receive the message. - $teacher = $generator->create_user(['role' => 'editingteacher']); - $generator->enrol_user($teacher->id, $this->get_course()->id); - + $teacher = $generator->create_user(); + $generator->enrol_user($teacher->id, $this->get_course()->id, 'editingteacher'); + $this->setUser($teacher); // Mark the form to trigger notification. - $bbformdata->notification = true; + $bbformdata->coursecontentnotification = true; + $bbformdata->update = false; $messagesink = $this->redirectMessages(); mod_helper::process_post_save($bbformdata); + edit_module_post_actions($bbformdata, $this->course); // Now run cron. ob_start(); $this->runAdhocTasks(); ob_get_clean(); // Suppress output as it can fail the test. $this->assertEquals(1, $messagesink->count()); - // Do it a again, so we check we still have one event of type EVENT_MEETING_START. + $firstmessage = $messagesink->get_messages()[0]; + $this->assertStringContainsString('is new in', $firstmessage->smallmessage); + $messagesink->clear(); + // Do it a again, so we check we still have one event. mod_helper::process_post_save($bbformdata); + // Mark the form to trigger notification. + $bbformdata->update = true; + edit_module_post_actions($bbformdata, $this->course); + // Now run cron. + ob_start(); + $this->runAdhocTasks(); + ob_get_clean(); // Suppress output as it can fail the test. $this->assertEquals(1, $messagesink->count()); + $firstmessage = $messagesink->get_messages()[0]; + $this->assertStringContainsString('has been changed', $firstmessage->smallmessage); } } diff --git a/mod/bigbluebuttonbn/tests/task/send_instance_update_notification_test.php b/mod/bigbluebuttonbn/tests/task/send_instance_update_notification_test.php deleted file mode 100644 index 77ce8c9af88..00000000000 --- a/mod/bigbluebuttonbn/tests/task/send_instance_update_notification_test.php +++ /dev/null @@ -1,106 +0,0 @@ -. - -namespace mod_bigbluebuttonbn\task; - -use advanced_testcase; - -/** - * Class containing the scheduled task for lti module. - * - * @package mod_bigbluebuttonbn - * @copyright 2019 onwards, Blindside Networks Inc - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @coversDefaultClass \mod_bigbluebuttonbn\task\send_notification - * @covers \mod_bigbluebuttonbn\task\send_notification - * @covers \mod_bigbluebuttonbn\task\send_instance_update_notification - */ -class send_instance_update_notification_test extends advanced_testcase { - /** - * Test the sending of messages. - * - * @dataProvider update_type_provider - * @param int $type - */ - public function test_recipients(int $type): void { - $this->resetAfterTest(); - $this->preventResetByRollback(); - - $generator = $this->getDataGenerator(); - $course = $generator->create_course(); - $instancedata = $generator->create_module('bigbluebuttonbn', [ - 'course' => $course->id, - ]); - - // Create some users in the course, and some not. - $editingteacher = $generator->create_and_enrol($course, 'editingteacher'); - $teacher = $generator->create_and_enrol($course, 'teacher'); - $students = [ - $generator->create_and_enrol($course, 'student'), - $generator->create_and_enrol($course, 'student'), - $generator->create_and_enrol($course, 'student'), - $generator->create_and_enrol($course, 'student'), - $generator->create_and_enrol($course, 'student'), - ]; - - $recipients = array_map(function($user) { - return $user->id; - }, $students); - $recipients[] = $editingteacher->id; - $recipients[] = $teacher->id; - - $unrelateduser = $generator->create_user(); - - $stub = $this->getMockBuilder(send_instance_update_notification::class) - ->onlyMethods([]) - ->getMock(); - $stub->set_update_type($type); - - $instancedata = $generator->create_module('bigbluebuttonbn', [ - 'course' => $course->id, - ]); - - $stub->set_instance_id($instancedata->id); - - // Capture events. - $sink = $this->redirectMessages(); - - // Now execute. - $stub->execute(); - - // Check the events. - $messages = $sink->get_messages(); - $this->assertCount(7, $messages); - - foreach ($messages as $message) { - $this->assertNotFalse(array_search($message->useridto, $recipients)); - $this->assertNotEquals($unrelateduser->id, $message->useridto); - $this->assertEquals($editingteacher->id, $message->useridfrom); - } - } - - /** - * Provider to provide a list of update types. - * - * @return array - */ - public function update_type_provider(): array { - return [ - [send_instance_update_notification::TYPE_CREATED], - [send_instance_update_notification::TYPE_UPDATED], - ]; - } -}