Skip to content

Commit

Permalink
MDL-81898 mod_bigbluebuttonbn: Add server check
Browse files Browse the repository at this point in the history
  • Loading branch information
ssj365 committed Jan 2, 2025
1 parent 653edd7 commit 23233bc
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mod/bigbluebuttonbn/classes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ protected function add_general_settings(): admin_settingpage {
);
$settingsgeneral->add($item);

if (empty(config::get('server_url'))) {
// A notification should appear when server credentials are empty.
$settingsgeneral->add(new admin_setting_heading(
'bigbluebuttonbn_notification',
'',
$OUTPUT->notification(get_string('config_empty_credentials_warning', 'mod_bigbluebuttonbn'), 'error')
));
}

if (config::server_credentials_invalid()) {
// A notification should appear when default credentials are used.
$settingsgeneral->add(new admin_setting_heading(
Expand Down
3 changes: 3 additions & 0 deletions mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

$string['activityoverview'] = 'You have upcoming BigBlueButton sessions';
$string['credentials_warning'] = 'The use of default server credentials will soon expire (see note above to obtain new credentials).';
$string['enable_empty_credentials'] = 'Before enabling this plugin, you must enter your <a href="{$a}" target="_blank">BigBlueButton server URL and security secret</a>.';
$string['bbbduetimeoverstartingtime'] = 'The close time must be later than the open time.';
$string['bbbdurationwarning'] = 'The maximum duration for this session is %duration% minutes.';
$string['bbbrecordwarning'] = 'This session may be recorded.';
Expand Down Expand Up @@ -142,6 +143,8 @@
$string['config_checksum_algorithm'] = 'BigBlueButton server checksum algorithm';
$string['config_checksum_algorithm_description'] = 'SHA1 is compatible with older servers. SHA256 and SHA512 are more secure. SHA512 is FIPS 140-2 compliant.';

$string['config_empty_credentials_warning'] = 'Before using this plugin, you must enter your BigBlueButton server URL and security secret.';

$string['config_recording'] = 'Recording';
$string['config_recording_description'] = 'These settings are feature specific';
$string['config_recording_default'] = 'Recording enabled by default';
Expand Down
20 changes: 20 additions & 0 deletions mod/bigbluebuttonbn/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,26 @@ function bigbluebuttonbn_print_recent_activity(object $course, bool $viewfullnam
return true;
}

/**
* Callback method executed prior to enabling the activity module.
*
* @return bool Whether to proceed and enable the plugin or not.
*/
function bigbluebuttonbn_pre_enable_plugin_actions(): bool {
global $PAGE;

// By default there are no server credentials and the plugin should not be enabled.
if ((empty(config::get('server_url')))) {
$url = new moodle_url('/admin/category.php', ['category' => 'modbigbluebuttonbnfolder']);
\core\notification::add(
get_string('enable_empty_credentials', 'mod_bigbluebuttonbn', $url->out(false)),
\core\notification::ERROR
);
return false;
}
// Otherwise, continue and enable the plugin.
return true;
}

/**
* Creates a number of BigblueButtonBN activities.
Expand Down
3 changes: 3 additions & 0 deletions mod/bigbluebuttonbn/tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class mod_bigbluebuttonbn_generator extends \testing_module_generator {
*/
public function create_instance($record = null, ?array $options = null) {
// Prior to creating the instance, make sure that the BigBlueButton module is enabled.
if ((empty(config::get('server_url')))) {
set_config('bigbluebuttonbn_server_url', config::DEFAULT_SERVER_URL);
}
$modules = \core_plugin_manager::instance()->get_plugins_of_type('mod');
if (!$modules['bigbluebuttonbn']->is_enabled()) {
mod::enable_plugin('bigbluebuttonbn', true);
Expand Down
68 changes: 68 additions & 0 deletions mod/bigbluebuttonbn/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,4 +698,72 @@ public function test_mod_bigbluebuttonbn_core_calendar_is_event_visible(): void
$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|null $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);
if ($initialstate) {
set_config('bigbluebuttonbn_server_url', \mod_bigbluebuttonbn\local\config::DEFAULT_SERVER_URL);
}
$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|null $initialstate
* @param bool $expected
* @param int $notificationcount
*/
public function test_enable_plugin(
?bool $initialstate,
bool $expected,
int $notificationcount
): void {
$this->resetAfterTest(true);
if ($initialstate) {
set_config('bigbluebuttonbn_server_url', \mod_bigbluebuttonbn\local\config::DEFAULT_SERVER_URL);
}
$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 static 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,
],
];
}
}
1 change: 1 addition & 0 deletions mod/bigbluebuttonbn/tests/local/extension_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ public static function classes_implementing_class(): array {
*/
private function enable_plugins(bool $bbbenabled) {
// First make sure that either BBB is enabled or not.
set_config('bigbluebuttonbn_server_url', $bbbenabled ? config::DEFAULT_SERVER_URL : '');
\core\plugininfo\mod::enable_plugin('bigbluebuttonbn', $bbbenabled ? 1 : 0);
$plugin = extension::BBB_EXTENSION_PLUGIN_NAME . '_simple';
if ($bbbenabled) {
Expand Down

0 comments on commit 23233bc

Please sign in to comment.