Skip to content

Commit

Permalink
MDL-80790 mod_bigbluebuttonbn: Trigger callback when guest added
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentdavid authored and jfederico committed Sep 16, 2024
1 parent 3d30372 commit 57f1fed
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 11 deletions.
12 changes: 2 additions & 10 deletions mod/bigbluebuttonbn/classes/form/guest_add.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class guest_add extends dynamic_form {
* @return array
*/
public function process_dynamic_submission(): array {
global $USER;
$data = $this->get_data();
$allmails = [];
if (!empty($data->emails)) {
Expand All @@ -56,15 +55,8 @@ public function process_dynamic_submission(): array {
$allmails[] = $email;
}
}
$adhoctask = new send_guest_emails();
$adhoctask->set_custom_data(
[
'emails' => $allmails,
'useridfrom' => $USER->id
]
);
$adhoctask->set_instance_id($data->id);
\core\task\manager::queue_adhoc_task($adhoctask);
$instance = $this->get_instance_from_params();
$instance->add_guests($allmails);
}
return [
'result' => true,
Expand Down
34 changes: 33 additions & 1 deletion mod/bigbluebuttonbn/classes/instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use mod_bigbluebuttonbn\local\helpers\files;
use mod_bigbluebuttonbn\local\helpers\roles;
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
use mod_bigbluebuttonbn\task\send_guest_emails;
use moodle_url;
use stdClass;

Expand Down Expand Up @@ -1289,7 +1290,7 @@ public function get_guest_access_url(): moodle_url {
*/
public function is_guest_allowed(): bool {
return !$this->is_type_recordings_only() &&
config::get('guestaccess_enabled') && $this->get_instance_var('guestallowed');
config::get('guestaccess_enabled') && $this->get_instance_var('guestallowed');
}

/**
Expand Down Expand Up @@ -1317,4 +1318,35 @@ private function generate_guest_credentials():void {
\mod_bigbluebuttonbn\plugin::generate_guest_meeting_credentials();
$DB->update_record('bigbluebuttonbn', $this->instancedata);
}

/**
* Add guest to current instance
*
* This will launch an adhoc task to send emails to guest and call back any plugin that
* would need to take care (or record) of additional guest users.
*
* @param array $guestemails
* @return void
*/
public function add_guests(array $guestemails) {
global $USER;
$adhoctask = new send_guest_emails();
$adhoctask->set_custom_data(
[
'emails' => $guestemails,
'useridfrom' => $USER->id,
]
);
$adhoctask->set_instance_id($this->get_instance_id());
\core\task\manager::queue_adhoc_task($adhoctask);
$callbacks = get_plugins_with_function('meeting_add_guests');
foreach ($callbacks as $plugintype => $plugins) {
if ($plugintype !== 'bbbext') {
continue; // Skip.
}
foreach ($plugins as $plugin => $callback) {
$callback($guestemails, $this->get_instance_id());
}
}
}
}
37 changes: 37 additions & 0 deletions mod/bigbluebuttonbn/tests/fixtures/extension/simple/lib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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/>.

/**
* Library calls for the simple extension.
*
* @package mod_bigbluebuttonbn
* @copyright 2023 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent [at] call-learning [dt] fr)
*/

/**
* Get the list of emails to add to the meeting
*
* This is a dummy callback used to demonstrate how to add a new setting to the BigBlueButtonBN settings page.
*
* @param array $emails
* @param int $instanceid
* @return void
*/
function bbbext_simple_meeting_add_guests(array $emails, int $instanceid): void {
set_config('bbbext_simple_meeting_add_guests', join(",", $emails), 'bbbext_simple');
}
13 changes: 13 additions & 0 deletions mod/bigbluebuttonbn/tests/local/extension_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,17 @@ private function enable_plugins(bool $bbbenabled) {
set_config('disabled', 'disabled', $plugin);
}
}

/**
* Test that extension has been notified that a guest has been added
* @covers \mod_bigbluebuttonbn\instance::add_guests
*/
public function test_extension_guest_emails_callback(): void {
$this->resetAfterTest();
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
$instance = instance::get_from_instanceid($bbactivity->id);
$emails = ['[email protected]', '[email protected]'];
$instance->add_guests($emails);
$this->assertEquals(join(',', $emails), get_config('bbbext_simple', 'bbbext_simple_meeting_add_guests'));
}
}

0 comments on commit 57f1fed

Please sign in to comment.