Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat default presentation #207

Open
wants to merge 7 commits into
base: feat-send-file
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/BigBlueButton/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private function buildMeetingParams(Room $room, Presentation $presentation = nul

if ($presentation !== null && $presentation->isValid()) {
/** @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) {
Expand Down
67 changes: 61 additions & 6 deletions lib/BigBlueButton/Presentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,80 @@

namespace OCA\BigBlueButton\BigBlueButton;

use OCA\DAV\Db\Direct;
use OCA\DAV\Db\DirectMapper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IRootFolder;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\IURLGenerator;
use OCP\Security\ISecureRandom;

class Presentation {
private $url;
private $userId;

/** @var File*/
private $file;

/** @var Folder */
private $userFolder;

/** @var DirectMapper */
private $mapper;

/** @var ISecureRandom */
private $random;

/** @var ITimeFactory */
private $timeFactory;

/** @var IURLGenerator */
private $urlGenerator;

public function __construct(
string $path,
string $userId,
IRootFolder $iRootFolder,
DirectMapper $mapper,
ISecureRandom $random,
ITimeFactory $timeFactory,
IURLGenerator $urlGenerator
) {
$this->userFolder = $iRootFolder->getUserFolder($userId);
$this->file = $this->userFolder->get($path);
$this->mapper = $mapper;
$this->random = $random;
$this->timeFactory = $timeFactory;
$this->userId = $userId;
$this->urlGenerator = $urlGenerator;
}

public function generateUrl() {
$direct = new Direct();
$direct->setUserId($this->userId);
$direct->setFileId($this->file->getId());

$token = $this->random->generate(60, ISecureRandom::CHAR_ALPHANUMERIC);
$direct->setToken($token);
$direct->setExpiration($this->timeFactory->getTime() + (60 * 60 * 8));

$this->mapper->insert($direct);

private $filename;
$url = $this->urlGenerator->getAbsoluteURL('remote.php/direct/' . $token);

public function __construct(string $url, string $filename) {
$this->url = $url;
$this->filename = preg_replace('/[^\x20-\x7E]+/','#', $filename);
return $url;
}

public function getUrl(): string {
return $this->url;
}

public function getFilename(): string {
return $this->filename;
return $this->file->getName();
}

public function isValid(): bool {
return !empty($this->url) && !empty($this->filename);
return !empty($this->file->getContent());
}
}
34 changes: 30 additions & 4 deletions lib/Controller/JoinController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
use OCA\BigBlueButton\NotFoundException;
use OCA\BigBlueButton\Permission;
use OCA\BigBlueButton\Service\RoomService;
use OCA\DAV\Db\DirectMapper;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\Files\IRootFolder;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Security\ISecureRandom;

class JoinController extends Controller {
/** @var string */
Expand All @@ -43,6 +47,18 @@ class JoinController extends Controller {
/** @var IJobList */
private $jobList;

/** @var IRootFolder */
private $iRootFolder;

/** @var DirectMapper */
private $mapper;

/** @var ISecureRandom */
private $random;

/** @var ITimeFactory */
private $timeFactory;

public function __construct(
string $appName,
IRequest $request,
Expand All @@ -51,7 +67,11 @@ public function __construct(
IUserSession $userSession,
API $api,
Permission $permission,
IJobList $jobList
IJobList $jobList,
IRootFolder $iRootFolder,
DirectMapper $mapper,
ISecureRandom $random,
ITimeFactory $timeFactory
) {
parent::__construct($appName, $request);

Expand All @@ -61,6 +81,10 @@ public function __construct(
$this->api = $api;
$this->permission = $permission;
$this->jobList = $jobList;
$this->iRootFolder = $iRootFolder;
$this->mapper = $mapper;
$this->random = $random;
$this->timeFactory = $timeFactory;
}

public function setToken(string $token): void {
Expand Down Expand Up @@ -107,8 +131,10 @@ public function index($displayname, $u = '', $filename = '', $password = '') {
throw new NoPermissionException();
}

if ($this->permission->isAdmin($room, $userId)) {
$presentation = new Presentation($u, $filename);
if ($this->permission->isAdmin($room, $userId) && !empty($filename)) {
$presentation = new Presentation($filename, $userId, $this->iRootFolder, $this->mapper, $this->random, $this->timeFactory, $this->urlGenerator);
} elseif (!$room->running && !empty($room->presentationPath)) {
$presentation = new Presentation($room->presentationPath, $room->presentationUserId, $this->iRootFolder, $this->mapper, $this->random, $this->timeFactory, $this->urlGenerator);
}
} elseif ($room->access === Room::ACCESS_INTERNAL || $room->access === Room::ACCESS_INTERNAL_RESTRICTED) {
return new RedirectResponse($this->getLoginUrl());
Expand Down Expand Up @@ -138,7 +164,7 @@ public function index($displayname, $u = '', $filename = '', $password = '') {

$this->markAsRunning($room);

\OCP\Util::addHeader('meta', ['http-equiv' => 'refresh', 'content' => '3;url='.$joinUrl]);
\OCP\Util::addHeader('meta', ['http-equiv' => 'refresh', 'content' => '3;url=' . $joinUrl]);

return new TemplateResponse($this->appName, 'forward', [
'room' => $room->name,
Expand Down
23 changes: 18 additions & 5 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\IUserManager;

class RoomController extends Controller {
use Errors;
/** @var RoomService */
private $service;

Expand All @@ -32,8 +33,6 @@ class RoomController extends Controller {
/** @var string */
private $userId;

use Errors;

public function __construct(
$appName,
IRequest $request,
Expand Down Expand Up @@ -119,7 +118,9 @@ public function update(
bool $listenOnly,
bool $mediaCheck,
bool $cleanLayout,
bool $joinMuted
bool $joinMuted,
string $presentationUserId,
string $presentationPath
): DataResponse {
$room = $this->service->find($id);

Expand All @@ -142,8 +143,20 @@ public function update(
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) {
return $this->service->update($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator, $requireModerator, $moderatorToken, $listenOnly, $mediaCheck, $cleanLayout, $joinMuted);
if ($presentationUserId != '' && $presentationUserId != $room->getPresentationUserId()) {
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);
});
}

Expand Down
4 changes: 4 additions & 0 deletions lib/Db/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class Room extends Entity implements JsonSerializable {
public $cleanLayout;
public $joinMuted;
public $running;
public $presentationUserId;
public $presentationPath;

public function __construct() {
$this->addType('maxParticipants', 'integer');
Expand Down Expand Up @@ -108,6 +110,8 @@ public function jsonSerialize(): array {
'cleanLayout' => boolval($this->cleanLayout),
'joinMuted' => boolval($this->joinMuted),
'running' => boolval($this->running),
'presentationUserId' => $this->presentationUserId,
'presentationPath' => $this->presentationPath,
];
}
}
68 changes: 68 additions & 0 deletions lib/Migration/Version000000Date20220413130357.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2022 Your name <your@email.com>
*
* @author Your name <your@email.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\BigBlueButton\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Auto-generated migration step: Please modify to your needs!
*/
class Version000000Date20220413130357 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
$schema = $schemaClosure();

if ($schema->hasTable('bbb_rooms')) {
$table = $schema->getTable('bbb_rooms');

if (!$table->hasColumn('presentation_user_id')) {
$table->addColumn('presentation_user_id', 'string', [
'notnull' => true,
'length' => 200,
]);
}

if (!$table->hasColumn('presentation_path')) {
$table->addColumn('presentation_path', 'string', [
'notnull' => false,
]);
}

return $schema;
}

return null;
}
}
13 changes: 10 additions & 3 deletions lib/Service/RoomService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use OCP\Security\ISecureRandom;

class RoomService {

/** @var RoomMapper */
private $mapper;

Expand All @@ -33,7 +32,8 @@ public function __construct(
RoomMapper $mapper,
IConfig $config,
IEventDispatcher $eventDispatcher,
ISecureRandom $random) {
ISecureRandom $random
) {
$this->mapper = $mapper;
$this->config = $config;
$this->eventDispatcher = $eventDispatcher;
Expand Down Expand Up @@ -103,6 +103,8 @@ public function create(string $name, string $welcome, int $maxParticipants, bool
$room->setMediaCheck($mediaCheck);
$room->setCleanLayout(false);
$room->setJoinMuted(false);
$room->setPresentationUserId('');
$room->setPresentationPath('');

if ($access === Room::ACCESS_PASSWORD) {
$room->setPassword($this->humanReadableRandom(8));
Expand Down Expand Up @@ -133,7 +135,10 @@ public function update(
bool $listenOnly,
bool $mediaCheck,
bool $cleanLayout,
bool $joinMuted) {
bool $joinMuted,
string $presentationUserId,
string $presentationPath
) {
try {
$room = $this->mapper->find($id);

Expand All @@ -156,6 +161,8 @@ public function update(
$room->setMediaCheck($mediaCheck);
$room->setCleanLayout($cleanLayout);
$room->setJoinMuted($joinMuted);
$room->setPresentationUserId($presentationUserId);
$room->setPresentationPath($presentationPath);

return $this->mapper->update($room);
} catch (Exception $e) {
Expand Down
3 changes: 2 additions & 1 deletion ts/Common/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export interface Room {
cleanLayout: boolean,
joinMuted: boolean,
running: boolean,
presentationUserId: string,
presentationPath: string | string[]
}

export interface RoomShare {
Expand Down Expand Up @@ -178,7 +180,6 @@ class Api {

public async updateRoom(room: Room) {
const response = await axios.put(this.getUrl(`rooms/${room.id}`), room);

return response.data;
}

Expand Down
Loading