2020-06-16 16:54:50 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\BigBlueButton;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use OCA\BigBlueButton\Service\RoomShareService;
|
|
|
|
use OCA\BigBlueButton\Db\Room;
|
|
|
|
use OCA\BigBlueButton\Db\RoomShare;
|
|
|
|
use OCP\IGroupManager;
|
|
|
|
|
|
|
|
class Permission
|
|
|
|
{
|
|
|
|
|
|
|
|
/** @var IGroupManager */
|
|
|
|
private $groupManager;
|
|
|
|
|
|
|
|
/** @var RoomShareService */
|
|
|
|
private $roomShareService;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
IGroupManager $groupManager,
|
|
|
|
RoomShareService $roomShareService
|
|
|
|
) {
|
|
|
|
$this->groupManager = $groupManager;
|
|
|
|
$this->roomShareService = $roomShareService;
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:20:03 +02:00
|
|
|
public function isUser(Room $room, ?string $uid)
|
2020-06-16 16:54:50 +02:00
|
|
|
{
|
|
|
|
return $this->hasPermission($room, $uid, function (RoomShare $share) {
|
|
|
|
return $share->hasUserPermission();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:20:03 +02:00
|
|
|
public function isModerator(Room $room, ?string $uid)
|
2020-06-16 16:54:50 +02:00
|
|
|
{
|
2020-06-17 08:19:54 +02:00
|
|
|
if ($room->everyoneIsModerator) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-16 16:54:50 +02:00
|
|
|
return $this->hasPermission($room, $uid, function (RoomShare $share) {
|
|
|
|
return $share->hasModeratorPermission();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:20:03 +02:00
|
|
|
public function isAdmin(Room $room, ?string $uid)
|
2020-06-16 16:54:50 +02:00
|
|
|
{
|
|
|
|
return $this->hasPermission($room, $uid, function (RoomShare $share) {
|
|
|
|
return $share->hasAdminPermission();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:20:03 +02:00
|
|
|
private function hasPermission(Room $room, ?string $uid, Closure $hasPermission): bool
|
2020-06-16 16:54:50 +02:00
|
|
|
{
|
|
|
|
if ($uid === null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($uid === $room->userId) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$shares = $this->roomShareService->findAll($room->id);
|
|
|
|
|
|
|
|
/** @var RoomShare $share */
|
|
|
|
foreach ($shares as $share) {
|
|
|
|
if (!$hasPermission($share)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($share->getShareType() === RoomShare::SHARE_TYPE_USER) {
|
|
|
|
if ($share->getShareWith() === $uid) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} elseif ($share->getShareType() === RoomShare::SHARE_TYPE_GROUP) {
|
|
|
|
if ($this->groupManager->isInGroup($uid, $share->getShareWith())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|