cloud_bbb/lib/Controller/RoomController.php

166 lines
4.7 KiB
PHP
Raw Normal View History

2020-04-26 11:36:41 +02:00
<?php
namespace OCA\BigBlueButton\Controller;
use OCA\BigBlueButton\CircleHelper;
2020-09-23 12:33:09 +02:00
use OCA\BigBlueButton\Db\Room;
use OCA\BigBlueButton\Permission;
use OCA\BigBlueButton\Service\RoomService;
use OCP\AppFramework\Controller;
2020-06-17 10:56:28 +02:00
use OCP\AppFramework\Http;
2020-04-26 11:36:41 +02:00
use OCP\AppFramework\Http\DataResponse;
2020-06-17 10:56:28 +02:00
use OCP\IGroupManager;
2020-09-23 12:33:09 +02:00
use OCP\IRequest;
2020-06-17 10:56:28 +02:00
use OCP\IUserManager;
2020-04-26 11:36:41 +02:00
class RoomController extends Controller {
2020-04-26 11:36:41 +02:00
/** @var RoomService */
private $service;
2020-06-17 10:56:28 +02:00
/** @var IUserManager */
private $userManager;
/** @var IGroupManager */
private $groupManager;
/** @var Permission */
private $permission;
/** @var CircleHelper */
private $circleHelper;
2020-04-26 11:36:41 +02:00
/** @var string */
private $userId;
use Errors;
public function __construct(
$appName,
IRequest $request,
RoomService $service,
2020-06-17 10:56:28 +02:00
IUserManager $userManager,
IGroupManager $groupManager,
Permission $permission,
CircleHelper $circleHelper,
2020-04-26 11:36:41 +02:00
$userId
2020-04-29 11:08:49 +02:00
) {
2020-04-26 11:36:41 +02:00
parent::__construct($appName, $request);
$this->service = $service;
2020-06-17 10:56:28 +02:00
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->permission = $permission;
$this->circleHelper = $circleHelper;
2020-04-26 11:36:41 +02:00
$this->userId = $userId;
}
/**
* @NoAdminRequired
*/
public function index(): DataResponse {
2020-06-17 10:56:28 +02:00
$user = $this->userManager->get($this->userId);
$groupIds = $this->groupManager->getUserGroupIds($user);
$circleIds = $this->circleHelper->getCircleIds($this->userId);
2020-04-26 11:36:41 +02:00
return new DataResponse($this->service->findAll($this->userId, $groupIds, $circleIds));
2020-04-26 11:36:41 +02:00
}
/**
* @NoAdminRequired
*/
public function create(
string $name,
string $welcome,
int $maxParticipants,
bool $record,
string $access
2020-04-29 11:08:49 +02:00
): DataResponse {
if (!$this->permission->isAllowedToCreateRoom($this->userId)) {
2021-02-13 17:36:14 +01:00
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
$restriction = $this->permission->getRestriction($this->userId);
if ($restriction->getMaxParticipants() > -1 && ($maxParticipants > $restriction->getMaxParticipants() || $maxParticipants <= 0)) {
2021-02-13 17:36:14 +01:00
return new DataResponse(['message' => 'Max participants limit exceeded.'], Http::STATUS_BAD_REQUEST);
}
if (!$restriction->getAllowRecording() && $record) {
2021-02-13 17:36:14 +01:00
return new DataResponse(['message' => 'Not allowed to enable recordings.'], Http::STATUS_BAD_REQUEST);
}
$disabledRoomTypes = \json_decode($restriction->getRoomTypes());
if (in_array($access, $disabledRoomTypes) || !in_array($access, Room::ACCESS)) {
2021-02-13 17:36:14 +01:00
return new DataResponse(['message' => 'Access type not allowed.'], Http::STATUS_BAD_REQUEST);
}
2020-04-26 11:36:41 +02:00
return new DataResponse($this->service->create(
$name,
$welcome,
$maxParticipants,
$record,
$access,
2020-04-26 11:36:41 +02:00
$this->userId
));
}
/**
* @NoAdminRequired
*/
public function update(
int $id,
string $name,
string $welcome,
int $maxParticipants,
bool $record,
string $access,
bool $everyoneIsModerator,
2021-01-22 19:12:55 +01:00
bool $requireModerator,
?string $moderatorToken,
bool $listenOnly,
bool $mediaCheck,
bool $cleanLayout,
bool $joinMuted
2020-04-29 11:08:49 +02:00
): DataResponse {
2020-06-17 10:56:28 +02:00
$room = $this->service->find($id);
if (!$this->permission->isAdmin($room, $this->userId)) {
return new DataResponse(null, Http::STATUS_FORBIDDEN);
}
$restriction = $this->permission->getRestriction($this->userId);
if ($restriction->getMaxParticipants() > -1 && $maxParticipants !== $room->getMaxParticipants() && ($maxParticipants > $restriction->getMaxParticipants() || $maxParticipants <= 0)) {
2021-02-13 17:36:14 +01:00
return new DataResponse(['message' => 'Max participants limit exceeded.'], Http::STATUS_BAD_REQUEST);
}
if (!$restriction->getAllowRecording() && $record !== $room->getRecord()) {
2021-02-13 17:36:14 +01:00
return new DataResponse(['message' => 'Not allowed to enable recordings.'], Http::STATUS_BAD_REQUEST);
}
$disabledRoomTypes = \json_decode($restriction->getRoomTypes());
if ((in_array($access, $disabledRoomTypes) && $access !== $room->getAccess()) || !in_array($access, Room::ACCESS)) {
2021-02-13 17:36:14 +01:00
return new DataResponse(['message' => 'Access type not allowed.'], Http::STATUS_BAD_REQUEST);
}
return $this->handleNotFound(function () use ($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator, $requireModerator, $moderatorToken, $listenOnly, $mediaCheck, $cleanLayout, $joinMuted) {
return $this->service->update($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator, $requireModerator, $moderatorToken, $listenOnly, $mediaCheck, $cleanLayout, $joinMuted);
2020-04-26 11:36:41 +02:00
});
}
/**
* @NoAdminRequired
*/
public function destroy(int $id): DataResponse {
2020-06-17 10:56:28 +02:00
$room = $this->service->find($id);
if (!$this->permission->isAdmin($room, $this->userId)) {
2021-02-13 17:36:14 +01:00
return new DataResponse([], Http::STATUS_FORBIDDEN);
2020-06-17 10:56:28 +02:00
}
2020-04-26 11:36:41 +02:00
return $this->handleNotFound(function () use ($id) {
2020-06-17 10:56:28 +02:00
//@TODO delete shares
return $this->service->delete($id);
2020-04-26 11:36:41 +02:00
});
}
}