diff --git a/mod/bigbluebuttonbn/classes/instance.php b/mod/bigbluebuttonbn/classes/instance.php index f4822f9fef1..71dfbb071ab 100644 --- a/mod/bigbluebuttonbn/classes/instance.php +++ b/mod/bigbluebuttonbn/classes/instance.php @@ -725,6 +725,19 @@ EOF; return $this->get_viewer_password(); } + /** + * Get the appropriate designated role for the current user. + * + * @return string + */ + public function get_current_user_role(): string { + if ($this->is_admin() || $this->is_moderator()) { + return 'MODERATOR'; + } + + return 'VIEWER'; + } + /** * Whether to show the recording button * diff --git a/mod/bigbluebuttonbn/classes/local/proxy/bigbluebutton_proxy.php b/mod/bigbluebuttonbn/classes/local/proxy/bigbluebutton_proxy.php index 5ba3cd7b9fc..29e8ea688d8 100644 --- a/mod/bigbluebuttonbn/classes/local/proxy/bigbluebutton_proxy.php +++ b/mod/bigbluebuttonbn/classes/local/proxy/bigbluebutton_proxy.php @@ -47,6 +47,7 @@ class bigbluebutton_proxy extends proxy_base { * @param string $username * @param string $pw * @param string $logouturl + * @param string $role * @param string|null $configtoken * @param string|null $userid * @param string|null $createtime @@ -58,6 +59,7 @@ class bigbluebutton_proxy extends proxy_base { string $username, string $pw, string $logouturl, + string $role, string $configtoken = null, string $userid = null, string $createtime = null @@ -67,6 +69,7 @@ class bigbluebutton_proxy extends proxy_base { 'fullName' => $username, 'password' => $pw, 'logoutURL' => $logouturl, + 'role' => $role ]; if (!is_null($configtoken)) { diff --git a/mod/bigbluebuttonbn/classes/meeting.php b/mod/bigbluebuttonbn/classes/meeting.php index a6b397606bf..b52ce970383 100644 --- a/mod/bigbluebuttonbn/classes/meeting.php +++ b/mod/bigbluebuttonbn/classes/meeting.php @@ -198,6 +198,7 @@ class meeting { $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 @@ -355,6 +356,7 @@ class meeting { ]; /** * Helper to prepare data used for create meeting. + * @todo moderatorPW and attendeePW will be removed from create after release of BBB v2.6. * * @return array */ diff --git a/mod/bigbluebuttonbn/tests/instance_test.php b/mod/bigbluebuttonbn/tests/instance_test.php index 287dd5ab23f..ccd03256566 100644 --- a/mod/bigbluebuttonbn/tests/instance_test.php +++ b/mod/bigbluebuttonbn/tests/instance_test.php @@ -460,6 +460,47 @@ class instance_test extends advanced_testcase { ]; } + /** + * Ensure that the get_current_user_role function works as expected. + * + * @dataProvider get_current_user_role_provider + * @param bool $isadmin + * @param bool $ismoderator + * @param bool $expectedmodrole + * @covers ::get_current_user_role + */ + public function test_get_current_user_role(bool $isadmin, bool $ismoderator, bool $expectedmodrole): void { + $stub = $this->getMockBuilder(instance::class) + ->setMethods([ + 'is_admin', + 'is_moderator', + ]) + ->disableOriginalConstructor() + ->getMock(); + + $stub->method('is_admin')->willReturn($isadmin); + $stub->method('is_moderator')->willReturn($ismoderator); + + if ($expectedmodrole) { + $this->assertEquals('MODERATOR', $stub->get_current_user_role()); + } else { + $this->assertEquals('VIEWER', $stub->get_current_user_role()); + } + } + + /** + * Data provider for the get_current_user_role function. + * + * @return array + */ + public function get_current_user_role_provider(): array { + return [ + 'Admin is a moderator' => [true, false, true], + 'Moderator is a moderator' => [false, true, true], + 'Others are a viewer' => [false, false, false], + ]; + } + /** * Tests for the allow_recording_start_stop function. *