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)) {
|
|
|
|
return new DataResponse(null, Http::STATUS_CONFLICT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new DataResponse($this->service->create(
|
|
|
|
$groupId
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(
|
|
|
|
int $id,
|
|
|
|
string $groupId,
|
|
|
|
int $maxRooms,
|
|
|
|
array $roomTypes,
|
|
|
|
int $maxParticipants,
|
|
|
|
bool $allowRecording
|
|
|
|
): DataResponse {
|
|
|
|
return $this->handleNotFound(function () use (
|
|
|
|
$id,
|
|
|
|
$groupId,
|
|
|
|
$maxRooms,
|
|
|
|
$roomTypes,
|
|
|
|
$maxParticipants,
|
|
|
|
$allowRecording) {
|
|
|
|
return $this->service->update(
|
|
|
|
$id,
|
|
|
|
$groupId,
|
|
|
|
$maxRooms,
|
|
|
|
$roomTypes,
|
|
|
|
$maxParticipants,
|
|
|
|
$allowRecording
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(int $id): DataResponse {
|
|
|
|
return $this->handleNotFound(function () use ($id) {
|
|
|
|
$roomShare = $this->service->find($id);
|
|
|
|
|
|
|
|
return $this->service->delete($id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|