feat: Default Presentation

added backend handling
pull/207/head
Specht, David 2022-04-15 19:45:27 +02:00
parent 1f1879013c
commit 38da9bda60
6 changed files with 78 additions and 22 deletions

View File

@ -206,7 +206,7 @@ class API {
if ($presentation !== null && $presentation->isValid()) { if ($presentation !== null && $presentation->isValid()) {
/** @psalm-suppress InvalidArgument */ /** @psalm-suppress InvalidArgument */
$createMeetingParams->addPresentation($presentation->getUrl(), null, $presentation->getFilename()); $createMeetingParams->addPresentation($presentation->generateUrl(), null, $presentation->getFilename());
} }
if ($room->access === Room::ACCESS_WAITING_ROOM || $room->access === Room::ACCESS_WAITING_ROOM_ALL) { if ($room->access === Room::ACCESS_WAITING_ROOM || $room->access === Room::ACCESS_WAITING_ROOM_ALL) {

View File

@ -2,14 +2,26 @@
namespace OCA\BigBlueButton\BigBlueButton; namespace OCA\BigBlueButton\BigBlueButton;
use OCP\Files\Storage\IStorage;
class Presentation { class Presentation {
private $url; private $url;
private $filename; private $filename;
public function __construct(string $url, string $filename) { private $path;
$this->url = $url;
$this->filename = preg_replace('/[^\x20-\x7E]+/','#', $filename); /** @var IStorage */
private $storage;
public function __construct(string $path, IStorage $storage) {
$this->storage = $storage;
$this->path = preg_replace('/^\//', '', $path);
$this->filename = preg_replace('/[^\x20-\x7E]+/','#', $path);
}
public function generateUrl(): string {
return $this->storage->getDirectDownload($this->path);
} }
public function getUrl(): string { public function getUrl(): string {
@ -21,6 +33,6 @@ class Presentation {
} }
public function isValid(): bool { public function isValid(): bool {
return !empty($this->url) && !empty($this->filename); return !empty($this->filename);
} }
} }

View File

@ -14,11 +14,13 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\IJobList;
use OCP\Files\Storage\IStorage;
use OCP\IRequest; use OCP\IRequest;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUserSession; use OCP\IUserSession;
class JoinController extends Controller { class JoinController extends Controller
{
/** @var string */ /** @var string */
protected $token; protected $token;
@ -43,6 +45,9 @@ class JoinController extends Controller {
/** @var IJobList */ /** @var IJobList */
private $jobList; private $jobList;
/** @var IStorage */
private $storage;
public function __construct( public function __construct(
string $appName, string $appName,
IRequest $request, IRequest $request,
@ -51,7 +56,8 @@ class JoinController extends Controller {
IUserSession $userSession, IUserSession $userSession,
API $api, API $api,
Permission $permission, Permission $permission,
IJobList $jobList IJobList $jobList,
IStorage $storage
) { ) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
@ -61,14 +67,17 @@ class JoinController extends Controller {
$this->api = $api; $this->api = $api;
$this->permission = $permission; $this->permission = $permission;
$this->jobList = $jobList; $this->jobList = $jobList;
$this->storage = $storage;
} }
public function setToken(string $token): void { public function setToken(string $token): void
{
$this->token = $token; $this->token = $token;
$this->room = null; $this->room = null;
} }
public function isValidToken(): bool { public function isValidToken(): bool
{
$room = $this->getRoom(); $room = $this->getRoom();
return $room !== null; return $room !== null;
@ -81,7 +90,8 @@ class JoinController extends Controller {
* *
* @return RedirectResponse|TemplateResponse * @return RedirectResponse|TemplateResponse
*/ */
public function index($displayname, $u = '', $filename = '', $password = '') { public function index($displayname, $u = '', $filename = '', $password = '')
{
$room = $this->getRoom(); $room = $this->getRoom();
if ($room === null) { if ($room === null) {
@ -108,7 +118,11 @@ class JoinController extends Controller {
} }
if ($this->permission->isAdmin($room, $userId)) { if ($this->permission->isAdmin($room, $userId)) {
$presentation = new Presentation($u, $filename); $presentation = new Presentation($filename, $this->storage);
}
if (!$room->running && $presentation === null) {
$presentation = new Presentation($room->presentationPath, $this->storage);
} }
} elseif ($room->access === Room::ACCESS_INTERNAL || $room->access === Room::ACCESS_INTERNAL_RESTRICTED) { } elseif ($room->access === Room::ACCESS_INTERNAL || $room->access === Room::ACCESS_INTERNAL_RESTRICTED) {
return new RedirectResponse($this->getLoginUrl()); return new RedirectResponse($this->getLoginUrl());
@ -146,7 +160,8 @@ class JoinController extends Controller {
], 'guest'); ], 'guest');
} }
private function getRoom(): ?Room { private function getRoom(): ?Room
{
if ($this->room === null) { if ($this->room === null) {
$this->room = $this->service->findByUid($this->token); $this->room = $this->service->findByUid($this->token);
} }
@ -154,7 +169,8 @@ class JoinController extends Controller {
return $this->room; return $this->room;
} }
private function getLoginUrl(): string { private function getLoginUrl(): string
{
return $this->urlGenerator->linkToRoute('core.login.showLoginForm', [ return $this->urlGenerator->linkToRoute('core.login.showLoginForm', [
'redirect_url' => $this->urlGenerator->linkToRoute( 'redirect_url' => $this->urlGenerator->linkToRoute(
'bbb.join.index', 'bbb.join.index',
@ -163,7 +179,8 @@ class JoinController extends Controller {
]); ]);
} }
private function markAsRunning(Room $room) { private function markAsRunning(Room $room)
{
if (!$room->running) { if (!$room->running) {
$this->service->updateRunning($room->getId(), true); $this->service->updateRunning($room->getId(), true);
} }

View File

@ -13,7 +13,8 @@ use OCP\IGroupManager;
use OCP\IRequest; use OCP\IRequest;
use OCP\IUserManager; use OCP\IUserManager;
class RoomController extends Controller { class RoomController extends Controller
{
/** @var RoomService */ /** @var RoomService */
private $service; private $service;
@ -56,7 +57,8 @@ class RoomController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function index(): DataResponse { public function index(): DataResponse
{
$user = $this->userManager->get($this->userId); $user = $this->userManager->get($this->userId);
$groupIds = $this->groupManager->getUserGroupIds($user); $groupIds = $this->groupManager->getUserGroupIds($user);
$circleIds = $this->circleHelper->getCircleIds($this->userId); $circleIds = $this->circleHelper->getCircleIds($this->userId);
@ -119,7 +121,9 @@ class RoomController extends Controller {
bool $listenOnly, bool $listenOnly,
bool $mediaCheck, bool $mediaCheck,
bool $cleanLayout, bool $cleanLayout,
bool $joinMuted bool $joinMuted,
string $presentationUserId,
string $presentationPath
): DataResponse { ): DataResponse {
$room = $this->service->find($id); $room = $this->service->find($id);
@ -142,15 +146,28 @@ class RoomController extends Controller {
return new DataResponse(['message' => 'Access type not allowed.'], Http::STATUS_BAD_REQUEST); return new DataResponse(['message' => 'Access type not allowed.'], Http::STATUS_BAD_REQUEST);
} }
return $this->handleNotFound(function () use ($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator, $requireModerator, $moderatorToken, $listenOnly, $mediaCheck, $cleanLayout, $joinMuted) { if ($presentationUserId != '' && $presentationUserId != $room->getPresentationUserId()) {
return $this->service->update($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator, $requireModerator, $moderatorToken, $listenOnly, $mediaCheck, $cleanLayout, $joinMuted); return new DataResponse(['message' => 'Not allowed to change to another user.'], Http::STATUS_BAD_REQUEST);
}
if ($presentationUserId === '') {
$presentationUserId = $this->userId;
}
if ($presentationUserId != $this->userId && $presentationPath != $room->getPresentationPath()) {
return new DataResponse(['message' => 'Not allowed to choose path of another user.'], Http::STATUS_BAD_REQUEST);
}
return $this->handleNotFound(function () use ($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator, $requireModerator, $moderatorToken, $listenOnly, $mediaCheck, $cleanLayout, $joinMuted, $presentationUserId, $presentationPath) {
return $this->service->update($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator, $requireModerator, $moderatorToken, $listenOnly, $mediaCheck, $cleanLayout, $joinMuted, $presentationUserId, $presentationPath);
}); });
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function destroy(int $id): DataResponse { public function destroy(int $id): DataResponse
{
$room = $this->service->find($id); $room = $this->service->find($id);
if (!$this->permission->isAdmin($room, $this->userId)) { if (!$this->permission->isAdmin($room, $this->userId)) {

View File

@ -74,6 +74,8 @@ class Room extends Entity implements JsonSerializable {
public $cleanLayout; public $cleanLayout;
public $joinMuted; public $joinMuted;
public $running; public $running;
public $presentationUserId;
public $presentationPath;
public function __construct() { public function __construct() {
$this->addType('maxParticipants', 'integer'); $this->addType('maxParticipants', 'integer');
@ -108,6 +110,8 @@ class Room extends Entity implements JsonSerializable {
'cleanLayout' => boolval($this->cleanLayout), 'cleanLayout' => boolval($this->cleanLayout),
'joinMuted' => boolval($this->joinMuted), 'joinMuted' => boolval($this->joinMuted),
'running' => boolval($this->running), 'running' => boolval($this->running),
'presentationUserId' => $this->presentationUserId,
'presentationPath' => $this->presentationPath,
]; ];
} }
} }

View File

@ -103,6 +103,8 @@ class RoomService {
$room->setMediaCheck($mediaCheck); $room->setMediaCheck($mediaCheck);
$room->setCleanLayout(false); $room->setCleanLayout(false);
$room->setJoinMuted(false); $room->setJoinMuted(false);
$room->setPresentationUserId('');
$room->setPresentationPath('');
if ($access === Room::ACCESS_PASSWORD) { if ($access === Room::ACCESS_PASSWORD) {
$room->setPassword($this->humanReadableRandom(8)); $room->setPassword($this->humanReadableRandom(8));
@ -133,7 +135,9 @@ class RoomService {
bool $listenOnly, bool $listenOnly,
bool $mediaCheck, bool $mediaCheck,
bool $cleanLayout, bool $cleanLayout,
bool $joinMuted) { bool $joinMuted,
string $presentationUserId,
string $presentationPath) {
try { try {
$room = $this->mapper->find($id); $room = $this->mapper->find($id);
@ -156,6 +160,8 @@ class RoomService {
$room->setMediaCheck($mediaCheck); $room->setMediaCheck($mediaCheck);
$room->setCleanLayout($cleanLayout); $room->setCleanLayout($cleanLayout);
$room->setJoinMuted($joinMuted); $room->setJoinMuted($joinMuted);
$room->setPresentationUserId($presentationUserId);
$room->setPresentationPath($presentationPath);
return $this->mapper->update($room); return $this->mapper->update($room);
} catch (Exception $e) { } catch (Exception $e) {