mirror of https://github.com/sualko/cloud_bbb
parent
0110003401
commit
da9234a24f
|
@ -58,7 +58,7 @@ class API
|
|||
*
|
||||
* @return string join url
|
||||
*/
|
||||
public function createJoinUrl(Room $room, int $creationTime, string $displayname, string $uid = null)
|
||||
public function createJoinUrl(Room $room, int $creationTime, string $displayname, ?string $uid = null)
|
||||
{
|
||||
$password = $this->permission->isModerator($room, $uid) ? $room->moderatorPassword : $room->attendeePassword;
|
||||
|
||||
|
|
|
@ -25,14 +25,14 @@ class Permission
|
|||
$this->roomShareService = $roomShareService;
|
||||
}
|
||||
|
||||
public function isUser(Room $room, string $uid)
|
||||
public function isUser(Room $room, ?string $uid)
|
||||
{
|
||||
return $this->hasPermission($room, $uid, function (RoomShare $share) {
|
||||
return $share->hasUserPermission();
|
||||
});
|
||||
}
|
||||
|
||||
public function isModerator(Room $room, string $uid)
|
||||
public function isModerator(Room $room, ?string $uid)
|
||||
{
|
||||
if ($room->everyoneIsModerator) {
|
||||
return true;
|
||||
|
@ -43,14 +43,14 @@ class Permission
|
|||
});
|
||||
}
|
||||
|
||||
public function isAdmin(Room $room, string $uid)
|
||||
public function isAdmin(Room $room, ?string $uid)
|
||||
{
|
||||
return $this->hasPermission($room, $uid, function (RoomShare $share) {
|
||||
return $share->hasAdminPermission();
|
||||
});
|
||||
}
|
||||
|
||||
private function hasPermission(Room $room, string $uid, Closure $hasPermission): bool
|
||||
private function hasPermission(Room $room, ?string $uid, Closure $hasPermission): bool
|
||||
{
|
||||
if ($uid === null) {
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
namespace OCA\BigBlueButton\Tests;
|
||||
|
||||
use OCA\BigBlueButton\Db\Room;
|
||||
use OCA\BigBlueButton\Db\RoomShare;
|
||||
use OCA\BigBlueButton\Permission;
|
||||
use OCA\BigBlueButton\Service\RoomShareService;
|
||||
use OCP\IGroupManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PermissionTest extends TestCase
|
||||
{
|
||||
/** @var Permission */
|
||||
private $permission;
|
||||
|
||||
/** @var IGroupManager|MockObject */
|
||||
private $groupManager;
|
||||
|
||||
/** @var RoomShareService|MockObject */
|
||||
private $roomShareService;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
/** @var IGroupManager|MockObject */
|
||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||
|
||||
/** @var RoomShareService|MockObject */
|
||||
$this->roomShareService = $this->createMock(RoomShareService::class);
|
||||
|
||||
$this->permission = new Permission(
|
||||
$this->groupManager,
|
||||
$this->roomShareService
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsUser()
|
||||
{
|
||||
$room = $this->createRoom(1, 'foo');
|
||||
|
||||
$this->roomShareService
|
||||
->expects($this->exactly(4))
|
||||
->method('findAll')
|
||||
->will($this->returnValueMap([
|
||||
[1, [
|
||||
$this->createRoomShare(RoomShare::SHARE_TYPE_USER, 'user', RoomShare::PERMISSION_ADMIN),
|
||||
$this->createRoomShare(RoomShare::SHARE_TYPE_GROUP, 'group', RoomShare::PERMISSION_MODERATOR),
|
||||
]],
|
||||
[2, []],
|
||||
]));
|
||||
|
||||
$this->groupManager
|
||||
->method('isInGroup')
|
||||
->will($this->returnValueMap([
|
||||
['bar', 'group', false],
|
||||
['group_user', 'group', true],
|
||||
]));
|
||||
|
||||
$this->assertFalse($this->permission->isUser($room, null), 'Test guest user');
|
||||
$this->assertFalse($this->permission->isUser($room, 'bar'), 'Test no matching share');
|
||||
$this->assertFalse($this->permission->isUser($this->createRoom(2, 'foo'), 'bar'), 'Test empty shares');
|
||||
|
||||
$this->assertTrue($this->permission->isUser($room, 'foo'), 'Test room owner');
|
||||
$this->assertTrue($this->permission->isUser($room, 'user'));
|
||||
$this->assertTrue($this->permission->isUser($room, 'group_user'));
|
||||
}
|
||||
|
||||
private function createRoom(int $id, string $userId): Room
|
||||
{
|
||||
$room = new Room();
|
||||
|
||||
$room->setId($id);
|
||||
$room->setUserId($userId);
|
||||
|
||||
return $room;
|
||||
}
|
||||
|
||||
private function createRoomShare(int $type, string $with, int $permission): RoomShare
|
||||
{
|
||||
$share = new RoomShare();
|
||||
|
||||
$share->setShareType($type);
|
||||
$share->setShareWith($with);
|
||||
$share->setPermission($permission);
|
||||
|
||||
return $share;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue