From a8fde989c5be2fd527d96c6c96794f92b157b942 Mon Sep 17 00:00:00 2001 From: "Shamiso.Jaravaza" <33659194+ssj365@users.noreply.github.com> Date: Wed, 24 Apr 2024 13:24:21 -0600 Subject: [PATCH] CONTRIB-9485: Backport registration code to v3.0 (#624) * Warning when test-install/test-moodle used --- classes/local/config.php | 25 +++++++++- classes/output/view_page.php | 25 ---------- classes/settings.php | 15 +++++- classes/test/testcase_helper_trait.php | 3 ++ lang/en/bigbluebuttonbn.php | 23 +++++---- lang/en/deprecated.txt | 1 + .../behat/add_instance_in_empty_state.feature | 48 +++++++++++++++++++ tests/behat/behat_mod_bigbluebuttonbn.php | 4 ++ tests/external/can_join_test.php | 1 + tests/external/completion_validate_test.php | 1 + tests/external/end_meeting_test.php | 1 + .../get_bigbluebuttons_by_courses_test.php | 1 + tests/external/get_join_url_test.php | 1 + tests/external/get_recordings_test.php | 2 + tests/external/view_bigbluebuttonbn_test.php | 1 + view.php | 12 +++++ 16 files changed, 125 insertions(+), 39 deletions(-) create mode 100644 tests/behat/add_instance_in_empty_state.feature diff --git a/classes/local/config.php b/classes/local/config.php index 47aa24e7d..4f478cba7 100644 --- a/classes/local/config.php +++ b/classes/local/config.php @@ -63,8 +63,8 @@ protected static function get_moodle_version_major() { */ protected static function defaultvalues() { return [ - 'server_url' => self::DEFAULT_SERVER_URL, - 'shared_secret' => self::DEFAULT_SHARED_SECRET, + 'server_url' => '', + 'shared_secret' => '', 'voicebridge_editable' => false, 'importrecordings_enabled' => false, 'importrecordings_from_deleted_enabled' => false, @@ -170,6 +170,27 @@ public static function importrecordings_enabled() { return (boolean)self::get('importrecordings_enabled'); } + /** + * Check if bbb server credentials are invalid. + * + * @return bool + */ + public static function server_credentials_invalid(): bool { + // Test server credentials across all versions of the plugin are flagged. + $parsedurl = parse_url(self::get('server_url')); + $defaultserverurl = parse_url(self::DEFAULT_SERVER_URL); + if (!isset($parsedurl['host'])) { + return false; + } + if (strpos($parsedurl['host'], $defaultserverurl['host']) === 0) { + return true; + } + if (strpos($parsedurl['host'], 'test-moodle.blindsidenetworks.com') === 0) { + return true; + } + return false; + } + /** * Wraps current settings in an array. * diff --git a/classes/output/view_page.php b/classes/output/view_page.php index 0116f6578..266a3d9d3 100644 --- a/classes/output/view_page.php +++ b/classes/output/view_page.php @@ -61,14 +61,6 @@ public function export_for_template(renderer_base $output): stdClass { 'joinurl' => $this->instance->get_join_url(), ]; - if ($this->show_default_server_warning()) { - $templatedata->serverwarning = (new notification( - get_string('view_warning_default_server', 'mod_bigbluebuttonbn'), - notification::NOTIFY_WARNING, - false - ))->export_for_template($output); - } - $viewwarningmessage = config::get('general_warning_message'); if ($this->show_view_warning() && !empty($viewwarningmessage)) { $templatedata->sitenotification = (object) [ @@ -117,23 +109,6 @@ public function export_for_template(renderer_base $output): stdClass { return $templatedata; } - /** - * Whether to show the default server warning. - * - * @return bool - */ - protected function show_default_server_warning(): bool { - if (!$this->instance->is_admin()) { - return false; - } - - if (config::DEFAULT_SERVER_URL != config::get('server_url')) { - return false; - } - - return true; - } - /** * Whether to show the view warning. * diff --git a/classes/settings.php b/classes/settings.php index 355442850..7e4fbe2a9 100644 --- a/classes/settings.php +++ b/classes/settings.php @@ -138,6 +138,7 @@ protected function add_conditional_element(string $name, admin_setting $item, ad * @throws \coding_exception */ protected function add_general_settings(): admin_settingpage { + global $OUTPUT; $settingsgeneral = new admin_settingpage( $this->section, get_string('config_general', 'bigbluebuttonbn'), @@ -151,11 +152,21 @@ protected function add_general_settings(): admin_settingpage { get_string('config_general_description', 'bigbluebuttonbn')); $settingsgeneral->add($item); + + if (config::server_credentials_invalid()) { + // A notification should appear when default credentials are used. + $settingsgeneral->add(new admin_setting_heading( + 'bigbluebuttonbn_notification', + '', + $OUTPUT->notification(get_string('credentials_warning', 'mod_bigbluebuttonbn'), 'error') + )); + } + $item = new admin_setting_configtext( 'bigbluebuttonbn_server_url', get_string('config_server_url', 'bigbluebuttonbn'), get_string('config_server_url_description', 'bigbluebuttonbn'), - config::DEFAULT_SERVER_URL, + '', PARAM_RAW ); $item->set_updatedcallback( @@ -174,7 +185,7 @@ function() { 'bigbluebuttonbn_shared_secret', get_string('config_shared_secret', 'bigbluebuttonbn'), get_string('config_shared_secret_description', 'bigbluebuttonbn'), - config::DEFAULT_SHARED_SECRET + '' ); $this->add_conditional_element( 'shared_secret', diff --git a/classes/test/testcase_helper_trait.php b/classes/test/testcase_helper_trait.php index 73ab4ca0f..1a6e2cb62 100644 --- a/classes/test/testcase_helper_trait.php +++ b/classes/test/testcase_helper_trait.php @@ -26,6 +26,7 @@ use context_module; use mod_bigbluebuttonbn\instance; +use mod_bigbluebuttonbn\local\config; use mod_bigbluebuttonbn\local\proxy\recording_proxy; use mod_bigbluebuttonbn\meeting; use stdClass; @@ -151,6 +152,8 @@ protected function initialise_mock_server(): void { } try { $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn')->reset_mock(); + // Mock server expects a value. By default this field is empty. + set_config('bigbluebuttonbn_shared_secret', config::DEFAULT_SHARED_SECRET); } catch (\moodle_exception $e) { $this->markTestSkipped( 'Cannot connect to the mock server for this test. Make sure that TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER points diff --git a/lang/en/bigbluebuttonbn.php b/lang/en/bigbluebuttonbn.php index 7818b1c5c..14a3c4e86 100644 --- a/lang/en/bigbluebuttonbn.php +++ b/lang/en/bigbluebuttonbn.php @@ -26,6 +26,7 @@ defined('MOODLE_INTERNAL') || die(); $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['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.'; @@ -72,6 +73,8 @@ $string['search:activity'] = 'BigBlueButton - activity information'; $string['search:tags'] = 'BigBlueButton - tags information'; $string['settings'] = 'BigBlueButton settings'; +$string['settings_credential_warning_no_capability'] = 'The use of default server credentials will soon expire. To use BigBlueButton your site will require new server credentials. Please contact your site administrator for help with this.'; +$string['settings_credential_warning'] = 'Default BigBlueButton plugin credentials will soon expire. See BigBlueButton plugin settings (opens in a new window) for more information.'; $string['privacy:metadata:bigbluebuttonbn'] = 'BigBlueButton session configuration'; $string['privacy:metadata:bigbluebuttonbn:participants'] = 'A list of rules that define the role users will have in the BigBlueButton session. A user ID may be stored as permissions can be granted per role or per user.'; $string['privacy:metadata:bigbluebuttonbn_logs'] = 'Stores events triggered when using the plugin.'; @@ -125,11 +128,11 @@ $string['minutes'] = 'minutes'; $string['config_general'] = 'General settings'; -$string['config_general_description'] = 'These settings are always used.'; +$string['config_general_description'] = '
These settings are always used.
To use BigBlueButton, you can setup your own BigBlueButton server and enter the credentials below, or visit the Blindside Networks Registration Portal (opens in a new window) to obtain free trial credentials
'; $string['config_server_url'] = 'BigBlueButton Server URL'; -$string['config_server_url_description'] = 'The URL of your BigBlueButton server must end with /bigbluebutton/. (This default URL is for a BigBlueButton server provided by Blindside Networks that you can use for testing.)'; +$string['config_server_url_description'] = 'The server URL of your BigBlueButton server '; $string['config_shared_secret'] = 'BigBlueButton Shared Secret'; -$string['config_shared_secret_description'] = 'The security salt of your BigBlueButton server. (This default salt is for a BigBlueButton server provided by Blindside Networks that you can use for testing.)'; +$string['config_shared_secret_description'] = 'The security secret of your BigBlueButton server.'; $string['config_checksum_algorithm'] = 'BigBlueButton Checksum Algorithm'; $string['config_checksum_algorithm_description'] = 'The checksum algorithm of your BigBlueButton server. (SHA1 guarantees compatibility with older server versions but is less secure whereas SHA512 is FIPS 140-2 compliant.)'; @@ -577,13 +580,6 @@ $string['view_error_meeting_not_running'] = 'Something went wrong; the session is not running.'; $string['view_error_current_state_not_found'] = 'Current state was not found. The recording may have been deleted or the BigBlueButton server is not compatible with the action performed.'; $string['view_error_action_not_completed'] = 'Action could not be completed'; -$string['view_warning_default_server'] = 'This site is using a free BigBlueButton service for Moodle (opens in new window) provided by Blindside Networks with restrictions as follows: -