From ba81f720db5d8a578076b7ad3b96d61893471e30 Mon Sep 17 00:00:00 2001 From: Laurent David Date: Wed, 11 Jan 2023 17:38:03 +0100 Subject: [PATCH] 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).