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
This commit is contained in:
Laurent David 2022-02-01 15:39:31 +01:00
parent 4f9a539600
commit 4d726630b1
9 changed files with 29 additions and 324 deletions

View File

@ -65,7 +65,6 @@ class config {
'userlimit_default' => '0', 'userlimit_default' => '0',
'userlimit_editable' => false, 'userlimit_editable' => false,
'preuploadpresentation_enabled' => false, 'preuploadpresentation_enabled' => false,
'sendnotifications_enabled' => false,
'recordingready_enabled' => false, 'recordingready_enabled' => false,
'recordingstatus_enabled' => false, 'recordingstatus_enabled' => false,
'meetingevents_enabled' => false, 'meetingevents_enabled' => false,
@ -182,7 +181,6 @@ class config {
'userlimit_default' => self::get('userlimit_default'), 'userlimit_default' => self::get('userlimit_default'),
'userlimit_editable' => self::get('userlimit_editable'), 'userlimit_editable' => self::get('userlimit_editable'),
'preuploadpresentation_enabled' => self::get('preuploadpresentation_enabled'), 'preuploadpresentation_enabled' => self::get('preuploadpresentation_enabled'),
'sendnotifications_enabled' => self::get('sendnotifications_enabled'),
'recordings_enabled' => self::get('recordings_enabled'), 'recordings_enabled' => self::get('recordings_enabled'),
'meetingevents_enabled' => self::get('meetingevents_enabled'), 'meetingevents_enabled' => self::get('meetingevents_enabled'),
'recordings_deleted_default' => self::get('recordings_deleted_default'), 'recordings_deleted_default' => self::get('recordings_deleted_default'),

View File

@ -20,7 +20,6 @@ use calendar_event;
use mod_bigbluebuttonbn\instance; use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\logger; use mod_bigbluebuttonbn\logger;
use mod_bigbluebuttonbn\plugin; use mod_bigbluebuttonbn\plugin;
use mod_bigbluebuttonbn\task\send_instance_update_notification;
use stdClass; use stdClass;
/** /**
@ -143,31 +142,10 @@ class mod_helper {
* @param stdClass $bigbluebuttonbn BigBlueButtonBN form data * @param stdClass $bigbluebuttonbn BigBlueButtonBN form data
**/ **/
public static function process_post_save(stdClass $bigbluebuttonbn): void { 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_event($bigbluebuttonbn);
self::process_post_save_completion($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. * Generates an event after a bigbluebuttonbn insert/update.
* *

View File

@ -139,16 +139,6 @@ class setting_validator {
return (!isset($CFG->bigbluebuttonbn['participant_moderator_default'])); 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. * Validate if settings extended section will be shown.
* *

View File

@ -96,7 +96,6 @@ class settings {
$this->add_preupload_settings(); $this->add_preupload_settings();
$this->add_userlimit_settings(); $this->add_userlimit_settings();
$this->add_participants_settings(); $this->add_participants_settings();
$this->add_notifications_settings();
$this->add_muteonstart_settings(); $this->add_muteonstart_settings();
$this->add_locksettings_settings(); $this->add_locksettings_settings();
// Renders settings for extended capabilities. // Renders settings for extended capabilities.
@ -712,40 +711,6 @@ class settings {
$this->admin->add($this->section, $participantsettings); $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. * Helper function renders general settings if the feature is enabled.
*/ */

View File

@ -1,124 +0,0 @@
<?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 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 <andrew@nicols.co.uk>
* @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(),
];
}
}

View File

@ -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'] = '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_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'] = 'Configuration for extended capabilities';
$string['config_extended_capabilities_description'] = 'Configuration for extended capabilities when the BigBlueButton server offers them.'; $string['config_extended_capabilities_description'] = 'Configuration for extended capabilities when the BigBlueButton server offers them.';
$string['config_uidelegation_enabled'] = 'UI delegation is enabled'; $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'] = 'Instance type';
$string['mod_form_field_instanceprofiles_help'] = 'Select the type for this BigBlueButton instance.'; $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_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_html'] = 'Show the table in plain html';
$string['mod_form_field_recordings_deleted'] = 'Include recordings from deleted activities'; $string['mod_form_field_recordings_deleted'] = 'Include recordings from deleted activities';
$string['mod_form_field_recordings_imported'] = 'Show only imported links'; $string['mod_form_field_recordings_imported'] = 'Show only imported links';

View File

@ -307,12 +307,6 @@ class mod_bigbluebuttonbn_mod_form extends moodleform_mod {
$this->standard_intro_elements(get_string('mod_form_field_intro', 'bigbluebuttonbn')); $this->standard_intro_elements(get_string('mod_form_field_intro', 'bigbluebuttonbn'));
$mform->setAdvanced('introeditor'); $mform->setAdvanced('introeditor');
$mform->setAdvanced('showdescription'); $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);
}
} }
/** /**

View File

@ -114,14 +114,18 @@ class mod_helper_trait_test extends \advanced_testcase {
$generator->enrol_user($teacher->id, $this->get_course()->id); $generator->enrol_user($teacher->id, $this->get_course()->id);
// Mark the form to trigger notification. // Mark the form to trigger notification.
$bbformdata->notification = true; $bbformdata->coursecontentnotification = true;
$bbformdata->update = false;
$messagesink = $this->redirectMessages(); $messagesink = $this->redirectMessages();
mod_helper::process_post_save($bbformdata); mod_helper::process_post_save($bbformdata);
edit_module_post_actions($bbformdata, $this->course);
// Now run cron. // Now run cron.
ob_start(); ob_start();
$this->runAdhocTasks(); $this->runAdhocTasks();
ob_get_clean(); // Suppress output as it can fail the test. ob_get_clean(); // Suppress output as it can fail the test.
$this->assertEquals(1, $messagesink->count()); $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]); $this->create_instance(null, ['type' => instance::TYPE_RECORDING_ONLY]);
$bbformdata = $this->get_form_data_from_instance($bbactivity); $bbformdata = $this->get_form_data_from_instance($bbactivity);
$bbformdata->add = "1"; $bbformdata->update = false;
$messagesink = $this->redirectMessages(); $messagesink = $this->redirectMessages();
// Enrol users in a course so he will receive the message. // Enrol users in a course so he will receive the message.
$teacher = $generator->create_user(['role' => 'editingteacher']); $teacher = $generator->create_user(['role' => 'editingteacher']);
$generator->enrol_user($teacher->id, $this->get_course()->id); $generator->enrol_user($teacher->id, $this->get_course()->id);
$bbformdata->notification = true; $bbformdata->coursecontentnotification = true;
mod_helper::process_post_save($bbformdata); mod_helper::process_post_save($bbformdata);
edit_module_post_actions($bbformdata, $this->course);
// Now run cron. // Now run cron.
ob_start(); ob_start();
$this->runAdhocTasks(); $this->runAdhocTasks();
ob_get_clean(); // Suppress output as it can fail the test. ob_get_clean(); // Suppress output as it can fail the test.
$this->assertEquals(1, $messagesink->count()); $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->openingtime = time() - 1000;
$bbformdata->closing = time() + 1000; $bbformdata->closing = time() + 1000;
// Enrol users in a course so he will receive the message. // Enrol users in a course so he will receive the message.
$teacher = $generator->create_user(['role' => 'editingteacher']); $teacher = $generator->create_user();
$generator->enrol_user($teacher->id, $this->get_course()->id); $generator->enrol_user($teacher->id, $this->get_course()->id, 'editingteacher');
$this->setUser($teacher);
// Mark the form to trigger notification. // Mark the form to trigger notification.
$bbformdata->notification = true; $bbformdata->coursecontentnotification = true;
$bbformdata->update = false;
$messagesink = $this->redirectMessages(); $messagesink = $this->redirectMessages();
mod_helper::process_post_save($bbformdata); mod_helper::process_post_save($bbformdata);
edit_module_post_actions($bbformdata, $this->course);
// Now run cron. // Now run cron.
ob_start(); ob_start();
$this->runAdhocTasks(); $this->runAdhocTasks();
ob_get_clean(); // Suppress output as it can fail the test. ob_get_clean(); // Suppress output as it can fail the test.
$this->assertEquals(1, $messagesink->count()); $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); 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()); $this->assertEquals(1, $messagesink->count());
$firstmessage = $messagesink->get_messages()[0];
$this->assertStringContainsString('has been changed', $firstmessage->smallmessage);
} }
} }

View File

@ -1,106 +0,0 @@
<?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 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],
];
}
}