Skip to content

Commit

Permalink
MDL-82872
Browse files Browse the repository at this point in the history
* Backport of broker meeting events addons to Moodle 4.1 Plus branch
  • Loading branch information
ssj365 committed Nov 18, 2024
1 parent 57f1fed commit b62a8b0
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 23 deletions.
3 changes: 1 addition & 2 deletions mod/bigbluebuttonbn/bbb_broker.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@

$params = $_REQUEST;

$broker = new broker();
$error = $broker->validate_parameters($params);
$error = broker::validate_parameters($params);
if (!empty($error)) {
header('HTTP/1.0 400 Bad Request. ' . $error);
return;
Expand Down
52 changes: 33 additions & 19 deletions mod/bigbluebuttonbn/classes/broker.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,31 @@
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com)
*/
class broker {

/** @var array List of required params */
protected $requiredparams = [
'recording_ready' => [
'bigbluebuttonbn' => 'The BigBlueButtonBN instance ID must be specified.',
'signed_parameters' => 'A JWT encoded string must be included as [signed_parameters].'
],
'meeting_events' => [
'bigbluebuttonbn' => 'The BigBlueButtonBN instance ID must be specified.'
],
];

/**
* Validate the supplied list of parameters, providing feedback about any missing or incorrect values.
*
* @param array $params
* @return null|string
*/
public function validate_parameters(array $params): ?string {
if (!isset($params['action']) || empty($params['action']) ) {
return 'Parameter ['.$params['action'].'] was not included';
public static function validate_parameters(array $params): ?string {
$requiredparams = [
'recording_ready' => [
'bigbluebuttonbn' => 'The BigBlueButtonBN instance ID must be specified.',
'signed_parameters' => 'A JWT encoded string must be included as [signed_parameters].',
],
'meeting_events' => [
'bigbluebuttonbn' => 'The BigBlueButtonBN instance ID must be specified.',
],
];
if (!isset($params['action']) || empty($params['action'])) {
return 'Parameter [' . $params['action'] . '] was not included';
}

$action = strtolower($params['action']);
if (!array_key_exists($action, $this->requiredparams)) {
if (!array_key_exists($action, $requiredparams)) {
return "Action {$params['action']} can not be performed.";
}
return $this->validate_parameters_message($params, $this->requiredparams[$action]);
return self::validate_parameters_message($params, $requiredparams[$action]);
}

/**
Expand Down Expand Up @@ -157,13 +154,30 @@ public static function process_meeting_events(instance $instance) {
// Convert JSON string to a JSON object.
$jsonobj = json_decode($jsonstr);
$headermsg = meeting::meeting_events($instance, $jsonobj);
header($headermsg);
self::process_extension_actions($instance, $jsonstr);
} catch (Exception $e) {
$msg = 'Caught exception: ' . $e->getMessage();
header('HTTP/1.0 400 Bad Request. ' . $msg);
debugging($msg, DEBUG_DEVELOPER);
$headermsg = 'HTTP/1.0 400 Bad Request. ' . $msg;
}

header($headermsg);
}

/**
* Process meeting events extension actions.
*
* @param instance $instance
* @param string $jsonstr
* @return void
*/
protected static function process_extension_actions(instance $instance, string $jsonstr) {
// Hooks for extensions.
$extensions = extension::broker_meeting_events_addons_instances($instance, $jsonstr);
foreach ($extensions as $extension) {
$extension->process_action();
}
}

/**
* Get authorisation token
Expand Down
4 changes: 3 additions & 1 deletion mod/bigbluebuttonbn/classes/event/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public function get_description() {
];
$string = $this->description;
foreach ($vars as $key => $value) {
$string = str_replace("##" . $key, $value, $string);
if ($value !== null) {
$string = str_replace("##" . $key, $value, $string);
}
}
return $string;
}
Expand Down
12 changes: 12 additions & 0 deletions mod/bigbluebuttonbn/classes/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use mod_bigbluebuttonbn\local\extension\action_url_addons;
use mod_bigbluebuttonbn\local\extension\mod_form_addons;
use mod_bigbluebuttonbn\local\extension\mod_instance_helper;
use mod_bigbluebuttonbn\local\extension\broker_meeting_events_addons;
use stdClass;
use core_plugin_manager;

Expand Down Expand Up @@ -192,4 +193,15 @@ public static function delete_instance(int $id): void {
$fmclass->delete_instance($id);
}
}

/**
* Get all broker_meeting_events addons classes instances
*
* @param instance|null $instance
* @param string|null $data
* @return array of custom completion addon classes instances
*/
public static function broker_meeting_events_addons_instances(instance $instance, string $data): array {
return self::get_instances_implementing(broker_meeting_events_addons::class, [$instance, $data]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace mod_bigbluebuttonbn\local\extension;
use mod_bigbluebuttonbn\instance;

/**
* A class to deal with broker addons in a subplugin
*
* @package mod_bigbluebuttonbn
* @copyright 2024 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com)
*/
abstract class broker_meeting_events_addons {
/**
* @var instance $instance BigBlueButton instance if any
*/
protected $instance;
/**
* @var string $data data to be processed
*/
protected $data;
/**
* Constructor
*
* @param instance $instance BigBlueButton instance
* @param string $data data to be processed
*/
public function __construct(instance $instance, string $data) {
$this->instance = $instance;
$this->data = $data;
}
/**
* Data processing action
*/
abstract public function process_action();
}
34 changes: 34 additions & 0 deletions mod/bigbluebuttonbn/tests/behat/subplugins.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,37 @@ Feature: BigBlueButtonBN Subplugins test
And I am on the "BBB Instance name" "bigbluebuttonbn activity editing" page
When I expand all fieldsets
Then I should not see "New field"

@javascript
Scenario: I check that custom events are triggered and sent to subplugin when enabled
Given a BigBlueButton mock server is configured
And the following config values are set as admin:
| bigbluebuttonbn_meetingevents_enabled | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| traverst | Terry | Travers | t.travers@example.com |
And the following "course enrolments" exist:
| user | course | role |
| traverst | Test course | student |
And the following "mod_bigbluebuttonbn > meeting" exists:
| activity | BBB Instance name |
And I log out
And I am on the "BBB Instance name" "bigbluebuttonbn activity" page logged in as "traverst"
And I click on "Join session" "link"
And I switch to "bigbluebutton_conference" window
And I wait until the page is ready
And I follow "End Meeting"
And the BigBlueButtonBN server has received the following events from user "traverst":
| instancename | eventtype | eventdata |
| BBB Instance name | chats | 1 |
# Selenium driver does not like the click action to be done before we
# automatically close the window so we need to make sure that the window
# is closed before.
And I close all opened windows
And I switch to the main window
And the BigBlueButtonBN activity "BBB Instance name" has sent recording all its events
And I log out
And I log in as "admin"
And I run all adhoc tasks
When I am on fixture page "/mod/bigbluebuttonbn/tests/behat/fixtures/show_simpleplugin_values.php"
Then I should see "(BBB Instance name): meetingevents: 1"
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function define_bigbluebuttonbn_subplugin_structure() {
$subpluginelement = new backup_nested_element(
'bbbext_simple',
null,
['newfield', 'completionextraisehandtwice']
['newfield', 'completionextraisehandtwice', 'meetingevents']
);

// Connect XML elements into the tree.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace bbbext_simple\bigbluebuttonbn;

/**
* When meeting_events callback is implemented by BigBlueButton, Moodle receives a POST request
* which is processed in the function using super globals.
*
* @package mod_bigbluebuttonbn
* @copyright 2024 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com)
*/
class broker_meeting_events_addons extends \mod_bigbluebuttonbn\local\extension\broker_meeting_events_addons {
/**
* Data processing action
*/
public function process_action() {
global $DB;
if ($this->instance) {
$bigbluebuttonbnid = $this->instance->get_instance_id();
$record = $DB->get_record('bbbext_simple', [
'bigbluebuttonbnid' => $bigbluebuttonbnid,
]);
if ($record) {
$record->meetingevents = $this->data;
return $DB->update_record('bbbext_simple', $record);
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function add_instance(stdClass $bigbluebuttonbn) {
$DB->insert_record('bbbext_simple', (object) [
'bigbluebuttonbnid' => $bigbluebuttonbn->id,
'newfield' => $bigbluebuttonbn->newfield ?? '',
'meetingevents' => $bigbluebuttonbn->meetingevents ?? '',
]);
}

Expand All @@ -54,9 +55,11 @@ public function update_instance(stdClass $bigbluebuttonbn): void {
$record = new stdClass();
$record->bigbluebuttonbnid = $bigbluebuttonbn->id;
$record->newfield = $bigbluebuttonbn->newfield ?? '';
$record->meetingevents = $bigbluebuttonbn->meetingevents ?? '';
$DB->insert_record('bbbext_simple', $record);
} else {
$record->newfield = $bigbluebuttonbn->newfield ?? '';
$record->meetingevents = $bigbluebuttonbn->meetingevents ?? '';
$DB->update_record('bbbext_simple', $record);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="bigbluebuttonbnid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="newfield" TYPE="int" LENGTH="2" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="meetingevents" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
44 changes: 44 additions & 0 deletions mod/bigbluebuttonbn/tests/fixtures/show_simpleplugin_values.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Test page for simple subplugins.
*
* @package mod_bigbluebuttonbn
* @copyright 2024 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Shamiso Jaravaza (shamiso [dt] jaravaza [at] blindsidenetworks [dt] com)
*/

require_once(__DIR__ . '/../../../../../config.php');

defined('BEHAT_SITE_RUNNING') || die();
global $PAGE, $OUTPUT;
require_login();
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/mod/bigbluebuttonbn/tests/behat/fixtures/show_simpleplugin_values.php');

echo $OUTPUT->header();

$bnid = $DB->get_field('bigbluebuttonbn', 'id', ['name' => 'BBB Instance name']);
// Check that the subplugin has the correct meeting events data.
$meetingevent = $DB->get_field('bbbext_simple', 'meetingevents', ['bigbluebuttonbnid' => $bnid]);
$meetingevent = json_decode($meetingevent, true);
$chats = $meetingevent['data']['attendees'][0]['engagement']['chats'];

echo "<p>(BBB Instance name): meetingevents: {$chats}</p>";

echo $OUTPUT->footer();
Loading

0 comments on commit b62a8b0

Please sign in to comment.