mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-77248 core: Move pre_enable_plugin_actions callback to enable_plugin
This commit is contained in:
parent
a31f5830bd
commit
9d5e363b41
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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(
|
||||
|
@ -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';
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user