Merge branch 'MDL-82872' of https://github.com/jfederico/moodle
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
issueNumber: MDL-82872
|
||||
notes:
|
||||
mod_bigbluebuttonbn:
|
||||
- message: >-
|
||||
The process_meeting_events in the broker class has been extended to process all the process_action functions
|
||||
implemented by the plugins.
|
||||
type: improved
|
||||
@@ -38,13 +38,11 @@ global $PAGE, $USER, $CFG, $SESSION, $DB;
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
$action = $params['action'];
|
||||
|
||||
$instance = instance::get_from_instanceid($params['bigbluebuttonbn']);
|
||||
|
||||
@@ -30,34 +30,31 @@ use mod_bigbluebuttonbn\local\config;
|
||||
* @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]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,13 +154,30 @@ class broker {
|
||||
// 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
|
||||
|
||||
@@ -67,7 +67,9 @@ abstract class base extends \core\event\base {
|
||||
];
|
||||
$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;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace mod_bigbluebuttonbn;
|
||||
use cache;
|
||||
use cm_info;
|
||||
use mod_bigbluebuttonbn\local\extension\action_url_addons;
|
||||
use mod_bigbluebuttonbn\local\extension\broker_meeting_events_addons;
|
||||
use mod_bigbluebuttonbn\local\extension\custom_completion_addons;
|
||||
use mod_bigbluebuttonbn\local\extension\mod_form_addons;
|
||||
use mod_bigbluebuttonbn\local\extension\mod_instance_helper;
|
||||
@@ -217,4 +218,15 @@ class extension {
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?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();
|
||||
}
|
||||
@@ -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();
|
||||
@@ -87,3 +87,37 @@ Feature: BigBlueButtonBN Subplugins test
|
||||
And I run all adhoc tasks
|
||||
When I reload the page
|
||||
Then I should see "Done: Raise hand twice in a meeting."
|
||||
|
||||
@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"
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ class backup_bbbext_simple_subplugin extends backup_subplugin {
|
||||
$subpluginelement = new backup_nested_element(
|
||||
'bbbext_simple',
|
||||
null,
|
||||
['newfield', 'completionextraisehandtwice']
|
||||
['newfield', 'completionextraisehandtwice', 'meetingevents']
|
||||
);
|
||||
|
||||
// Connect XML elements into the tree.
|
||||
|
||||
+46
@@ -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;
|
||||
}
|
||||
}
|
||||
Vendored
+3
@@ -37,6 +37,7 @@ class mod_instance_helper extends \mod_bigbluebuttonbn\local\extension\mod_insta
|
||||
'bigbluebuttonbnid' => $bigbluebuttonbn->id,
|
||||
'newfield' => $bigbluebuttonbn->newfield ?? '',
|
||||
'completionextraisehandtwice' => $bigbluebuttonbn->completionextraisehandtwice ?? '',
|
||||
'meetingevents' => $bigbluebuttonbn->meetingevents ?? '',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -56,10 +57,12 @@ class mod_instance_helper extends \mod_bigbluebuttonbn\local\extension\mod_insta
|
||||
$record->bigbluebuttonbnid = $bigbluebuttonbn->id;
|
||||
$record->newfield = $bigbluebuttonbn->newfield ?? '';
|
||||
$record->completionextraisehandtwice = $bigbluebuttonbn->completionextraisehandtwice ?? 0;
|
||||
$record->meetingevents = $bigbluebuttonbn->meetingevents ?? '';
|
||||
$DB->insert_record('bbbext_simple', $record);
|
||||
} else {
|
||||
$record->newfield = $bigbluebuttonbn->newfield ?? '';
|
||||
$record->completionextraisehandtwice = $bigbluebuttonbn->completionextraisehandtwice ?? 0;
|
||||
$record->meetingevents = $bigbluebuttonbn->meetingevents ?? '';
|
||||
$DB->update_record('bbbext_simple', $record);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<FIELD NAME="bigbluebuttonbnid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="newfield" TYPE="int" LENGTH="2" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="completionextraisehandtwice" TYPE="int" LENGTH="9" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="meetingevents" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace mod_bigbluebuttonbn\local;
|
||||
|
||||
use backup;
|
||||
use backup_controller;
|
||||
use mod_bigbluebuttonbn\broker;
|
||||
use mod_bigbluebuttonbn\completion\custom_completion;
|
||||
use mod_bigbluebuttonbn\extension;
|
||||
use mod_bigbluebuttonbn\instance;
|
||||
@@ -369,6 +370,54 @@ class extension_test extends \advanced_testcase {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test broker meeting_events with and without addons.
|
||||
* @return void
|
||||
* @covers \mod_bigbluebuttonbn\local\extension\broker_meeting_events_addons
|
||||
*/
|
||||
public function test_broker_meeting_events_addons(): void {
|
||||
$this->resetAfterTest();
|
||||
global $DB;
|
||||
// Enable plugin.
|
||||
$this->enable_plugins(true);
|
||||
$this->initialise_mock_server();
|
||||
[$bbactivitycontext, $bbactivitycm, $bbactivity] = $this->create_instance(
|
||||
$this->get_course());
|
||||
$plugingenerator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn');
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
// Now create a couple of events.
|
||||
$instance = instance::get_from_instanceid($bbactivity->id);
|
||||
set_config('bigbluebuttonbn_meetingevents_enabled', true);
|
||||
$meeting = $plugingenerator->create_meeting([
|
||||
'instanceid' => $instance->get_instance_id(),
|
||||
'groupid' => $instance->get_group_id(),
|
||||
'participants' => json_encode([$user->id]),
|
||||
]);
|
||||
|
||||
$events = [
|
||||
(object) ['name' => 'talks'],
|
||||
(object) ['name' => 'raisehand'],
|
||||
(object) ['name' => 'raisehand'],
|
||||
];
|
||||
foreach ($events as $edesc) {
|
||||
$plugingenerator->add_meeting_event($user, $instance, $edesc->name, $edesc->data ?? '');
|
||||
}
|
||||
$result = $plugingenerator->send_all_events($instance);
|
||||
$this->assertNotEmpty($result->data);
|
||||
$data = json_encode($result->data);
|
||||
$reflection = new \ReflectionClass(broker::class);
|
||||
$method = $reflection->getMethod('process_extension_actions');
|
||||
$method->setAccessible(true);
|
||||
$method->invokeArgs(null, [$instance, $data]);
|
||||
$addondata = $DB->get_field('bbbext_simple', 'meetingevents', ['bigbluebuttonbnid' => $bbactivity->id]);
|
||||
$addondata = json_decode($addondata);
|
||||
// Check that the data is received.
|
||||
$this->assertEquals(json_encode($addondata), $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Data provider for testing get_class_implementing
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user