2020-08-27 17:21:34 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\BigBlueButton\Controller;
|
|
|
|
|
|
|
|
use OCA\BigBlueButton\Db\Restriction;
|
2020-09-23 12:33:09 +02:00
|
|
|
use OCA\BigBlueButton\Service\RestrictionService;
|
|
|
|
use OCP\AppFramework\Controller;
|
2020-08-27 17:21:34 +02:00
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
2020-09-23 12:33:09 +02:00
|
|
|
use OCP\IGroupManager;
|
|
|
|
use OCP\IRequest;
|
2020-08-27 17:21:34 +02:00
|
|
|
|
2020-09-23 12:33:09 +02:00
|
|
|
use OCP\IUserManager;
|
2020-08-27 17:21:34 +02:00
|
|
|
|
|
|
|
class RestrictionController extends Controller {
|
|
|
|
/** @var RestrictionService */
|
|
|
|
private $service;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $userId;
|
|
|
|
|
|
|
|
/** @var IUserManager */
|
|
|
|
private $userManager;
|
|
|
|
|
|
|
|
/** @var IGroupManager */
|
|
|
|
private $groupManager;
|
|
|
|
|
|
|
|
use Errors;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
$appName,
|
|
|
|
IRequest $request,
|
|
|
|
RestrictionService $service,
|
|
|
|
IUserManager $userManager,
|
|
|
|
IGroupManager $groupManager,
|
|
|
|
$userId
|
|
|
|
) {
|
|
|
|
parent::__construct($appName, $request);
|
|
|
|
$this->service = $service;
|
|
|
|
$this->userManager = $userManager;
|
|
|
|
$this->groupManager = $groupManager;
|
|
|
|
$this->userId = $userId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*/
|
|
|
|
public function user(): DataResponse {
|
|
|
|
$user = $this->userManager->get($this->userId);
|
|
|
|
$groupIds = $this->groupManager->getUserGroupIds($user);
|
|
|
|
|
|
|
|
return new DataResponse($this->service->findByGroupIds($groupIds));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index(): DataResponse {
|
|
|
|
$restrictions = $this->service->findAll();
|
|
|
|
|
|
|
|
if (!$this->service->existsByGroupId(Restriction::ALL_ID)) {
|
|
|
|
$defaultRestriction = new Restriction();
|
|
|
|
$defaultRestriction->setGroupId('');
|
|
|
|
|
|
|
|
$restrictions[] = $defaultRestriction;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new DataResponse($restrictions);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create(
|
|
|
|
string $groupId
|
|
|
|
): DataResponse {
|
|
|
|
if ($this->service->existsByGroupId($groupId)) {
|
2021-02-13 17:36:14 +01:00
|
|
|
return new DataResponse([], Http::STATUS_CONFLICT);
|
2020-08-27 17:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return new DataResponse($this->service->create(
|
|
|
|
$groupId
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(
|
|
|
|
int $id,
|
|
|
|
string $groupId,
|
|
|
|
int $maxRooms,
|
|
|
|
array $roomTypes,
|
|
|
|
int $maxParticipants,
|
2022-03-16 18:43:44 +01:00
|
|
|
bool $allowRecording,
|
|
|
|
bool $allowLogoutURL
|
2020-08-27 17:21:34 +02:00
|
|
|
): DataResponse {
|
|
|
|
return $this->handleNotFound(function () use (
|
|
|
|
$id,
|
|
|
|
$groupId,
|
|
|
|
$maxRooms,
|
|
|
|
$roomTypes,
|
|
|
|
$maxParticipants,
|
2022-03-16 18:43:44 +01:00
|
|
|
$allowRecording,
|
|
|
|
$allowLogoutURL) {
|
2020-08-27 17:21:34 +02:00
|
|
|
return $this->service->update(
|
|
|
|
$id,
|
|
|
|
$groupId,
|
|
|
|
$maxRooms,
|
|
|
|
$roomTypes,
|
|
|
|
$maxParticipants,
|
2022-03-16 18:43:44 +01:00
|
|
|
$allowRecording,
|
|
|
|
$allowLogoutURL
|
2020-08-27 17:21:34 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(int $id): DataResponse {
|
|
|
|
return $this->handleNotFound(function () use ($id) {
|
|
|
|
$roomShare = $this->service->find($id);
|
|
|
|
|
|
|
|
return $this->service->delete($id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|