2020-04-26 11:36:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\BigBlueButton\Controller;
|
|
|
|
|
2020-08-29 13:20:28 +02:00
|
|
|
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
|
|
|
|
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)) {
|
2021-02-13 17:36:14 +01:00
|
|
|
return new DataResponse([], Http::STATUS_FORBIDDEN);
|
2020-08-27 17:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$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);
|
2020-08-27 17:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-08-27 17:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$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-08-27 17:21:34 +02:00
|
|
|
}
|
|
|
|
|
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,
|
2021-01-22 19:12:55 +01:00
|
|
|
bool $requireModerator,
|
2021-04-19 14:47:15 +02:00
|
|
|
?string $moderatorToken,
|
|
|
|
bool $listenOnly,
|
|
|
|
bool $mediaCheck,
|
2021-07-30 12:12:42 +02:00
|
|
|
bool $cleanLayout,
|
2022-03-16 18:43:44 +01:00
|
|
|
bool $joinMuted,
|
|
|
|
string $logoutURL
|
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)) {
|
2021-02-13 17:36:14 +01:00
|
|
|
return new DataResponse(['message' => 'Max participants limit exceeded.'], Http::STATUS_BAD_REQUEST);
|
2020-08-27 17:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-08-27 17:21:34 +02:00
|
|
|
}
|
|
|
|
|
2022-03-17 12:08:04 +01:00
|
|
|
if (!$restriction->getAllowLogoutURL() && $logoutURL !== $room->getLogoutURL()) {
|
2022-03-16 18:43:44 +01:00
|
|
|
return new DataResponse(['message' => 'Not allowed to enable custom logout URLs'], Https::STATUS_BAD_REQUEST);
|
|
|
|
}
|
|
|
|
|
2020-08-27 17:21:34 +02:00
|
|
|
$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);
|
2020-08-27 17:21:34 +02:00
|
|
|
}
|
|
|
|
|
2022-03-16 18:43:44 +01:00
|
|
|
return $this->handleNotFound(function () use ($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator, $requireModerator, $moderatorToken, $listenOnly, $mediaCheck, $cleanLayout, $joinMuted, $logoutURL) {
|
|
|
|
return $this->service->update($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator, $requireModerator, $moderatorToken, $listenOnly, $mediaCheck, $cleanLayout, $joinMuted, $logoutURL);
|
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)) {
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|