refactor: use Nextcloud coding standard

pull/63/head
sualko 2020-06-19 09:28:58 +02:00
parent da9234a24f
commit 86415b3f6a
39 changed files with 324 additions and 416 deletions

View File

@ -1,13 +1,18 @@
<?php <?php
$finder = PhpCsFixer\Finder::create()
->in('lib/') declare(strict_types=1);
;
return PhpCsFixer\Config::create() require_once './vendor/autoload.php';
->setRules([
'@PSR2' => true, use Nextcloud\CodingStandard\Config;
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => false], $config = new Config();
]) $config
->setIndent("\t") ->getFinder()
->setFinder($finder) ->ignoreVCSIgnored(true)
; ->notPath('build')
->notPath('l10n')
->notPath('src')
->notPath('vendor')
->in(__DIR__);
return $config;

View File

@ -1,15 +1,15 @@
<?php <?php
OCP\Util::addScript ( 'bbb', 'filelist'); OCP\Util::addScript('bbb', 'filelist');
$apiUrl = \OC::$server->getConfig()->getAppValue('bbb', 'api.url'); $apiUrl = \OC::$server->getConfig()->getAppValue('bbb', 'api.url');
$parsedApiUrl = @parse_url($apiUrl); $parsedApiUrl = @parse_url($apiUrl);
if ($parsedApiUrl !== false) { if ($parsedApiUrl !== false) {
$manager = \OC::$server->getContentSecurityPolicyManager(); $manager = \OC::$server->getContentSecurityPolicyManager();
$policy = new \OCP\AppFramework\Http\EmptyContentSecurityPolicy(); $policy = new \OCP\AppFramework\Http\EmptyContentSecurityPolicy();
$policy->addAllowedFormActionDomain(($parsedApiUrl['scheme'] ?: 'https') . '://' . $parsedApiUrl['host']); $policy->addAllowedFormActionDomain(($parsedApiUrl['scheme'] ?: 'https') . '://' . $parsedApiUrl['host']);
$manager->addDefaultPolicy($policy); $manager->addDefaultPolicy($policy);
} }

View File

@ -1,14 +1,15 @@
<?php <?php
return [ return [
'resources' => [ 'resources' => [
'room' => ['url' => '/rooms'], 'room' => ['url' => '/rooms'],
'roomShare' => ['url' => '/roomShares'], 'roomShare' => ['url' => '/roomShares'],
], ],
'routes' => [ 'routes' => [
['name' => 'server#records', 'url' => '/server/{roomUid}/records', 'verb' => 'GET'], ['name' => 'server#records', 'url' => '/server/{roomUid}/records', 'verb' => 'GET'],
['name' => 'server#check', 'url' => '/server/check', 'verb' => 'POST'], ['name' => 'server#check', 'url' => '/server/check', 'verb' => 'POST'],
['name' => 'server#version', 'url' => '/server/version', 'verb' => 'GET'], ['name' => 'server#version', 'url' => '/server/version', 'verb' => 'GET'],
['name' => 'server#delete_record', 'url' => '/server/record/{recordId}', 'verb' => 'DELETE'], ['name' => 'server#delete_record', 'url' => '/server/record/{recordId}', 'verb' => 'DELETE'],
['name' => 'join#index', 'url' => '/b/{token}', 'verb' => 'GET'], ['name' => 'join#index', 'url' => '/b/{token}', 'verb' => 'GET'],
] ]
]; ];

View File

@ -14,7 +14,8 @@
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^8", "phpunit/phpunit": "^8",
"friendsofphp/php-cs-fixer": "^2.16" "friendsofphp/php-cs-fixer": "^2.16",
"nextcloud/coding-standard": "^0.3.0"
}, },
"config": { "config": {
"optimize-autoloader": true, "optimize-autoloader": true,

39
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "67b538bdf36cbd6464297b3d9257bb3c", "content-hash": "a5f7d2fab7db00ef99eb9468c2fa9a0a",
"packages": [ "packages": [
{ {
"name": "littleredbutton/bigbluebutton-api-php", "name": "littleredbutton/bigbluebutton-api-php",
@ -580,6 +580,43 @@
], ],
"time": "2020-01-17T21:11:47+00:00" "time": "2020-01-17T21:11:47+00:00"
}, },
{
"name": "nextcloud/coding-standard",
"version": "v0.3.0",
"source": {
"type": "git",
"url": "https://github.com/nextcloud/coding-standard.git",
"reference": "4f5cd012760f8293e19e602651a0ecaa265e4db9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/4f5cd012760f8293e19e602651a0ecaa265e4db9",
"reference": "4f5cd012760f8293e19e602651a0ecaa265e4db9",
"shasum": ""
},
"require": {
"friendsofphp/php-cs-fixer": "^2.16",
"php": "^7.2"
},
"type": "library",
"autoload": {
"psr-4": {
"Nextcloud\\CodingStandard\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Christoph Wurst",
"email": "christoph@winzerhof-wurst.at"
}
],
"description": "Nextcloud coding standards for the php cs fixer",
"time": "2020-04-10T14:57:18+00:00"
},
{ {
"name": "paragonie/random_compat", "name": "paragonie/random_compat",
"version": "v9.99.99", "version": "v9.99.99",

View File

@ -9,10 +9,8 @@ if ((@include_once __DIR__ . '/../../vendor/autoload.php') === false) {
throw new \Exception('Cannot include autoload. Did you run install dependencies using composer?'); throw new \Exception('Cannot include autoload. Did you run install dependencies using composer?');
} }
class Application extends App class Application extends App {
{ public function __construct(array $urlParams = []) {
public function __construct(array $urlParams = [])
{
parent::__construct('bbb', $urlParams); parent::__construct('bbb', $urlParams);
$container = $this->getContainer(); $container = $this->getContainer();

View File

@ -10,15 +10,11 @@ use BigBlueButton\Core\Record;
use BigBlueButton\Parameters\DeleteRecordingsParameters; use BigBlueButton\Parameters\DeleteRecordingsParameters;
use BigBlueButton\Parameters\IsMeetingRunningParameters; use BigBlueButton\Parameters\IsMeetingRunningParameters;
use OCA\BigBlueButton\Db\Room; use OCA\BigBlueButton\Db\Room;
use OCA\BigBlueButton\Db\RoomShare;
use OCA\BigBlueButton\Permission; use OCA\BigBlueButton\Permission;
use OCA\BigBlueButton\Service\RoomShareService;
use OCP\IConfig; use OCP\IConfig;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IGroupManager;
class API class API {
{
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
@ -41,8 +37,7 @@ class API
$this->permission = $permission; $this->permission = $permission;
} }
private function getServer() private function getServer() {
{
if (!$this->server) { if (!$this->server) {
$apiUrl = $this->config->getAppValue('bbb', 'api.url'); $apiUrl = $this->config->getAppValue('bbb', 'api.url');
$secret = $this->config->getAppValue('bbb', 'api.secret'); $secret = $this->config->getAppValue('bbb', 'api.secret');
@ -58,8 +53,7 @@ class API
* *
* @return string join url * @return string join url
*/ */
public function createJoinUrl(Room $room, int $creationTime, string $displayname, ?string $uid = null) public function createJoinUrl(Room $room, int $creationTime, string $displayname, ?string $uid = null) {
{
$password = $this->permission->isModerator($room, $uid) ? $room->moderatorPassword : $room->attendeePassword; $password = $this->permission->isModerator($room, $uid) ? $room->moderatorPassword : $room->attendeePassword;
$joinMeetingParams = new JoinMeetingParameters($room->uid, $displayname, $password); $joinMeetingParams = new JoinMeetingParameters($room->uid, $displayname, $password);
@ -82,8 +76,7 @@ class API
* *
* @return int creation time * @return int creation time
*/ */
public function createMeeting(Room $room, Presentation $presentation = null) public function createMeeting(Room $room, Presentation $presentation = null) {
{
$bbb = $this->getServer(); $bbb = $this->getServer();
$meetingParams = $this->buildMeetingParams($room, $presentation); $meetingParams = $this->buildMeetingParams($room, $presentation);
@ -100,8 +93,7 @@ class API
return $response->getCreationTime(); return $response->getCreationTime();
} }
private function buildMeetingParams(Room $room, Presentation $presentation = null): CreateMeetingParameters private function buildMeetingParams(Room $room, Presentation $presentation = null): CreateMeetingParameters {
{
$createMeetingParams = new CreateMeetingParameters($room->uid, $room->name); $createMeetingParams = new CreateMeetingParameters($room->uid, $room->name);
$createMeetingParams->setAttendeePassword($room->attendeePassword); $createMeetingParams->setAttendeePassword($room->attendeePassword);
$createMeetingParams->setModeratorPassword($room->moderatorPassword); $createMeetingParams->setModeratorPassword($room->moderatorPassword);
@ -131,8 +123,7 @@ class API
return $createMeetingParams; return $createMeetingParams;
} }
public function getRecording(string $recordId) public function getRecording(string $recordId) {
{
$recordingParams = new GetRecordingsParameters(); $recordingParams = new GetRecordingsParameters();
$recordingParams->setRecordId($recordId); $recordingParams->setRecordId($recordId);
$recordingParams->setState('any'); $recordingParams->setState('any');
@ -152,8 +143,7 @@ class API
return $this->recordToArray($records[0]); return $this->recordToArray($records[0]);
} }
public function getRecordings(Room $room) public function getRecordings(Room $room) {
{
$recordingParams = new GetRecordingsParameters(); $recordingParams = new GetRecordingsParameters();
$recordingParams->setMeetingId($room->uid); $recordingParams->setMeetingId($room->uid);
$recordingParams->setState('processing,processed,published,unpublished'); $recordingParams->setState('processing,processed,published,unpublished');
@ -171,8 +161,7 @@ class API
}, $records); }, $records);
} }
public function deleteRecording(string $recordingId): bool public function deleteRecording(string $recordingId): bool {
{
$deleteParams = new DeleteRecordingsParameters($recordingId); $deleteParams = new DeleteRecordingsParameters($recordingId);
$response = $this->getServer()->deleteRecordings($deleteParams); $response = $this->getServer()->deleteRecordings($deleteParams);
@ -180,8 +169,7 @@ class API
return $response->isDeleted(); return $response->isDeleted();
} }
private function recordToArray(Record $record) private function recordToArray(Record $record) {
{
return [ return [
'id' => $record->getRecordId(), 'id' => $record->getRecordId(),
'name' => $record->getName(), 'name' => $record->getName(),
@ -196,8 +184,7 @@ class API
]; ];
} }
public function check($url, $secret) public function check($url, $secret) {
{
$server = new BigBlueButton($url, $secret); $server = new BigBlueButton($url, $secret);
$meetingParams = new IsMeetingRunningParameters('foobar'); $meetingParams = new IsMeetingRunningParameters('foobar');
@ -219,8 +206,7 @@ class API
} }
} }
public function getVersion($url = null) public function getVersion($url = null) {
{
$server = $url === null ? $this->getServer() : new BigBlueButton($url, ''); $server = $url === null ? $this->getServer() : new BigBlueButton($url, '');
return $server->getApiVersion()->getVersion(); return $server->getApiVersion()->getVersion();

View File

@ -2,30 +2,25 @@
namespace OCA\BigBlueButton\BigBlueButton; namespace OCA\BigBlueButton\BigBlueButton;
class Presentation class Presentation {
{
private $url; private $url;
private $filename; private $filename;
public function __construct(string $url, string $filename) public function __construct(string $url, string $filename) {
{
$this->url = $url; $this->url = $url;
$this->filename = $filename; $this->filename = $filename;
} }
public function getUrl() public function getUrl() {
{
return $this->url; return $this->url;
} }
public function getFilename() public function getFilename() {
{
return $this->filename; return $this->filename;
} }
public function isValid() public function isValid() {
{
return !empty($this->url) && !empty($this->filename); return !empty($this->url) && !empty($this->filename);
} }
} }

View File

@ -10,10 +10,8 @@ use OCP\AppFramework\Http\DataResponse;
use OCA\BigBlueButton\Service\RoomNotFound; use OCA\BigBlueButton\Service\RoomNotFound;
use OCA\BigBlueButton\Service\RoomShareNotFound; use OCA\BigBlueButton\Service\RoomShareNotFound;
trait Errors trait Errors {
{ protected function handleNotFound(Closure $callback): DataResponse {
protected function handleNotFound(Closure $callback): DataResponse
{
try { try {
$return = $callback(); $return = $callback();
return ($return instanceof DataResponse) ? $return : new DataResponse($return); return ($return instanceof DataResponse) ? $return : new DataResponse($return);

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OCA\BigBlueButton\Controller; namespace OCA\BigBlueButton\Controller;
use OCA\BigBlueButton\BigBlueButton\API; use OCA\BigBlueButton\BigBlueButton\API;
@ -17,8 +18,7 @@ use OCA\BigBlueButton\Service\RoomService;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
class JoinController extends Controller class JoinController extends Controller {
{
/** @var string */ /** @var string */
protected $token; protected $token;
@ -64,14 +64,12 @@ class JoinController extends Controller
$this->permission = $permission; $this->permission = $permission;
} }
public function setToken(string $token) public function setToken(string $token) {
{
$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,8 +79,7 @@ class JoinController extends Controller
* @PublicPage * @PublicPage
* @NoCSRFRequired * @NoCSRFRequired
*/ */
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) {
@ -133,8 +130,7 @@ class JoinController extends Controller
return new RedirectResponse($joinUrl); return new RedirectResponse($joinUrl);
} }
private function addFormActionDomain($response) private function addFormActionDomain($response) {
{
$apiUrl = $this->config->getAppValue($this->appName, 'api.url'); $apiUrl = $this->config->getAppValue($this->appName, 'api.url');
$parsedApiUrl = parse_url($apiUrl); $parsedApiUrl = parse_url($apiUrl);
@ -145,8 +141,7 @@ class JoinController extends Controller
$response->getContentSecurityPolicy()->addAllowedFormActionDomain(($parsedApiUrl['scheme'] ?: 'https') . '://' . $parsedApiUrl['host']); $response->getContentSecurityPolicy()->addAllowedFormActionDomain(($parsedApiUrl['scheme'] ?: 'https') . '://' . $parsedApiUrl['host']);
} }
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);
} }

View File

@ -11,8 +11,7 @@ use OCP\AppFramework\Controller;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IUserManager; use OCP\IUserManager;
class RoomController extends Controller class RoomController extends Controller {
{
/** @var RoomService */ /** @var RoomService */
private $service; private $service;
@ -50,8 +49,7 @@ 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);
@ -102,8 +100,7 @@ class RoomController extends Controller
/** /**
* @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

@ -13,8 +13,7 @@ use OCP\AppFramework\Controller;
use OCA\BigBlueButton\Service\RoomShareService; use OCA\BigBlueButton\Service\RoomShareService;
use OCP\IUserManager; use OCP\IUserManager;
class RoomShareController extends Controller class RoomShareController extends Controller {
{
/** @var RoomShareService */ /** @var RoomShareService */
private $service; private $service;
@ -47,8 +46,7 @@ class RoomShareController extends Controller
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function index(): DataResponse public function index(): DataResponse {
{
$roomId = $this->request->getParam('id'); $roomId = $this->request->getParam('id');
if ($roomId === null) { if ($roomId === null) {
@ -127,8 +125,7 @@ class RoomShareController extends Controller
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function destroy(int $id): DataResponse public function destroy(int $id): DataResponse {
{
return $this->handleNotFound(function () use ($id) { return $this->handleNotFound(function () use ($id) {
$roomShare = $this->service->find($id); $roomShare = $this->service->find($id);
@ -140,8 +137,7 @@ class RoomShareController extends Controller
}); });
} }
private function isUserAllowed(int $roomId): bool private function isUserAllowed(int $roomId): bool {
{
try { try {
$room = $this->roomService->find($roomId); $room = $this->roomService->find($roomId);

View File

@ -11,8 +11,7 @@ use OCP\AppFramework\Controller;
use OCA\BigBlueButton\Service\RoomService; use OCA\BigBlueButton\Service\RoomService;
class ServerController extends Controller class ServerController extends Controller {
{
/** @var RoomService */ /** @var RoomService */
private $service; private $service;
@ -42,10 +41,9 @@ class ServerController extends Controller
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function records(string $roomUid): DataResponse public function records(string $roomUid): DataResponse {
{
$room = $this->service->findByUid($roomUid); $room = $this->service->findByUid($roomUid);
if ($room === null) { if ($room === null) {
@ -62,10 +60,9 @@ class ServerController extends Controller
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function deleteRecord(string $recordId): DataResponse public function deleteRecord(string $recordId): DataResponse {
{
$record = $this->server->getRecording($recordId); $record = $this->server->getRecording($recordId);
$room = $this->service->findByUid($record['metas']['meetingId']); $room = $this->service->findByUid($record['metas']['meetingId']);
@ -83,8 +80,7 @@ class ServerController extends Controller
return new DataResponse($success); return new DataResponse($success);
} }
public function check(string $url, string $secret) public function check(string $url, string $secret) {
{
if ($url === null || empty($url) || $secret === null || empty($secret)) { if ($url === null || empty($url) || $secret === null || empty($secret)) {
return new DataResponse(false); return new DataResponse(false);
} }
@ -92,8 +88,7 @@ class ServerController extends Controller
return new DataResponse($this->server->check($url, $secret)); return new DataResponse($this->server->check($url, $secret));
} }
public function version(string $url) public function version(string $url) {
{
if ($url === null || empty($url)) { if ($url === null || empty($url)) {
return new DataResponse(false, Http::STATUS_NOT_FOUND); return new DataResponse(false, Http::STATUS_NOT_FOUND);
} }

View File

@ -1,17 +1,17 @@
<?php <?php
namespace OCA\BigBlueButton\Db; namespace OCA\BigBlueButton\Db;
use JsonSerializable; use JsonSerializable;
use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\Entity;
class Room extends Entity implements JsonSerializable class Room extends Entity implements JsonSerializable {
{ public const ACCESS_PUBLIC = 'public';
const ACCESS_PUBLIC = 'public'; public const ACCESS_PASSWORD = 'password';
const ACCESS_PASSWORD = 'password'; public const ACCESS_WAITING_ROOM = 'waiting_room';
const ACCESS_WAITING_ROOM = 'waiting_room'; public const ACCESS_INTERNAL = 'internal';
const ACCESS_INTERNAL = 'internal'; public const ACCESS_INTERNAL_RESTRICTED = 'internal_restricted';
const ACCESS_INTERNAL_RESTRICTED = 'internal_restricted';
public $uid; public $uid;
public $name; public $name;
@ -25,15 +25,13 @@ class Room extends Entity implements JsonSerializable
public $password; public $password;
public $everyoneIsModerator; public $everyoneIsModerator;
public function __construct() public function __construct() {
{
$this->addType('maxParticipants', 'integer'); $this->addType('maxParticipants', 'integer');
$this->addType('record', 'boolean'); $this->addType('record', 'boolean');
$this->addType('everyoneIsModerator', 'boolean'); $this->addType('everyoneIsModerator', 'boolean');
} }
public function jsonSerialize(): array public function jsonSerialize(): array {
{
return [ return [
'id' => $this->id, 'id' => $this->id,
'uid' => $this->uid, 'uid' => $this->uid,

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OCA\BigBlueButton\Db; namespace OCA\BigBlueButton\Db;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
@ -7,10 +8,8 @@ use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection; use OCP\IDBConnection;
class RoomMapper extends QBMapper class RoomMapper extends QBMapper {
{ public function __construct(IDBConnection $db) {
public function __construct(IDBConnection $db)
{
parent::__construct($db, 'bbb_rooms', Room::class); parent::__construct($db, 'bbb_rooms', Room::class);
} }
@ -21,8 +20,7 @@ class RoomMapper extends QBMapper
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException * @throws DoesNotExistException
*/ */
public function find(int $id): Room public function find(int $id): Room {
{
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('*')
@ -37,8 +35,7 @@ class RoomMapper extends QBMapper
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException * @throws DoesNotExistException
*/ */
public function findByUid(string $uid): Room public function findByUid(string $uid): Room {
{
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('*')
@ -52,8 +49,7 @@ class RoomMapper extends QBMapper
* @param array $groupIds * @param array $groupIds
* @return array * @return array
*/ */
public function findAll(string $userId, array $groupIds): array public function findAll(string $userId, array $groupIds): array {
{
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('r.*') $qb->select('r.*')

View File

@ -1,18 +1,18 @@
<?php <?php
namespace OCA\BigBlueButton\Db; namespace OCA\BigBlueButton\Db;
use JsonSerializable; use JsonSerializable;
use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\Entity;
class RoomShare extends Entity implements JsonSerializable class RoomShare extends Entity implements JsonSerializable {
{ public const PERMISSION_ADMIN = 0;
const PERMISSION_ADMIN = 0; public const PERMISSION_MODERATOR = 1;
const PERMISSION_MODERATOR = 1; public const PERMISSION_USER = 2;
const PERMISSION_USER = 2;
const SHARE_TYPE_USER = 0; public const SHARE_TYPE_USER = 0;
const SHARE_TYPE_GROUP = 1; public const SHARE_TYPE_GROUP = 1;
protected $roomId; protected $roomId;
protected $shareType; protected $shareType;
@ -20,15 +20,13 @@ class RoomShare extends Entity implements JsonSerializable
protected $shareWithDisplayName; protected $shareWithDisplayName;
protected $permission; protected $permission;
public function __construct() public function __construct() {
{
$this->addType('roomId', 'integer'); $this->addType('roomId', 'integer');
$this->addType('shareType', 'integer'); $this->addType('shareType', 'integer');
$this->addType('permission', 'integer'); $this->addType('permission', 'integer');
} }
public function jsonSerialize(): array public function jsonSerialize(): array {
{
return [ return [
'id' => $this->id, 'id' => $this->id,
'roomId' => $this->roomId, 'roomId' => $this->roomId,
@ -39,18 +37,15 @@ class RoomShare extends Entity implements JsonSerializable
]; ];
} }
public function hasUserPermission(): bool public function hasUserPermission(): bool {
{
return $this->permission === self::PERMISSION_ADMIN || $this->permission === self::PERMISSION_MODERATOR || $this->permission === self::PERMISSION_USER; return $this->permission === self::PERMISSION_ADMIN || $this->permission === self::PERMISSION_MODERATOR || $this->permission === self::PERMISSION_USER;
} }
public function hasModeratorPermission(): bool public function hasModeratorPermission(): bool {
{
return $this->permission === self::PERMISSION_ADMIN || $this->permission === self::PERMISSION_MODERATOR; return $this->permission === self::PERMISSION_ADMIN || $this->permission === self::PERMISSION_MODERATOR;
} }
public function hasAdminPermission(): bool public function hasAdminPermission(): bool {
{
return $this->permission === self::PERMISSION_ADMIN; return $this->permission === self::PERMISSION_ADMIN;
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OCA\BigBlueButton\Db; namespace OCA\BigBlueButton\Db;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
@ -7,10 +8,8 @@ use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection; use OCP\IDBConnection;
class RoomShareMapper extends QBMapper class RoomShareMapper extends QBMapper {
{ public function __construct(IDBConnection $db) {
public function __construct(IDBConnection $db)
{
parent::__construct($db, 'bbb_room_shares', RoomShare::class); parent::__construct($db, 'bbb_room_shares', RoomShare::class);
} }
@ -20,8 +19,7 @@ class RoomShareMapper extends QBMapper
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws DoesNotExistException * @throws DoesNotExistException
*/ */
public function find(int $id): RoomShare public function find(int $id): RoomShare {
{
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('*')
@ -30,8 +28,7 @@ class RoomShareMapper extends QBMapper
return $this->findEntity($qb); return $this->findEntity($qb);
} }
public function findByRoomAndEntity(int $roomId, string $shareWith, int $shareType): RoomShare public function findByRoomAndEntity(int $roomId, string $shareWith, int $shareType): RoomShare {
{
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('*')
@ -43,8 +40,7 @@ class RoomShareMapper extends QBMapper
return $this->findEntity($qb); return $this->findEntity($qb);
} }
public function findAll(int $roomId): array public function findAll(int $roomId): array {
{
/* @var $qb IQueryBuilder */ /* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
$qb->select('*') $qb->select('*')

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OCA\BigBlueButton\Middleware; namespace OCA\BigBlueButton\Middleware;
use OCA\BigBlueButton\Controller\JoinController; use OCA\BigBlueButton\Controller\JoinController;
@ -9,18 +10,15 @@ use OCP\AppFramework\Middleware;
use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\NotFoundResponse;
use OCP\IRequest; use OCP\IRequest;
class JoinMiddleware extends Middleware class JoinMiddleware extends Middleware {
{
/** @var IRequest */ /** @var IRequest */
private $request; private $request;
public function __construct(IRequest $request) public function __construct(IRequest $request) {
{
$this->request = $request; $this->request = $request;
} }
public function beforeController($controller, $methodName) public function beforeController($controller, $methodName) {
{
if (!($controller instanceof JoinController)) { if (!($controller instanceof JoinController)) {
return; return;
} }
@ -39,8 +37,7 @@ class JoinMiddleware extends Middleware
throw new NotFoundException(); throw new NotFoundException();
} }
public function afterException($controller, $methodName, \Exception $exception) public function afterException($controller, $methodName, \Exception $exception) {
{
if (!($controller instanceof JoinController)) { if (!($controller instanceof JoinController)) {
throw $exception; throw $exception;
} }

View File

@ -9,8 +9,7 @@ use OCP\DB\ISchemaWrapper;
use OCP\Migration\SimpleMigrationStep; use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput; use OCP\Migration\IOutput;
class Version000000Date20200416124731 extends SimpleMigrationStep class Version000000Date20200416124731 extends SimpleMigrationStep {
{
/** /**
* @param IOutput $output * @param IOutput $output
@ -18,8 +17,7 @@ class Version000000Date20200416124731 extends SimpleMigrationStep
* @param array $options * @param array $options
* @return null|ISchemaWrapper * @return null|ISchemaWrapper
*/ */
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
{
/** @var ISchemaWrapper $schema */ /** @var ISchemaWrapper $schema */
$schema = $schemaClosure(); $schema = $schemaClosure();

View File

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

View File

@ -9,8 +9,7 @@ use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput; use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep; use OCP\Migration\SimpleMigrationStep;
class Version000000Date20200613111242 extends SimpleMigrationStep class Version000000Date20200613111242 extends SimpleMigrationStep {
{
/** /**
* @param IOutput $output * @param IOutput $output
@ -18,8 +17,7 @@ class Version000000Date20200613111242 extends SimpleMigrationStep
* @param array $options * @param array $options
* @return null|ISchemaWrapper * @return null|ISchemaWrapper
*/ */
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
{
/** @var ISchemaWrapper $schema */ /** @var ISchemaWrapper $schema */
$schema = $schemaClosure(); $schema = $schemaClosure();

View File

@ -9,8 +9,7 @@ use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput; use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep; use OCP\Migration\SimpleMigrationStep;
class Version000000Date20200617055735 extends SimpleMigrationStep class Version000000Date20200617055735 extends SimpleMigrationStep {
{
/** /**
* @param IOutput $output * @param IOutput $output
@ -18,8 +17,7 @@ class Version000000Date20200617055735 extends SimpleMigrationStep
* @param array $options * @param array $options
* @return null|ISchemaWrapper * @return null|ISchemaWrapper
*/ */
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
{
/** @var ISchemaWrapper $schema */ /** @var ISchemaWrapper $schema */
$schema = $schemaClosure(); $schema = $schemaClosure();

View File

@ -2,6 +2,5 @@
namespace OCA\BigBlueButton; namespace OCA\BigBlueButton;
class NoPermissionException extends \Exception class NoPermissionException extends \Exception {
{
} }

View File

@ -1,22 +1,20 @@
<?php <?php
namespace OCA\BigBlueButton; namespace OCA\BigBlueButton;
use OCP\Template; use OCP\Template;
use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\ContentSecurityPolicy;
class NoPermissionResponse extends Response class NoPermissionResponse extends Response {
{ public function __construct() {
public function __construct()
{
parent::__construct(); parent::__construct();
$this->setContentSecurityPolicy(new ContentSecurityPolicy()); $this->setContentSecurityPolicy(new ContentSecurityPolicy());
$this->setStatus(404); $this->setStatus(404);
} }
public function render() public function render() {
{
$template = new Template('core', '403', 'guest'); $template = new Template('core', '403', 'guest');
return $template->fetchPage(); return $template->fetchPage();
} }

View File

@ -2,6 +2,5 @@
namespace OCA\BigBlueButton; namespace OCA\BigBlueButton;
class NotFoundException extends \Exception class NotFoundException extends \Exception {
{
} }

View File

@ -8,8 +8,7 @@ use OCA\BigBlueButton\Db\Room;
use OCA\BigBlueButton\Db\RoomShare; use OCA\BigBlueButton\Db\RoomShare;
use OCP\IGroupManager; use OCP\IGroupManager;
class Permission class Permission {
{
/** @var IGroupManager */ /** @var IGroupManager */
private $groupManager; private $groupManager;
@ -25,15 +24,13 @@ class Permission
$this->roomShareService = $roomShareService; $this->roomShareService = $roomShareService;
} }
public function isUser(Room $room, ?string $uid) public function isUser(Room $room, ?string $uid) {
{
return $this->hasPermission($room, $uid, function (RoomShare $share) { return $this->hasPermission($room, $uid, function (RoomShare $share) {
return $share->hasUserPermission(); return $share->hasUserPermission();
}); });
} }
public function isModerator(Room $room, ?string $uid) public function isModerator(Room $room, ?string $uid) {
{
if ($room->everyoneIsModerator) { if ($room->everyoneIsModerator) {
return true; return true;
} }
@ -43,15 +40,13 @@ class Permission
}); });
} }
public function isAdmin(Room $room, ?string $uid) public function isAdmin(Room $room, ?string $uid) {
{
return $this->hasPermission($room, $uid, function (RoomShare $share) { return $this->hasPermission($room, $uid, function (RoomShare $share) {
return $share->hasAdminPermission(); return $share->hasAdminPermission();
}); });
} }
private function hasPermission(Room $room, ?string $uid, Closure $hasPermission): bool private function hasPermission(Room $room, ?string $uid, Closure $hasPermission): bool {
{
if ($uid === null) { if ($uid === null) {
return false; return false;
} }

View File

@ -2,6 +2,5 @@
namespace OCA\BigBlueButton\Service; namespace OCA\BigBlueButton\Service;
class RoomNotFound extends \Exception class RoomNotFound extends \Exception {
{
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OCA\BigBlueButton\Service; namespace OCA\BigBlueButton\Service;
use Exception; use Exception;
@ -8,26 +9,21 @@ use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCA\BigBlueButton\Db\Room; use OCA\BigBlueButton\Db\Room;
use OCA\BigBlueButton\Db\RoomMapper; use OCA\BigBlueButton\Db\RoomMapper;
use OCA\BigBlueButton\NoPermissionException;
class RoomService class RoomService {
{
/** @var RoomMapper */ /** @var RoomMapper */
private $mapper; private $mapper;
public function __construct(RoomMapper $mapper) public function __construct(RoomMapper $mapper) {
{
$this->mapper = $mapper; $this->mapper = $mapper;
} }
public function findAll(string $userId, array $groupIds): array public function findAll(string $userId, array $groupIds): array {
{
return $this->mapper->findAll($userId, $groupIds); return $this->mapper->findAll($userId, $groupIds);
} }
private function handleException(Exception $e): void private function handleException(Exception $e): void {
{
if ($e instanceof DoesNotExistException || if ($e instanceof DoesNotExistException ||
$e instanceof MultipleObjectsReturnedException) { $e instanceof MultipleObjectsReturnedException) {
throw new RoomNotFound($e->getMessage()); throw new RoomNotFound($e->getMessage());
@ -36,8 +32,7 @@ class RoomService
} }
} }
public function find($id): Room public function find($id): Room {
{
try { try {
return $this->mapper->find($id); return $this->mapper->find($id);
@ -50,8 +45,7 @@ class RoomService
} }
} }
public function findByUid($uid) public function findByUid($uid) {
{
try { try {
return $this->mapper->findByUid($uid); return $this->mapper->findByUid($uid);
} catch (Exception $e) { } catch (Exception $e) {
@ -60,8 +54,7 @@ class RoomService
} }
} }
public function create($name, $welcome, $maxParticipants, $record, $userId) public function create($name, $welcome, $maxParticipants, $record, $userId) {
{
$room = new Room(); $room = new Room();
$room->setUid(\OC::$server->getSecureRandom()->generate(16, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE)); $room->setUid(\OC::$server->getSecureRandom()->generate(16, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE));
@ -76,8 +69,7 @@ class RoomService
return $this->mapper->insert($room); return $this->mapper->insert($room);
} }
public function update($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator) public function update($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator) {
{
try { try {
$room = $this->mapper->find($id); $room = $this->mapper->find($id);
@ -98,8 +90,7 @@ class RoomService
} }
} }
public function delete($id) public function delete($id) {
{
try { try {
$room = $this->mapper->find($id); $room = $this->mapper->find($id);
$this->mapper->delete($room); $this->mapper->delete($room);
@ -109,8 +100,7 @@ class RoomService
} }
} }
private function humanReadableRandom($length) private function humanReadableRandom($length) {
{
return \OC::$server->getSecureRandom()->generate($length, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE); return \OC::$server->getSecureRandom()->generate($length, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE);
} }
} }

View File

@ -2,6 +2,5 @@
namespace OCA\BigBlueButton\Service; namespace OCA\BigBlueButton\Service;
class RoomShareNotFound extends \Exception class RoomShareNotFound extends \Exception {
{
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OCA\BigBlueButton\Service; namespace OCA\BigBlueButton\Service;
use Exception; use Exception;
@ -9,24 +10,20 @@ use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCA\BigBlueButton\Db\RoomShare; use OCA\BigBlueButton\Db\RoomShare;
use OCA\BigBlueButton\Db\RoomShareMapper; use OCA\BigBlueButton\Db\RoomShareMapper;
class RoomShareService class RoomShareService {
{
/** @var RoomShareMapper */ /** @var RoomShareMapper */
private $mapper; private $mapper;
public function __construct(RoomShareMapper $mapper) public function __construct(RoomShareMapper $mapper) {
{
$this->mapper = $mapper; $this->mapper = $mapper;
} }
public function findAll(int $roomId): array public function findAll(int $roomId): array {
{
return $this->mapper->findAll($roomId); return $this->mapper->findAll($roomId);
} }
private function handleException(Exception $e): void private function handleException(Exception $e): void {
{
if ($e instanceof DoesNotExistException || if ($e instanceof DoesNotExistException ||
$e instanceof MultipleObjectsReturnedException) { $e instanceof MultipleObjectsReturnedException) {
throw new RoomShareNotFound($e->getMessage()); throw new RoomShareNotFound($e->getMessage());
@ -35,8 +32,7 @@ class RoomShareService
} }
} }
public function find($id): RoomShare public function find($id): RoomShare {
{
try { try {
return $this->mapper->find($id); return $this->mapper->find($id);
} catch (Exception $e) { } catch (Exception $e) {
@ -44,8 +40,7 @@ class RoomShareService
} }
} }
public function create(int $roomId, int $shareType, string $shareWith, int $permission): RoomShare public function create(int $roomId, int $shareType, string $shareWith, int $permission): RoomShare {
{
try { try {
$roomShare = $this->mapper->findByRoomAndEntity($roomId, $shareWith, $shareType); $roomShare = $this->mapper->findByRoomAndEntity($roomId, $shareWith, $shareType);
@ -62,8 +57,7 @@ class RoomShareService
} }
} }
public function update(int $id, int $roomId, int $shareType, string $shareWith, int $permission): RoomShare public function update(int $id, int $roomId, int $shareType, string $shareWith, int $permission): RoomShare {
{
try { try {
$roomShare = $this->mapper->find($id); $roomShare = $this->mapper->find($id);
@ -78,8 +72,7 @@ class RoomShareService
} }
} }
public function delete(int $id): RoomShare public function delete(int $id): RoomShare {
{
try { try {
$roomShare = $this->mapper->find($id); $roomShare = $this->mapper->find($id);
$this->mapper->delete($roomShare); $this->mapper->delete($roomShare);

View File

@ -1,12 +1,12 @@
<?php <?php
namespace OCA\BigBlueButton\Settings; namespace OCA\BigBlueButton\Settings;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig; use OCP\IConfig;
use OCP\Settings\ISettings; use OCP\Settings\ISettings;
class Admin implements ISettings class Admin implements ISettings {
{
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
@ -16,20 +16,18 @@ class Admin implements ISettings
* *
* @param IConfig $config * @param IConfig $config
*/ */
public function __construct(IConfig $config) public function __construct(IConfig $config) {
{
$this->config = $config; $this->config = $config;
} }
/** /**
* @return TemplateResponse * @return TemplateResponse
*/ */
public function getForm() public function getForm() {
{
$parameters = [ $parameters = [
'api.url' => $this->config->getAppValue('bbb', 'api.url'), 'api.url' => $this->config->getAppValue('bbb', 'api.url'),
'api.secret' => $this->config->getAppValue('bbb', 'api.secret'), 'api.secret' => $this->config->getAppValue('bbb', 'api.secret'),
]; ];
return new TemplateResponse('bbb', 'admin', $parameters); return new TemplateResponse('bbb', 'admin', $parameters);
} }
@ -37,8 +35,7 @@ class Admin implements ISettings
/** /**
* @return string the section ID, e.g. 'sharing' * @return string the section ID, e.g. 'sharing'
*/ */
public function getSection() public function getSection() {
{
return 'additional'; return 'additional';
} }
@ -47,8 +44,7 @@ class Admin implements ISettings
* the admin section. The forms are arranged in ascending order of the * the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100. * priority values. It is required to return a value between 0 and 100.
*/ */
public function getPriority() public function getPriority() {
{
return 50; return 50;
} }
} }

View File

@ -7,8 +7,7 @@ use OCP\Settings\ISettings;
use OCP\IConfig; use OCP\IConfig;
use \OCP\IL10N; use \OCP\IL10N;
class Personal implements ISettings class Personal implements ISettings {
{
/** @var IConfig */ /** @var IConfig */
private $config; private $config;
@ -20,8 +19,7 @@ class Personal implements ISettings
* *
* @param IConfig $config * @param IConfig $config
*/ */
public function __construct(IConfig $config, IL10N $l) public function __construct(IConfig $config, IL10N $l) {
{
$this->config = $config; $this->config = $config;
$this->l = $l; $this->l = $l;
} }
@ -29,8 +27,7 @@ class Personal implements ISettings
/** /**
* @return TemplateResponse * @return TemplateResponse
*/ */
public function getForm() public function getForm() {
{
$warning = ''; $warning = '';
if (empty($this->config->getAppValue('bbb', 'api.url')) || empty($this->config->getAppValue('bbb', 'api.secret'))) { if (empty($this->config->getAppValue('bbb', 'api.url')) || empty($this->config->getAppValue('bbb', 'api.secret'))) {
@ -43,8 +40,7 @@ class Personal implements ISettings
/** /**
* @return string the section ID, e.g. 'sharing' * @return string the section ID, e.g. 'sharing'
*/ */
public function getSection() public function getSection() {
{
return 'bbb'; return 'bbb';
} }
@ -55,8 +51,7 @@ class Personal implements ISettings
* *
* E.g.: 70 * E.g.: 70
*/ */
public function getPriority() public function getPriority() {
{
return 50; return 50;
} }
} }

View File

@ -6,15 +6,13 @@ use OCP\IL10N;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\Settings\IIconSection; use OCP\Settings\IIconSection;
class Section implements IIconSection class Section implements IIconSection {
{
/** @var IL10N */ /** @var IL10N */
private $l; private $l;
/** @var IURLGenerator */ /** @var IURLGenerator */
private $url; private $url;
public function __construct(IL10N $l, IURLGenerator $url) public function __construct(IL10N $l, IURLGenerator $url) {
{
$this->l = $l; $this->l = $l;
$this->url = $url; $this->url = $url;
} }
@ -25,8 +23,7 @@ class Section implements IIconSection
* *
* @returns string * @returns string
*/ */
public function getID() public function getID() {
{
return 'bbb'; return 'bbb';
} }
@ -36,8 +33,7 @@ class Section implements IIconSection
* *
* @return string * @return string
*/ */
public function getName() public function getName() {
{
return "BigBlueButton"; return "BigBlueButton";
} }
@ -48,16 +44,14 @@ class Section implements IIconSection
* *
* E.g.: 70 * E.g.: 70
*/ */
public function getPriority() public function getPriority() {
{
return 50; return 50;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getIcon() public function getIcon() {
{
return $this->url->imagePath('bbb', 'app-dark.svg'); return $this->url->imagePath('bbb', 'app-dark.svg');
} }
} }

View File

@ -4,7 +4,7 @@ script('bbb', 'manager');
<div id="bbb-root"></div> <div id="bbb-root"></div>
<?php if(!empty($_['warning'])): ?> <?php if (!empty($_['warning'])): ?>
<div id="bbb-warning"> <div id="bbb-warning">
<span class="icon icon-error-color icon-visible"></span> <?php p($_['warning']); ?> <span class="icon icon-error-color icon-visible"></span> <?php p($_['warning']); ?>
</div> </div>

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OCA\BigBlueButton\Tests\Integration\Db; namespace OCA\BigBlueButton\Tests\Integration\Db;
use OC; use OC;
@ -10,132 +11,124 @@ use PHPUnit\Framework\TestCase;
use OCP\IDBConnection; use OCP\IDBConnection;
class RoomMapperTest extends TestCase { class RoomMapperTest extends TestCase {
/** @var IDBConnection */ /** @var IDBConnection */
private $db; private $db;
/** @var RoomMapper */ /** @var RoomMapper */
private $mapper; private $mapper;
/** @var RoomShareMapper */ /** @var RoomShareMapper */
private $shareMapper; private $shareMapper;
/** @var string */ /** @var string */
private $userId; private $userId;
/** @var string */ /** @var string */
private $uid; private $uid;
public function setUp(): void public function setUp(): void {
{
parent::setUp(); parent::setUp();
$this->db = OC::$server->getDatabaseConnection(); $this->db = OC::$server->getDatabaseConnection();
$this->mapper = new RoomMapper($this->db); $this->mapper = new RoomMapper($this->db);
$this->shareMapper = new RoomShareMapper($this->db); $this->shareMapper = new RoomShareMapper($this->db);
$this->userId = $this->getRandomString(); $this->userId = $this->getRandomString();
$this->uid = $this->getRandomString(); $this->uid = $this->getRandomString();
} }
public function testInsert() public function testInsert() {
{ $room = $this->insert($this->uid, $this->userId);
$room = $this->insert($this->uid, $this->userId);
$this->assertEquals($this->uid, $room->getUid()); $this->assertEquals($this->uid, $room->getUid());
$this->mapper->delete($room); $this->mapper->delete($room);
} }
/** /**
* @depends testInsert * @depends testInsert
*/ */
public function testFind() public function testFind() {
{ $newRoom = $this->insert($this->uid, $this->userId);
$newRoom = $this->insert($this->uid, $this->userId);
$room = $this->mapper->find($newRoom->getId()); $room = $this->mapper->find($newRoom->getId());
$this->assertEquals($this->uid, $room->getUid()); $this->assertEquals($this->uid, $room->getUid());
$this->mapper->delete($room); $this->mapper->delete($room);
} }
/** /**
* @depends testInsert * @depends testInsert
*/ */
public function testFindByUid() public function testFindByUid() {
{ $newRoom = $this->insert($this->uid, $this->userId);
$newRoom = $this->insert($this->uid, $this->userId);
$room = $this->mapper->findByUid($this->uid); $room = $this->mapper->findByUid($this->uid);
$this->assertEquals($newRoom->getId(), $room->getId()); $this->assertEquals($newRoom->getId(), $room->getId());
$this->mapper->delete($room); $this->mapper->delete($room);
} }
/** /**
* @depends testInsert * @depends testInsert
*/ */
public function testFindAll() public function testFindAll() {
{ $room = $this->insert($this->uid, $this->userId);
$room = $this->insert($this->uid, $this->userId);
$foreignRoom1 = $this->insert($this->getRandomString(), $this->getRandomString()); $foreignRoom1 = $this->insert($this->getRandomString(), $this->getRandomString());
$foreignRoom2 = $this->insert($this->getRandomString(), $this->getRandomString()); $foreignRoom2 = $this->insert($this->getRandomString(), $this->getRandomString());
$foreignRoom3 = $this->insert($this->getRandomString(), $this->getRandomString()); $foreignRoom3 = $this->insert($this->getRandomString(), $this->getRandomString());
$this->assertCount(1, $this->mapper->findAll($this->userId, [])); $this->assertCount(1, $this->mapper->findAll($this->userId, []));
$shares = []; $shares = [];
$shares[] = $this->insertShare($foreignRoom1->getId(), RoomShare::SHARE_TYPE_USER, $this->userId); $shares[] = $this->insertShare($foreignRoom1->getId(), RoomShare::SHARE_TYPE_USER, $this->userId);
$shares[] = $this->insertShare($foreignRoom1->getId(), RoomShare::SHARE_TYPE_GROUP, 'foo bar'); $shares[] = $this->insertShare($foreignRoom1->getId(), RoomShare::SHARE_TYPE_GROUP, 'foo bar');
$shares[] = $this->insertShare($foreignRoom2->getId(), RoomShare::SHARE_TYPE_GROUP, 'foo bar'); $shares[] = $this->insertShare($foreignRoom2->getId(), RoomShare::SHARE_TYPE_GROUP, 'foo bar');
$shares[] = $this->insertShare($foreignRoom3->getId(), RoomShare::SHARE_TYPE_USER, $this->getRandomString()); $shares[] = $this->insertShare($foreignRoom3->getId(), RoomShare::SHARE_TYPE_USER, $this->getRandomString());
$shares[] = $this->insertShare($foreignRoom3->getId(), RoomShare::SHARE_TYPE_USER, $this->userId, RoomShare::PERMISSION_MODERATOR); $shares[] = $this->insertShare($foreignRoom3->getId(), RoomShare::SHARE_TYPE_USER, $this->userId, RoomShare::PERMISSION_MODERATOR);
$shares[] = $this->insertShare($foreignRoom3->getId(), RoomShare::SHARE_TYPE_GROUP, 'foo bar', RoomShare::PERMISSION_USER); $shares[] = $this->insertShare($foreignRoom3->getId(), RoomShare::SHARE_TYPE_GROUP, 'foo bar', RoomShare::PERMISSION_USER);
$rooms = $this->mapper->findAll($this->userId, ['foo bar']); $rooms = $this->mapper->findAll($this->userId, ['foo bar']);
$this->assertCount(3, $rooms); $this->assertCount(3, $rooms);
$this->mapper->delete($room); $this->mapper->delete($room);
$this->mapper->delete($foreignRoom1); $this->mapper->delete($foreignRoom1);
$this->mapper->delete($foreignRoom2); $this->mapper->delete($foreignRoom2);
$this->mapper->delete($foreignRoom3); $this->mapper->delete($foreignRoom3);
foreach($shares as $share) { foreach ($shares as $share) {
$this->shareMapper->delete($share); $this->shareMapper->delete($share);
} }
} }
private function getRandomString(): string private function getRandomString(): string {
{ return \OC::$server->getSecureRandom()->generate(18, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE);
return \OC::$server->getSecureRandom()->generate(18, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE); }
}
private function insert($uid, $userId): Room private function insert($uid, $userId): Room {
{ $room = new Room();
$room = new Room(); $room->setUid($uid);
$room->setUid($uid);
$room->setName('random name'); $room->setName('random name');
$room->setWelcome(''); $room->setWelcome('');
$room->setMaxParticipants(0); $room->setMaxParticipants(0);
$room->setAttendeePassword('1'); $room->setAttendeePassword('1');
$room->setModeratorPassword('2'); $room->setModeratorPassword('2');
$room->setRecord(false); $room->setRecord(false);
$room->setUserId($userId); $room->setUserId($userId);
return $this->mapper->insert($room); return $this->mapper->insert($room);
} }
private function insertShare($id, $type, $with, $permission = RoomShare::PERMISSION_ADMIN): RoomShare private function insertShare($id, $type, $with, $permission = RoomShare::PERMISSION_ADMIN): RoomShare {
{ $roomShare = new RoomShare();
$roomShare = new RoomShare();
$roomShare->setRoomId($id); $roomShare->setRoomId($id);
$roomShare->setShareType($type); $roomShare->setShareType($type);
$roomShare->setShareWith($with); $roomShare->setShareWith($with);
$roomShare->setPermission($permission); $roomShare->setPermission($permission);
return $this->shareMapper->insert($roomShare); return $this->shareMapper->insert($roomShare);
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace OCA\BigBlueButton\Tests\Controller;
namespace OCA\BigBlueButton\Tests\Controller;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\RedirectResponse;
@ -19,8 +19,7 @@ use OCA\BigBlueButton\Permission;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
class JoinControllerTest extends TestCase class JoinControllerTest extends TestCase {
{
private $request; private $request;
private $service; private $service;
private $userSession; private $userSession;
@ -31,8 +30,7 @@ class JoinControllerTest extends TestCase
private $permission; private $permission;
private $room; private $room;
public function setUp(): void public function setUp(): void {
{
parent::setUp(); parent::setUp();
$this->request = $this->createMock(IRequest::class); $this->request = $this->createMock(IRequest::class);
@ -64,8 +62,7 @@ class JoinControllerTest extends TestCase
$this->room->password = 'password_foo'; $this->room->password = 'password_foo';
} }
public function testNonExistingRoom() public function testNonExistingRoom() {
{
$this->expectException(NotFoundException::class); $this->expectException(NotFoundException::class);
$this->service $this->service
->expects($this->once()) ->expects($this->once())
@ -75,8 +72,7 @@ class JoinControllerTest extends TestCase
$this->controller->index(null); $this->controller->index(null);
} }
public function testUserIsLoggedIn() public function testUserIsLoggedIn() {
{
$this->controller->setToken($this->room->uid); $this->controller->setToken($this->room->uid);
$this->service $this->service
->expects($this->once()) ->expects($this->once())
@ -115,8 +111,7 @@ class JoinControllerTest extends TestCase
$this->assertEquals($url, $result->getRedirectURL()); $this->assertEquals($url, $result->getRedirectURL());
} }
public function testUserNeedsToAuthenticateForInternal() public function testUserNeedsToAuthenticateForInternal() {
{
$this->room->setAccess(Room::ACCESS_INTERNAL); $this->room->setAccess(Room::ACCESS_INTERNAL);
$this->controller->setToken($this->room->uid); $this->controller->setToken($this->room->uid);
@ -144,8 +139,7 @@ class JoinControllerTest extends TestCase
$this->assertEquals(Http::STATUS_SEE_OTHER, $result->getStatus()); $this->assertEquals(Http::STATUS_SEE_OTHER, $result->getStatus());
} }
public function testUserNeedsToAuthenticateForInternalRestricted() public function testUserNeedsToAuthenticateForInternalRestricted() {
{
$this->room->setAccess(Room::ACCESS_INTERNAL_RESTRICTED); $this->room->setAccess(Room::ACCESS_INTERNAL_RESTRICTED);
$this->controller->setToken($this->room->uid); $this->controller->setToken($this->room->uid);
@ -173,8 +167,7 @@ class JoinControllerTest extends TestCase
$this->assertEquals(Http::STATUS_SEE_OTHER, $result->getStatus()); $this->assertEquals(Http::STATUS_SEE_OTHER, $result->getStatus());
} }
public function testDisplaynames() public function testDisplaynames() {
{
$this->controller->setToken($this->room->uid); $this->controller->setToken($this->room->uid);
$this->service $this->service
->expects($this->once()) ->expects($this->once())
@ -202,8 +195,7 @@ class JoinControllerTest extends TestCase
$this->assertInstanceOf(RedirectResponse::class, $response); $this->assertInstanceOf(RedirectResponse::class, $response);
} }
private function invalidDisplayname($displayname) private function invalidDisplayname($displayname) {
{
$response = $this->controller->index($displayname); $response = $this->controller->index($displayname);
$this->assertInstanceOf(TemplateResponse::class, $response); $this->assertInstanceOf(TemplateResponse::class, $response);
@ -211,8 +203,7 @@ class JoinControllerTest extends TestCase
$this->assertTrue($response->getParams()['wrongdisplayname']); $this->assertTrue($response->getParams()['wrongdisplayname']);
} }
public function testPasswordRequired() public function testPasswordRequired() {
{
$this->room->setAccess(Room::ACCESS_PASSWORD); $this->room->setAccess(Room::ACCESS_PASSWORD);
$this->room->setPassword('asdf'); $this->room->setPassword('asdf');

View File

@ -1,6 +1,6 @@
<?php <?php
namespace OCA\BigBlueButton\Tests\Controller;
namespace OCA\BigBlueButton\Tests\Controller;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use OCP\IRequest; use OCP\IRequest;
@ -8,13 +8,11 @@ use OCA\BigBlueButton\Service\RoomService;
use OCA\BigBlueButton\Controller\RoomShareController; use OCA\BigBlueButton\Controller\RoomShareController;
use OCA\BigBlueButton\Db\Room; use OCA\BigBlueButton\Db\Room;
use OCA\BigBlueButton\Db\RoomShare; use OCA\BigBlueButton\Db\RoomShare;
use OCA\BigBlueButton\Service\RoomShareNotFound;
use OCA\BigBlueButton\Service\RoomShareService; use OCA\BigBlueButton\Service\RoomShareService;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\IUserManager; use OCP\IUserManager;
class RoomShareControllerTest extends TestCase class RoomShareControllerTest extends TestCase {
{
private $request; private $request;
private $service; private $service;
private $roomService; private $roomService;
@ -23,8 +21,7 @@ class RoomShareControllerTest extends TestCase
private $userId = 'user_foo'; private $userId = 'user_foo';
public function setUp(): void public function setUp(): void {
{
parent::setUp(); parent::setUp();
$this->request = $this->createMock(IRequest::class); $this->request = $this->createMock(IRequest::class);
@ -42,15 +39,13 @@ class RoomShareControllerTest extends TestCase
); );
} }
public function testIndexWithoutRoomId() public function testIndexWithoutRoomId() {
{
$response = $this->controller->index(); $response = $this->controller->index();
$this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus()); $this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus());
} }
public function testIndexWithoutPermission() public function testIndexWithoutPermission() {
{
$this->request $this->request
->expects($this->once()) ->expects($this->once())
->method('getParam') ->method('getParam')
@ -71,8 +66,7 @@ class RoomShareControllerTest extends TestCase
$this->assertEquals(Http::STATUS_FORBIDDEN, $response->getStatus()); $this->assertEquals(Http::STATUS_FORBIDDEN, $response->getStatus());
} }
public function testIndexWithoutShares() public function testIndexWithoutShares() {
{
$roomId = 1234; $roomId = 1234;
$this->request $this->request
->expects($this->once()) ->expects($this->once())
@ -100,8 +94,7 @@ class RoomShareControllerTest extends TestCase
$this->assertEquals([], $response->getData()); $this->assertEquals([], $response->getData());
} }
public function testIndexWithShares() public function testIndexWithShares() {
{
$roomId = 1234; $roomId = 1234;
$this->request $this->request
->expects($this->once()) ->expects($this->once())

View File

@ -1,4 +1,5 @@
<?php <?php
namespace OCA\BigBlueButton\Tests; namespace OCA\BigBlueButton\Tests;
use OCA\BigBlueButton\Db\Room; use OCA\BigBlueButton\Db\Room;
@ -9,8 +10,7 @@ use OCP\IGroupManager;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class PermissionTest extends TestCase class PermissionTest extends TestCase {
{
/** @var Permission */ /** @var Permission */
private $permission; private $permission;
@ -20,8 +20,7 @@ class PermissionTest extends TestCase
/** @var RoomShareService|MockObject */ /** @var RoomShareService|MockObject */
private $roomShareService; private $roomShareService;
public function setUp(): void public function setUp(): void {
{
parent::setUp(); parent::setUp();
/** @var IGroupManager|MockObject */ /** @var IGroupManager|MockObject */
@ -36,8 +35,7 @@ class PermissionTest extends TestCase
); );
} }
public function testIsUser() public function testIsUser() {
{
$room = $this->createRoom(1, 'foo'); $room = $this->createRoom(1, 'foo');
$this->roomShareService $this->roomShareService
@ -67,8 +65,7 @@ class PermissionTest extends TestCase
$this->assertTrue($this->permission->isUser($room, 'group_user')); $this->assertTrue($this->permission->isUser($room, 'group_user'));
} }
private function createRoom(int $id, string $userId): Room private function createRoom(int $id, string $userId): Room {
{
$room = new Room(); $room = new Room();
$room->setId($id); $room->setId($id);
@ -77,8 +74,7 @@ class PermissionTest extends TestCase
return $room; return $room;
} }
private function createRoomShare(int $type, string $with, int $permission): RoomShare private function createRoomShare(int $type, string $with, int $permission): RoomShare {
{
$share = new RoomShare(); $share = new RoomShare();
$share->setShareType($type); $share->setShareType($type);

View File

@ -1,10 +1,10 @@
<?php <?php
if (!($ncRoot = getenv('NEXTCLOUD_ROOT'))) { if (!($ncRoot = getenv('NEXTCLOUD_ROOT'))) {
$ncRoot = __DIR__ . '/../../..'; $ncRoot = __DIR__ . '/../../..';
} }
echo "Using ".realpath($ncRoot)." as Nextcloud root.\n\n"; echo "Using ".realpath($ncRoot)." as Nextcloud root.\n\n";
require_once $ncRoot . '/lib/base.php'; require_once $ncRoot . '/lib/base.php';
require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../vendor/autoload.php';