From ba81f720db5d8a578076b7ad3b96d61893471e30 Mon Sep 17 00:00:00 2001 From: Laurent David Date: Wed, 11 Jan 2023 17:38:03 +0100 Subject: [PATCH 1/2] MDL-76551 mod_bigbluebuttonbn: Refactor join url * get_join url should not have as many parameters as they can be deduced from the instance. * Refactoring it will allow to pass on more implicit parameters like the user profile file. --- .../local/proxy/bigbluebutton_proxy.php | 78 ++++++++++++------- mod/bigbluebuttonbn/classes/meeting.php | 26 +------ mod/bigbluebuttonbn/upgrade.txt | 2 +- 3 files changed, 54 insertions(+), 52 deletions(-) diff --git a/mod/bigbluebuttonbn/classes/local/proxy/bigbluebutton_proxy.php b/mod/bigbluebuttonbn/classes/local/proxy/bigbluebutton_proxy.php index 7e0111185eb..03e6afa8495 100644 --- a/mod/bigbluebuttonbn/classes/local/proxy/bigbluebutton_proxy.php +++ b/mod/bigbluebuttonbn/classes/local/proxy/bigbluebutton_proxy.php @@ -51,50 +51,70 @@ class bigbluebutton_proxy extends proxy_base { const DEFAULT_POLL_INTERVAL = 5; /** - * Builds and returns a url for joining a bigbluebutton meeting. + * Builds and returns a url for joining a BigBlueButton meeting. * - * @param string $meetingid - * @param string $username - * @param string $pw - * @param string $logouturl - * @param string $role - * @param string|null $configtoken - * @param int $userid + * @param instance $instance * @param string|null $createtime * * @return string */ public static function get_join_url( - string $meetingid, - string $username, - string $pw, - string $logouturl, - string $role, - string $configtoken = null, - int $userid = 0, - string $createtime = null + instance $instance, + ?string $createtime + ): string { + return self::internal_get_join_url($instance, $createtime); + } + + /** + * Builds and returns a url for joining a BigBlueButton meeting. + * + * @param instance $instance + * @param string|null $createtime + * @param string $username + * @return string + */ + public static function get_guest_join_url( + instance $instance, + ?string $createtime, + string $username + ): string { + return self::internal_get_join_url($instance, $createtime, $username, true); + } + + /** + * Internal helper method to builds and returns a url for joining a BigBlueButton meeting. + * + * + * @param instance $instance + * @param string|null $jointime = null + * @param string|null $userfullname + * @param bool $isguestjoin + * @return string + * @throws \coding_exception + */ + private static function internal_get_join_url( + instance $instance, + ?string $jointime, + string $userfullname = null, + bool $isguestjoin = false ): string { $data = [ - 'meetingID' => $meetingid, - 'fullName' => $username, - 'password' => $pw, - 'logoutURL' => $logouturl, - 'role' => $role + 'meetingID' => $instance->get_meeting_id(), + 'fullName' => $userfullname ?? $instance->get_user_fullname(), + 'password' => $instance->get_current_user_password(), + 'logoutURL' => $isguestjoin ? $instance->get_guest_access_url()->out(false) : $instance->get_logout_url()->out(false), + 'role' => $instance->get_current_user_role() ]; - if (!is_null($configtoken)) { - $data['configToken'] = $configtoken; - } - - if (!empty($userid)) { - $data['userID'] = $userid; + if (!$isguestjoin) { + $data['userID'] = $instance->get_user_id(); $data['guest'] = "false"; } else { $data['guest'] = "true"; } - if (!is_null($createtime)) { - $data['createTime'] = $createtime; + if (!is_null($jointime)) { + $data['createTime'] = $jointime; } $currentlang = current_language(); if (!empty(trim($currentlang))) { diff --git a/mod/bigbluebuttonbn/classes/meeting.php b/mod/bigbluebuttonbn/classes/meeting.php index 6a13df20b45..4569ccd3c9b 100644 --- a/mod/bigbluebuttonbn/classes/meeting.php +++ b/mod/bigbluebuttonbn/classes/meeting.php @@ -193,35 +193,17 @@ class meeting { * @return string */ public function get_join_url(): string { - return bigbluebutton_proxy::get_join_url( - $this->instance->get_meeting_id(), - $this->instance->get_user_fullname(), - $this->instance->get_current_user_password(), - $this->instance->get_logout_url()->out(false), - $this->instance->get_current_user_role(), - null, - $this->instance->get_user_id(), - $this->get_meeting_info()->createtime - ); + return bigbluebutton_proxy::get_join_url($this->instance, $this->get_meeting_info()->createtime); } /** * Get meeting join URL for guest * - * @param string $fullname + * @param string $userfullname * @return string */ - public function get_guest_join_url(string $fullname): string { - return bigbluebutton_proxy::get_join_url( - $this->instance->get_meeting_id(), - $fullname, - $this->instance->get_current_user_password(), - $this->instance->get_guest_access_url()->out(false), - $this->instance->get_current_user_role(), - null, - 0, - $this->get_meeting_info()->createtime - ); + public function get_guest_join_url(string $userfullname): string { + return bigbluebutton_proxy::get_guest_join_url($this->instance, $this->get_meeting_info()->createtime, $userfullname); } diff --git a/mod/bigbluebuttonbn/upgrade.txt b/mod/bigbluebuttonbn/upgrade.txt index 7176f17b467..5871a50f02f 100644 --- a/mod/bigbluebuttonbn/upgrade.txt +++ b/mod/bigbluebuttonbn/upgrade.txt @@ -1,6 +1,6 @@ This files describes API changes in the bigbluebuttonbn code. - === 4.2 === +* Simplify bigbluebutton_proxy get_join_url so to pass only parameters that cannot be deduced from the instance. * Add a new parameter for mod_bigbluebuttonbn\recording::sync_pending_recordings_from_server so sync only 'dismissed' recordings (This was fixed in 4.2, 4.1.3 and 4.0.8). From aa9c5cf455a35393f8a0eb386f1873134329c857 Mon Sep 17 00:00:00 2001 From: Laurent David Date: Wed, 11 Jan 2023 17:38:42 +0100 Subject: [PATCH 2/2] MDL-76551 mod_bigbluebuttonbn: Add user picture * Add user picture with token * Add a new global setting to enable or disable avatar for users in meeting. --- mod/bigbluebuttonbn/classes/instance.php | 11 ++++++++++ mod/bigbluebuttonbn/classes/local/config.php | 1 + .../local/proxy/bigbluebutton_proxy.php | 21 +++++++++++++++++++ mod/bigbluebuttonbn/classes/settings.php | 11 ++++++++++ .../lang/en/bigbluebuttonbn.php | 2 ++ 5 files changed, 46 insertions(+) diff --git a/mod/bigbluebuttonbn/classes/instance.php b/mod/bigbluebuttonbn/classes/instance.php index cc798294c2e..9eeff97f504 100644 --- a/mod/bigbluebuttonbn/classes/instance.php +++ b/mod/bigbluebuttonbn/classes/instance.php @@ -1227,4 +1227,15 @@ EOF; \mod_bigbluebuttonbn\plugin::generate_guest_meeting_credentials(); $DB->update_record('bigbluebuttonbn', $this->instancedata); } + + /** + * Is this meeting configured to display avatars of the users ? + * + * Note: this is for now a global setting. + * + * @return bool + */ + public function is_profile_picture_enabled(): bool { + return (bool) config::get('profile_picture_enabled'); + } } diff --git a/mod/bigbluebuttonbn/classes/local/config.php b/mod/bigbluebuttonbn/classes/local/config.php index 5b4edfa0414..2a9047b0480 100644 --- a/mod/bigbluebuttonbn/classes/local/config.php +++ b/mod/bigbluebuttonbn/classes/local/config.php @@ -83,6 +83,7 @@ class config { 'recordingstatus_enabled' => false, 'meetingevents_enabled' => false, 'participant_moderator_default' => '0', + 'profile_picture_enabled' => false, 'scheduled_pre_opening' => '10', 'recordings_enabled' => true, 'recordings_deleted_default' => false, diff --git a/mod/bigbluebuttonbn/classes/local/proxy/bigbluebutton_proxy.php b/mod/bigbluebuttonbn/classes/local/proxy/bigbluebutton_proxy.php index 03e6afa8495..1bb065b8c68 100644 --- a/mod/bigbluebuttonbn/classes/local/proxy/bigbluebutton_proxy.php +++ b/mod/bigbluebuttonbn/classes/local/proxy/bigbluebutton_proxy.php @@ -26,6 +26,7 @@ use mod_bigbluebuttonbn\local\exceptions\bigbluebutton_exception; use mod_bigbluebuttonbn\local\exceptions\server_not_available_exception; use moodle_url; use stdClass; +use user_picture; /** * The bigbluebutton proxy class. @@ -120,9 +121,29 @@ class bigbluebutton_proxy extends proxy_base { if (!empty(trim($currentlang))) { $data['userdata-bbb_override_default_locale'] = $currentlang; } + if ($instance->is_profile_picture_enabled()) { + $user = $instance->get_user(); + if (!empty($user->picture)) { + $data['avatarURL'] = self::get_avatar_url($user)->out(false); + } + } return self::action_url('join', $data); } + /** + * Get user avatar URL + * + * @param object $user + * @return moodle_url + */ + private static function get_avatar_url(object $user): moodle_url { + global $PAGE; + $userpicture = new user_picture($user); + $userpicture->includetoken = true; + $userpicture->size = 3; // Size f3. + return $userpicture->get_url($PAGE); + } + /** * Perform api request on BBB. * diff --git a/mod/bigbluebuttonbn/classes/settings.php b/mod/bigbluebuttonbn/classes/settings.php index 284e2d57991..49cf9ba6bff 100644 --- a/mod/bigbluebuttonbn/classes/settings.php +++ b/mod/bigbluebuttonbn/classes/settings.php @@ -914,6 +914,17 @@ class settings { $item, $extendedcapabilitiessetting ); + $item = new admin_setting_configcheckbox( + 'bigbluebuttonbn_profile_picture_enabled', + get_string('config_profile_picture_enabled', 'bigbluebuttonbn'), + get_string('config_profile_picture_enabled_description', 'bigbluebuttonbn'), + false + ); + $this->add_conditional_element( + 'profile_picture_enabled', + $item, + $extendedcapabilitiessetting + ); } $this->admin->add($this->parent, $extendedcapabilitiessetting); // Configuration for extended BN capabilities should go here. diff --git a/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php b/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php index 1492ff4691b..2665329fcc4 100644 --- a/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php +++ b/mod/bigbluebuttonbn/lang/en/bigbluebuttonbn.php @@ -137,6 +137,8 @@ $string['config_guestaccess_enabled_description'] = 'Allow users without an acco $string['config_general'] = 'General settings'; $string['config_general_description'] = 'These settings are always used.'; +$string['config_profile_picture_enabled'] = 'Show profile pictures'; +$string['config_profile_picture_enabled_description'] = 'Should profile pictures of participants be shown in BigBlueButton sessions?'; $string['config_server_url'] = 'BigBlueButton server URL'; $string['config_server_url_description'] = 'The default credentials are for a free BigBlueButton service for Moodle (opens in new window) provided by Blindside Networks with restrictions as follows: