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;
|
2020-08-27 17:21:34 +02:00
|
|
|
use OCA\BigBlueButton\Db\Room;
|
2020-08-29 13:20:28 +02:00
|
|
|
use OCA\BigBlueButton\CircleHelper;
|
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
|
|
|
|
2020-06-19 09:28:58 +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-08-29 13:20:28 +02:00
|
|
|
/** @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,
|
2020-08-29 13:20:28 +02:00
|
|
|
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;
|
2020-08-29 13:20:28 +02:00
|
|
|
$this->circleHelper = $circleHelper;
|
2020-04-26 11:36:41 +02:00
|
|
|
$this->userId = $userId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
2020-06-19 09:28:58 +02:00
|
|
|
public function index(): DataResponse {
|
2020-06-17 10:56:28 +02:00
|
|
|
$user = $this->userManager->get($this->userId);
|
|
|
|
$groupIds = $this->groupManager->getUserGroupIds($user);
|
2020-08-29 13:20:28 +02:00
|
|
|
$circleIds = $this->circleHelper->getCircleIds($this->userId);
|
2020-04-26 11:36:41 +02:00
|
|
|
|
2020-08-29 13:20:28 +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,
|
2020-08-27 17:21:34 +02:00
|
|
|
bool $record,
|
|
|
|
string $access
|
2020-04-29 11:08:49 +02:00
|
|
|
): DataResponse {
|
2020-08-27 17:21:34 +02:00
|
|
|
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,
|
2020-08-27 17:21:34 +02:00
|
|
|
$access,
|
2020-04-26 11:36:41 +02:00
|
|
|
$this->userId
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
|
|
|
public function update(
|
|
|
|
int $id,
|
|
|
|
string $name,
|
|
|
|
string $welcome,
|
|
|
|
int $maxParticipants,
|
2020-06-04 18:56:55 +02:00
|
|
|
bool $record,
|
2020-06-17 08:19:54 +02:00
|
|
|
string $access,
|
2020-08-29 14:37:50 +02:00
|
|
|
bool $everyoneIsModerator,
|
|
|
|
bool $requireModerator
|
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);
|
|
|
|
}
|
|
|
|
|
2020-08-27 17:21:34 +02:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2020-08-29 14:37:50 +02:00
|
|
|
return $this->handleNotFound(function () use ($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator, $requireModerator) {
|
|
|
|
return $this->service->update($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator, $requireModerator);
|
2020-04-26 11:36:41 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
2020-06-19 09:28:58 +02:00
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|