cloud_bbb/lib/Controller/RoomController.php

116 lines
2.5 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;
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
2020-04-29 11:08:49 +02:00
): DataResponse {
2020-04-26 11:36:41 +02:00
return new DataResponse($this->service->create(
$name,
$welcome,
$maxParticipants,
$record,
$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);
}
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
});
}
}