cloud_bbb/lib/Controller/RoomController.php

153 lines
4.1 KiB
PHP
Raw Normal View History

2020-04-26 11:36:41 +02:00
<?php
namespace OCA\BigBlueButton\Controller;
2020-06-17 10:56:28 +02:00
use OCA\BigBlueButton\Service\RoomService;
use OCA\BigBlueButton\Permission;
use OCA\BigBlueButton\Db\Room;
2020-04-26 11:36:41 +02:00
use OCP\IRequest;
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;
use OCP\AppFramework\Controller;
2020-06-17 10:56:28 +02:00
use OCP\IGroupManager;
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;
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,
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;
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);
2020-04-26 11:36:41 +02:00
2020-06-17 10:56:28 +02:00
return new DataResponse($this->service->findAll($this->userId, $groupIds));
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)) {
return new DataResponse(null, Http::STATUS_FORBIDDEN);
}
$restriction = $this->permission->getRestriction($this->userId);
if ($restriction->getMaxParticipants() > -1 && ($maxParticipants > $restriction->getMaxParticipants() || $maxParticipants <= 0)) {
return new DataResponse('Max participants limit exceeded.', Http::STATUS_BAD_REQUEST);
}
if (!$restriction->getAllowRecording() && $record) {
return new DataResponse('Not allowed to enable recordings.', Http::STATUS_BAD_REQUEST);
}
$disabledRoomTypes = \json_decode($restriction->getRoomTypes());
if (in_array($access, $disabledRoomTypes) || !in_array($access, Room::ACCESS)) {
return new DataResponse('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
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)) {
return new DataResponse('Max participants limit exceeded.', Http::STATUS_BAD_REQUEST);
}
if (!$restriction->getAllowRecording() && $record !== $room->getRecord()) {
return new DataResponse('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)) {
return new DataResponse('Access type not allowed.', Http::STATUS_BAD_REQUEST);
}
return $this->handleNotFound(function () use ($id, $name, $welcome, $maxParticipants, $record, $everyoneIsModerator, $access) {
2020-06-17 10:56:28 +02:00
return $this->service->update($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator);
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)) {
return new DataResponse(null, Http::STATUS_FORBIDDEN);
}
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
});
}
}