diff --git a/admin/modules.php b/admin/modules.php index b5e61fa2763..deec4a677e8 100644 --- a/admin/modules.php +++ b/admin/modules.php @@ -31,29 +31,20 @@ if (!empty($hide) and confirm_sesskey()) { $class = \core_plugin_manager::resolve_plugininfo_class('mod'); - $class::enable_plugin($hide, false); - - admin_get_root(true, false); // settings not required - only pages + if ($class::enable_plugin($hide, false)) { + // Settings not required - only pages. + admin_get_root(true, false); + } redirect(new moodle_url('/admin/modules.php')); } - if (!empty($show) and confirm_sesskey()) { - $canenablemodule = true; - $modulename = $show; - - // Invoking a callback function that enables plugins to force additional actions (e.g. displaying notifications, - // modals, etc.) and also specify through its returned value (bool) whether the process of enabling the plugin - // should continue after these actions or not. - if (component_callback_exists("mod_{$modulename}", 'pre_enable_plugin_actions')) { - $canenablemodule = component_callback("mod_{$modulename}", 'pre_enable_plugin_actions'); - } - - if ($canenablemodule) { - $class = \core_plugin_manager::resolve_plugininfo_class('mod'); - $class::enable_plugin($show, true); - admin_get_root(true, false); // Settings not required - only pages. - redirect(new moodle_url('/admin/modules.php')); + if (!empty($show) && confirm_sesskey()) { + $class = \core_plugin_manager::resolve_plugininfo_class('mod'); + if ($class::enable_plugin($show, true)) { + // Settings not required - only pages. + admin_get_root(true, false); } + redirect(new moodle_url('/admin/modules.php')); } echo $OUTPUT->header(); diff --git a/lib/classes/plugininfo/mod.php b/lib/classes/plugininfo/mod.php index ce8ebccf1dd..8e67f415b72 100644 --- a/lib/classes/plugininfo/mod.php +++ b/lib/classes/plugininfo/mod.php @@ -51,6 +51,14 @@ class mod extends base { // Only set visibility if it's different from the current value. if ($module->visible != $enabled) { + if ($enabled && component_callback_exists("mod_{$pluginname}", 'pre_enable_plugin_actions')) { + // Invoking a callback function that enables plugins to force additional actions (e.g. displaying notifications, + // modals, etc.) and also specify through its returned value (bool) whether the process of enabling the plugin + // should continue after these actions or not. + if (!component_callback("mod_{$pluginname}", 'pre_enable_plugin_actions')) { + return false; + } + } // Set module visibility. $DB->set_field('modules', 'visible', $enabled, ['id' => $module->id]); $haschanged = true; diff --git a/mod/bigbluebuttonbn/classes/settings.php b/mod/bigbluebuttonbn/classes/settings.php index 588dd5b6003..e338e281b0e 100644 --- a/mod/bigbluebuttonbn/classes/settings.php +++ b/mod/bigbluebuttonbn/classes/settings.php @@ -136,6 +136,8 @@ class settings { * @throws \coding_exception */ protected function add_general_settings(): admin_settingpage { + global $CFG; + $settingsgeneral = new admin_settingpage( $this->section, get_string('config_general', 'bigbluebuttonbn'), @@ -146,7 +148,17 @@ class settings { // Configuration for BigBlueButton. $item = new admin_setting_heading('bigbluebuttonbn_config_general', '', - get_string('config_general_description', 'bigbluebuttonbn')); + get_string('config_general_description', 'bigbluebuttonbn') + ); + + if (empty($CFG->bigbluebuttonbn_default_dpa_accepted)) { + $settingsgeneral->add(new admin_setting_configcheckbox( + 'bigbluebuttonbn_default_dpa_accepted', + get_string('acceptdpa', 'mod_bigbluebuttonbn'), + get_string('enablingbigbluebuttondpainfo', 'mod_bigbluebuttonbn', config::DEFAULT_DPA_URL), + 0 + )); + } $settingsgeneral->add($item); $item = new admin_setting_configtext( diff --git a/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php b/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php index 3ec2201f921..00b13420ec2 100644 --- a/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php +++ b/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php @@ -49,6 +49,7 @@ $string['bigbluebuttondisablednotification'] = 'The BigBlueButton activity modul $string['cannotperformaction'] = 'Cannot perform action {$a} on this recording'; $string['enablingbigbluebutton'] = 'Enabling BigBlueButton activity'; $string['enablingbigbluebuttondpainfo'] = 'In order to meet your data protection obligations, prior to enabling this plugin, you may need to ensure that you have read and accepted the <a href="{$a}" target="_blank">Blindside Networks data processing agreement</a>. Please consult with your own privacy professionals for advice.'; +$string['dpainfonotsigned'] = 'Before enabling this plugin, you must confirm that you have read and accepted the <a href="{$a}">Blindside Networks data processing agreement</a>.'; $string['indicator:cognitivedepth'] = 'BigBlueButton cognitive'; $string['indicator:cognitivedepth_help'] = 'This indicator is based on the cognitive depth reached by the student in a BigBlueButton activity.'; $string['indicator:socialbreadth'] = 'BigBlueButton social'; diff --git a/mod/bigbluebuttonbn/lib.php b/mod/bigbluebuttonbn/lib.php index f5800c3daae..5f7187a2177 100644 --- a/mod/bigbluebuttonbn/lib.php +++ b/mod/bigbluebuttonbn/lib.php @@ -730,7 +730,11 @@ function bigbluebuttonbn_pre_enable_plugin_actions(): bool { // agreement, do not enable the plugin. Instead, display a dynamic form where the administrator can confirm that he // accepts the DPA prior to enabling the plugin. if (config::get('server_url') === config::DEFAULT_SERVER_URL && !config::get('default_dpa_accepted')) { - $PAGE->requires->js_call_amd('mod_bigbluebuttonbn/accept_dpa', 'init', []); + $url = new moodle_url('/admin/category.php', ['category' => 'modbigbluebuttonbnfolder']); + \core\notification::add( + get_string('dpainfonotsigned', 'mod_bigbluebuttonbn', $url->out(false)), + \core\notification::ERROR + ); return false; } // Otherwise, continue and enable the plugin. diff --git a/mod/bigbluebuttonbn/tests/lib_test.php b/mod/bigbluebuttonbn/tests/lib_test.php index f4d60610b90..b54be9fee76 100644 --- a/mod/bigbluebuttonbn/tests/lib_test.php +++ b/mod/bigbluebuttonbn/tests/lib_test.php @@ -698,4 +698,72 @@ class lib_test extends \advanced_testcase { $event->instance = 0; $this->assertFalse(mod_bigbluebuttonbn_core_calendar_is_event_visible($event)); } + + /** + * Check the bigbluebuttonbn_pre_enable_plugin_actions function. + * + * @covers ::bigbluebuttonbn_pre_enable_plugin_actions + * @dataProvider bigbluebuttonbn_pre_enable_plugin_actions_provider + * @param bool $initialstate + * @param bool $expected + * @param int $notificationcount + */ + public function test_bigbluebuttonbn_pre_enable_plugin_actions( + ?bool $initialstate, + bool $expected, + int $notificationcount + ): void { + $this->resetAfterTest(true); + + set_config('bigbluebuttonbn_default_dpa_accepted', $initialstate); + + $this->assertEquals($expected, bigbluebuttonbn_pre_enable_plugin_actions()); + $this->assertCount($notificationcount, \core\notification::fetch()); + } + + /** + * Check the bigbluebuttonbn_pre_enable_plugin_actions function. + * + * @covers ::bigbluebuttonbn_pre_enable_plugin_actions + * @dataProvider bigbluebuttonbn_pre_enable_plugin_actions_provider + * @param bool $initialstate + * @param bool $expected + * @param int $notificationcount + */ + public function test_enable_plugin( + ?bool $initialstate, + bool $expected, + int $notificationcount + ): void { + $this->resetAfterTest(true); + + set_config('bigbluebuttonbn_default_dpa_accepted', $initialstate); + $this->assertEquals($expected, \core\plugininfo\mod::enable_plugin('bigbluebuttonbn', 1)); + $this->assertCount($notificationcount, \core\notification::fetch()); + } + + /** + * Data provider for bigbluebuttonbn_pre_enable_plugin_actions tests. + * + * @return array + */ + public function bigbluebuttonbn_pre_enable_plugin_actions_provider(): array { + return [ + 'Initially unset' => [ + null, + false, + 1, + ], + 'Set to false' => [ + false, + false, + 1, + ], + 'Initially set' => [ + true, + true, + 0, + ], + ]; + } }