Skip to content

Commit

Permalink
CONTRIB-9485: Backport registration code to v3.0 (#624)
Browse files Browse the repository at this point in the history
* Warning when test-install/test-moodle used
  • Loading branch information
ssj365 authored Apr 24, 2024
1 parent 19eb432 commit a8fde98
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 39 deletions.
25 changes: 23 additions & 2 deletions classes/local/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
*
Expand Down
25 changes: 0 additions & 25 deletions classes/output/view_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) [
Expand Down Expand Up @@ -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.
*
Expand Down
15 changes: 13 additions & 2 deletions classes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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(
Expand All @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions classes/test/testcase_helper_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
23 changes: 13 additions & 10 deletions lang/en/bigbluebuttonbn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down Expand Up @@ -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<a href="{$a->settingslink}" target="_blank"> plugin settings (opens in a new window)</a> 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.';
Expand Down Expand Up @@ -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'] = '<p>These settings are always used.</p><p>To use BigBlueButton, you can setup your own BigBlueButton server and enter the credentials below, or visit the <a href="https://registration-portal.blindsidenetworks.com/" target="_blank">Blindside Networks Registration Portal (opens in a new window)</a> to obtain free trial credentials</p>';
$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.)';
Expand Down Expand Up @@ -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 <a href="https://bigbluebutton.org/free-bigbluebutton-service-for-moodle/" target="_blank">free BigBlueButton service for Moodle (opens in new window)</a> provided by Blindside Networks with restrictions as follows:
<ol>
<li>The maximum length for each session is 60 minutes</li>
<li>The maximum number of concurrent users per session is 25</li>
<li>Recordings expire after seven (7) days and are not downloadable</li>
<li>Student webcams are only visible to the moderator.</li>
</ol>';

$string['view_room'] = 'View room';
$string['index_error_noinstances'] = 'There are no instances of BigBlueButton rooms';
Expand Down Expand Up @@ -620,3 +616,10 @@
$string['email_body_recording_ready_in_course'] = 'in the course';
$string['email_footer_sent_by'] = 'This automatic notification message was sent by';
$string['email_footer_sent_from'] = 'from the course';
$string['view_warning_default_server'] = 'This site is using a <a href="https://bigbluebutton.org/free-bigbluebutton-service-for-moodle/" target="_blank">free BigBlueButton service for Moodle (opens in new window)</a> provided by Blindside Networks with restrictions as follows:
<ol>
<li>The maximum length for each session is 60 minutes</li>
<li>The maximum number of concurrent users per session is 25</li>
<li>Recordings expire after seven (7) days and are not downloadable</li>
<li>Student webcams are only visible to the moderator.</li>
</ol>';
1 change: 1 addition & 0 deletions lang/en/deprecated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ email_body_recording_ready_for,mod_bigbluebuttonbn
email_body_recording_ready_in_course,mod_bigbluebuttonbn
email_footer_sent_by,mod_bigbluebuttonbn
email_footer_sent_from,mod_bigbluebuttonbn
view_warning_default_server,mod_bigbluebuttonbn
48 changes: 48 additions & 0 deletions tests/behat/add_instance_in_empty_state.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@mod @mod_bigbluebuttonbn @javascript
Feature: I can create a bigbluebuttonbn instance with default server
In case the BigBlueButton server has not been configured
As a user
I want to see a notification message

Background: Make sure that a course is created
Given the following "courses" exist:
| fullname | shortname | category |
| Test course | Test course | 0 |
And the following "users" exist:
| username | firstname | lastname | email |
| user1 | User1G1 | 1 | user1@example.com |
| teacher1 | TeacherG1 | 1 | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| user1 | Test course | student |
| teacher1 | Test course | editingteacher |
And the following "activities" exist:
| activity | course | name | type |
| bigbluebuttonbn | Test course | BBB Instance name | 0 |
| bigbluebuttonbn | Test course | BBB Instance name 2 | 1 |
| bigbluebuttonbn | Test course | BBB Instance name 3 | 2 |
And I am on the "Test course" "course" page logged in as "admin"

Scenario Outline: Add an activity using default server for the three types of instance types
When I turn editing mode on
And I change window size to "large"
And I add a "BigBlueButton" to section "1"
And I select "<type>" from the "Instance type" singleselect
Then I should see "Restrict access"

Examples:
| type |
| Room with recordings |
| Room only |
| Recordings only |

Scenario Outline: Users should see a notification message when accessing activities if the default server is used
When I am on the "BBB Instance name" Activity page logged in as <user>
Then "Join session" "link" should exist
And I <messageexist> "<shouldseemessage>"

Examples:
| user | shouldseemessage | messageexist |
| user1 | The use of default server credentials will soon expire.| should not see |
| teacher1 | The use of default server credentials will soon expire.| should see |
| admin | Default BigBlueButton plugin credentials will soon expire.| should see |
4 changes: 4 additions & 0 deletions tests/behat/behat_mod_bigbluebuttonbn.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use mod_bigbluebuttonbn\local\config;
use Moodle\BehatExtension\Exception\SkippedException;

/**
Expand All @@ -49,6 +50,9 @@ public function before_scenario(BeforeScenarioScope $scope) {
if (defined('TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER')) {
$this->send_mock_request('backoffice/reset');
}
// Fields are empty by default which causes tests to fail.
set_config('bigbluebuttonbn_server_url', config::DEFAULT_SERVER_URL);
set_config('bigbluebuttonbn_shared_secret', config::DEFAULT_SHARED_SECRET);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/external/can_join_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected function can_join(...$params) {
* Test execute API CALL with no instance
*/
public function test_execute_no_instance() {
$this->resetAfterTest();
$canjoin = $this->can_join(1234, 5678);

$this->assertIsArray($canjoin);
Expand Down
1 change: 1 addition & 0 deletions tests/external/completion_validate_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected function completion_validate(...$params) {
* Test execute API CALL with no instance
*/
public function test_execute_no_instance() {
$this->resetAfterTest();
$result = $this->completion_validate(1234);

$this->assertIsArray($result);
Expand Down
1 change: 1 addition & 0 deletions tests/external/end_meeting_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected function end_meeting(...$params) {
* Test execute API CALL with no instance
*/
public function test_execute_no_instance() {
$this->resetAfterTest();
$this->expectException(moodle_exception::class);
$endmeeting = $this->end_meeting(1234, 5678);
}
Expand Down
1 change: 1 addition & 0 deletions tests/external/get_bigbluebuttons_by_courses_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected function get_bigbluebuttons_by_courses(...$params) {
* Test execute API CALL with no instance
*/
public function test_execute_no_instance() {
$this->resetAfterTest();
$bbbactivities = $this->get_bigbluebuttons_by_courses([1234, 5678]);

$this->assertIsArray($bbbactivities);
Expand Down
1 change: 1 addition & 0 deletions tests/external/get_join_url_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected function get_join_url(...$params) {
* Test execute API CALL with no instance
*/
public function test_execute_no_instance() {
$this->resetAfterTest();
$this->expectExceptionMessageMatches('/No such instance.*/');
$joinurl = $this->get_join_url(1234, 5678);

Expand Down
2 changes: 2 additions & 0 deletions tests/external/get_recordings_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ protected function get_recordings(...$params) {
* Test execute API CALL with no instance
*/
public function test_execute_wrong_instance() {
$this->resetAfterTest();

$getrecordings = $this->get_recordings(1234);

$this->assertIsArray($getrecordings);
Expand Down
1 change: 1 addition & 0 deletions tests/external/view_bigbluebuttonbn_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected function view_bigbluebuttonbn(...$params) {
* Test execute API CALL with no instance
*/
public function test_execute_no_instance() {
$this->resetAfterTest();
$bbbactivities = $this->view_bigbluebuttonbn(1234);

$this->assertIsArray($bbbactivities);
Expand Down
12 changes: 12 additions & 0 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/

use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\config;
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
use mod_bigbluebuttonbn\logger;
use mod_bigbluebuttonbn\output\view_page;
Expand Down Expand Up @@ -80,6 +81,17 @@

echo $OUTPUT->header();

// Credentials have not been setup, then we output a message to teachers and admin.
if (config::server_credentials_invalid()) {
if (has_capability('moodle/site:config', context_system::instance())) {
$settingslink = new moodle_url('/admin/settings.php', ['section' => 'modsettingbigbluebuttonbn']);
echo $OUTPUT->notification(get_string('settings_credential_warning', 'bigbluebuttonbn',
['settingslink' => $settingslink->out()]), 'notifywarning');
} else if (has_capability('moodle/course:manageactivities', context_course::instance($course->id))) {
echo $OUTPUT->notification(get_string('settings_credential_warning_no_capability', 'bigbluebuttonbn'), 'notifywarning');
}
}

// Validate if the user is in a role allowed to join.
if (!$instance->can_join() && $instance->get_type() != instance::TYPE_RECORDING_ONLY) {
if (isguestuser()) {
Expand Down

0 comments on commit a8fde98

Please sign in to comment.