diff --git a/.php_cs.dist b/.php_cs.dist index 691bae4..5bc525b 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -1,13 +1,18 @@ in('lib/') -; -return PhpCsFixer\Config::create() - ->setRules([ - '@PSR2' => true, - 'array_syntax' => ['syntax' => 'short'], - 'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => false], - ]) - ->setIndent("\t") - ->setFinder($finder) - ; + +declare(strict_types=1); + +require_once './vendor/autoload.php'; + +use Nextcloud\CodingStandard\Config; + +$config = new Config(); +$config + ->getFinder() + ->ignoreVCSIgnored(true) + ->notPath('build') + ->notPath('l10n') + ->notPath('src') + ->notPath('vendor') + ->in(__DIR__); +return $config; \ No newline at end of file diff --git a/appinfo/app.php b/appinfo/app.php index aca4835..a5104c1 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -1,15 +1,15 @@ getConfig()->getAppValue('bbb', 'api.url'); $parsedApiUrl = @parse_url($apiUrl); if ($parsedApiUrl !== false) { - $manager = \OC::$server->getContentSecurityPolicyManager(); - $policy = new \OCP\AppFramework\Http\EmptyContentSecurityPolicy(); + $manager = \OC::$server->getContentSecurityPolicyManager(); + $policy = new \OCP\AppFramework\Http\EmptyContentSecurityPolicy(); $policy->addAllowedFormActionDomain(($parsedApiUrl['scheme'] ?: 'https') . '://' . $parsedApiUrl['host']); - $manager->addDefaultPolicy($policy); -} \ No newline at end of file + $manager->addDefaultPolicy($policy); +} diff --git a/appinfo/routes.php b/appinfo/routes.php index 3e54be4..73b137f 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -1,14 +1,15 @@ [ - 'room' => ['url' => '/rooms'], - 'roomShare' => ['url' => '/roomShares'], - ], - 'routes' => [ - ['name' => 'server#records', 'url' => '/server/{roomUid}/records', 'verb' => 'GET'], - ['name' => 'server#check', 'url' => '/server/check', 'verb' => 'POST'], - ['name' => 'server#version', 'url' => '/server/version', 'verb' => 'GET'], - ['name' => 'server#delete_record', 'url' => '/server/record/{recordId}', 'verb' => 'DELETE'], - ['name' => 'join#index', 'url' => '/b/{token}', 'verb' => 'GET'], - ] -]; \ No newline at end of file + 'resources' => [ + 'room' => ['url' => '/rooms'], + 'roomShare' => ['url' => '/roomShares'], + ], + 'routes' => [ + ['name' => 'server#records', 'url' => '/server/{roomUid}/records', 'verb' => 'GET'], + ['name' => 'server#check', 'url' => '/server/check', 'verb' => 'POST'], + ['name' => 'server#version', 'url' => '/server/version', 'verb' => 'GET'], + ['name' => 'server#delete_record', 'url' => '/server/record/{recordId}', 'verb' => 'DELETE'], + ['name' => 'join#index', 'url' => '/b/{token}', 'verb' => 'GET'], + ] +]; diff --git a/composer.json b/composer.json index febfdc9..3123b43 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ }, "require-dev": { "phpunit/phpunit": "^8", - "friendsofphp/php-cs-fixer": "^2.16" + "friendsofphp/php-cs-fixer": "^2.16", + "nextcloud/coding-standard": "^0.3.0" }, "config": { "optimize-autoloader": true, diff --git a/composer.lock b/composer.lock index 7a398ec..1175167 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "67b538bdf36cbd6464297b3d9257bb3c", + "content-hash": "a5f7d2fab7db00ef99eb9468c2fa9a0a", "packages": [ { "name": "littleredbutton/bigbluebutton-api-php", @@ -580,6 +580,43 @@ ], "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", "version": "v9.99.99", diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 9b7859a..b5d8d7c 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -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?'); } -class Application extends App -{ - public function __construct(array $urlParams = []) - { +class Application extends App { + public function __construct(array $urlParams = []) { parent::__construct('bbb', $urlParams); $container = $this->getContainer(); diff --git a/lib/BigBlueButton/API.php b/lib/BigBlueButton/API.php index a017d1f..7643f7d 100644 --- a/lib/BigBlueButton/API.php +++ b/lib/BigBlueButton/API.php @@ -10,15 +10,11 @@ use BigBlueButton\Core\Record; use BigBlueButton\Parameters\DeleteRecordingsParameters; use BigBlueButton\Parameters\IsMeetingRunningParameters; use OCA\BigBlueButton\Db\Room; -use OCA\BigBlueButton\Db\RoomShare; use OCA\BigBlueButton\Permission; -use OCA\BigBlueButton\Service\RoomShareService; use OCP\IConfig; use OCP\IURLGenerator; -use OCP\IGroupManager; -class API -{ +class API { /** @var IConfig */ private $config; @@ -41,8 +37,7 @@ class API $this->permission = $permission; } - private function getServer() - { + private function getServer() { if (!$this->server) { $apiUrl = $this->config->getAppValue('bbb', 'api.url'); $secret = $this->config->getAppValue('bbb', 'api.secret'); @@ -58,8 +53,7 @@ class API * * @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; $joinMeetingParams = new JoinMeetingParameters($room->uid, $displayname, $password); @@ -82,8 +76,7 @@ class API * * @return int creation time */ - public function createMeeting(Room $room, Presentation $presentation = null) - { + public function createMeeting(Room $room, Presentation $presentation = null) { $bbb = $this->getServer(); $meetingParams = $this->buildMeetingParams($room, $presentation); @@ -100,8 +93,7 @@ class API 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->setAttendeePassword($room->attendeePassword); $createMeetingParams->setModeratorPassword($room->moderatorPassword); @@ -131,8 +123,7 @@ class API return $createMeetingParams; } - public function getRecording(string $recordId) - { + public function getRecording(string $recordId) { $recordingParams = new GetRecordingsParameters(); $recordingParams->setRecordId($recordId); $recordingParams->setState('any'); @@ -152,8 +143,7 @@ class API return $this->recordToArray($records[0]); } - public function getRecordings(Room $room) - { + public function getRecordings(Room $room) { $recordingParams = new GetRecordingsParameters(); $recordingParams->setMeetingId($room->uid); $recordingParams->setState('processing,processed,published,unpublished'); @@ -171,8 +161,7 @@ class API }, $records); } - public function deleteRecording(string $recordingId): bool - { + public function deleteRecording(string $recordingId): bool { $deleteParams = new DeleteRecordingsParameters($recordingId); $response = $this->getServer()->deleteRecordings($deleteParams); @@ -180,8 +169,7 @@ class API return $response->isDeleted(); } - private function recordToArray(Record $record) - { + private function recordToArray(Record $record) { return [ 'id' => $record->getRecordId(), 'name' => $record->getName(), @@ -196,8 +184,7 @@ class API ]; } - public function check($url, $secret) - { + public function check($url, $secret) { $server = new BigBlueButton($url, $secret); $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, ''); return $server->getApiVersion()->getVersion(); diff --git a/lib/BigBlueButton/Presentation.php b/lib/BigBlueButton/Presentation.php index 1b74528..558c260 100644 --- a/lib/BigBlueButton/Presentation.php +++ b/lib/BigBlueButton/Presentation.php @@ -2,30 +2,25 @@ namespace OCA\BigBlueButton\BigBlueButton; -class Presentation -{ +class Presentation { private $url; private $filename; - public function __construct(string $url, string $filename) - { + public function __construct(string $url, string $filename) { $this->url = $url; $this->filename = $filename; } - public function getUrl() - { + public function getUrl() { return $this->url; } - public function getFilename() - { + public function getFilename() { return $this->filename; } - public function isValid() - { + public function isValid() { return !empty($this->url) && !empty($this->filename); } } diff --git a/lib/Controller/Errors.php b/lib/Controller/Errors.php index f49708a..1027a4d 100644 --- a/lib/Controller/Errors.php +++ b/lib/Controller/Errors.php @@ -10,10 +10,8 @@ use OCP\AppFramework\Http\DataResponse; use OCA\BigBlueButton\Service\RoomNotFound; use OCA\BigBlueButton\Service\RoomShareNotFound; -trait Errors -{ - protected function handleNotFound(Closure $callback): DataResponse - { +trait Errors { + protected function handleNotFound(Closure $callback): DataResponse { try { $return = $callback(); return ($return instanceof DataResponse) ? $return : new DataResponse($return); diff --git a/lib/Controller/JoinController.php b/lib/Controller/JoinController.php index 8b2f02c..b598ca6 100644 --- a/lib/Controller/JoinController.php +++ b/lib/Controller/JoinController.php @@ -1,4 +1,5 @@ permission = $permission; } - public function setToken(string $token) - { + public function setToken(string $token) { $this->token = $token; $this->room = null; } - public function isValidToken(): bool - { + public function isValidToken(): bool { $room = $this->getRoom(); return $room !== null; @@ -81,8 +79,7 @@ class JoinController extends Controller * @PublicPage * @NoCSRFRequired */ - public function index($displayname, $u = '', $filename = '', $password = '') - { + public function index($displayname, $u = '', $filename = '', $password = '') { $room = $this->getRoom(); if ($room === null) { @@ -133,8 +130,7 @@ class JoinController extends Controller return new RedirectResponse($joinUrl); } - private function addFormActionDomain($response) - { + private function addFormActionDomain($response) { $apiUrl = $this->config->getAppValue($this->appName, 'api.url'); $parsedApiUrl = parse_url($apiUrl); @@ -145,8 +141,7 @@ class JoinController extends Controller $response->getContentSecurityPolicy()->addAllowedFormActionDomain(($parsedApiUrl['scheme'] ?: 'https') . '://' . $parsedApiUrl['host']); } - private function getRoom(): ?Room - { + private function getRoom(): ?Room { if ($this->room === null) { $this->room = $this->service->findByUid($this->token); } diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index 5ca0395..16e3770 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -11,8 +11,7 @@ use OCP\AppFramework\Controller; use OCP\IGroupManager; use OCP\IUserManager; -class RoomController extends Controller -{ +class RoomController extends Controller { /** @var RoomService */ private $service; @@ -50,8 +49,7 @@ class RoomController extends Controller /** * @NoAdminRequired */ - public function index(): DataResponse - { + public function index(): DataResponse { $user = $this->userManager->get($this->userId); $groupIds = $this->groupManager->getUserGroupIds($user); @@ -102,8 +100,7 @@ class RoomController extends Controller /** * @NoAdminRequired */ - public function destroy(int $id): DataResponse - { + public function destroy(int $id): DataResponse { $room = $this->service->find($id); if (!$this->permission->isAdmin($room, $this->userId)) { diff --git a/lib/Controller/RoomShareController.php b/lib/Controller/RoomShareController.php index e6acfa4..a049781 100644 --- a/lib/Controller/RoomShareController.php +++ b/lib/Controller/RoomShareController.php @@ -13,8 +13,7 @@ use OCP\AppFramework\Controller; use OCA\BigBlueButton\Service\RoomShareService; use OCP\IUserManager; -class RoomShareController extends Controller -{ +class RoomShareController extends Controller { /** @var RoomShareService */ private $service; @@ -47,8 +46,7 @@ class RoomShareController extends Controller /** * @NoAdminRequired */ - public function index(): DataResponse - { + public function index(): DataResponse { $roomId = $this->request->getParam('id'); if ($roomId === null) { @@ -127,8 +125,7 @@ class RoomShareController extends Controller /** * @NoAdminRequired */ - public function destroy(int $id): DataResponse - { + public function destroy(int $id): DataResponse { return $this->handleNotFound(function () use ($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 { $room = $this->roomService->find($roomId); diff --git a/lib/Controller/ServerController.php b/lib/Controller/ServerController.php index 455c808..6e2d2bb 100644 --- a/lib/Controller/ServerController.php +++ b/lib/Controller/ServerController.php @@ -11,8 +11,7 @@ use OCP\AppFramework\Controller; use OCA\BigBlueButton\Service\RoomService; -class ServerController extends Controller -{ +class ServerController extends Controller { /** @var RoomService */ private $service; @@ -42,10 +41,9 @@ class ServerController extends Controller } /** - * @NoAdminRequired - */ - public function records(string $roomUid): DataResponse - { + * @NoAdminRequired + */ + public function records(string $roomUid): DataResponse { $room = $this->service->findByUid($roomUid); if ($room === null) { @@ -62,10 +60,9 @@ class ServerController extends Controller } /** - * @NoAdminRequired - */ - public function deleteRecord(string $recordId): DataResponse - { + * @NoAdminRequired + */ + public function deleteRecord(string $recordId): DataResponse { $record = $this->server->getRecording($recordId); $room = $this->service->findByUid($record['metas']['meetingId']); @@ -83,8 +80,7 @@ class ServerController extends Controller 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)) { return new DataResponse(false); } @@ -92,8 +88,7 @@ class ServerController extends Controller return new DataResponse($this->server->check($url, $secret)); } - public function version(string $url) - { + public function version(string $url) { if ($url === null || empty($url)) { return new DataResponse(false, Http::STATUS_NOT_FOUND); } diff --git a/lib/Db/Room.php b/lib/Db/Room.php index 2fb26cf..a9609b2 100644 --- a/lib/Db/Room.php +++ b/lib/Db/Room.php @@ -1,17 +1,17 @@ addType('maxParticipants', 'integer'); $this->addType('record', 'boolean'); $this->addType('everyoneIsModerator', 'boolean'); } - public function jsonSerialize(): array - { + public function jsonSerialize(): array { return [ 'id' => $this->id, 'uid' => $this->uid, diff --git a/lib/Db/RoomMapper.php b/lib/Db/RoomMapper.php index c052e44..a9fdfab 100644 --- a/lib/Db/RoomMapper.php +++ b/lib/Db/RoomMapper.php @@ -1,4 +1,5 @@ db->getQueryBuilder(); $qb->select('*') @@ -37,8 +35,7 @@ class RoomMapper extends QBMapper * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws DoesNotExistException */ - public function findByUid(string $uid): Room - { + public function findByUid(string $uid): Room { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->select('*') @@ -52,8 +49,7 @@ class RoomMapper extends QBMapper * @param array $groupIds * @return array */ - public function findAll(string $userId, array $groupIds): array - { + public function findAll(string $userId, array $groupIds): array { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->select('r.*') diff --git a/lib/Db/RoomShare.php b/lib/Db/RoomShare.php index f41696c..f7306c8 100644 --- a/lib/Db/RoomShare.php +++ b/lib/Db/RoomShare.php @@ -1,18 +1,18 @@ addType('roomId', 'integer'); $this->addType('shareType', 'integer'); $this->addType('permission', 'integer'); } - public function jsonSerialize(): array - { + public function jsonSerialize(): array { return [ 'id' => $this->id, '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; } - public function hasModeratorPermission(): bool - { + public function hasModeratorPermission(): bool { 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; } } diff --git a/lib/Db/RoomShareMapper.php b/lib/Db/RoomShareMapper.php index d99fe63..82ffbcb 100644 --- a/lib/Db/RoomShareMapper.php +++ b/lib/Db/RoomShareMapper.php @@ -1,4 +1,5 @@ db->getQueryBuilder(); $qb->select('*') @@ -30,8 +28,7 @@ class RoomShareMapper extends QBMapper 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 */ $qb = $this->db->getQueryBuilder(); $qb->select('*') @@ -43,8 +40,7 @@ class RoomShareMapper extends QBMapper return $this->findEntity($qb); } - public function findAll(int $roomId): array - { + public function findAll(int $roomId): array { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->select('*') diff --git a/lib/Middleware/JoinMiddleware.php b/lib/Middleware/JoinMiddleware.php index cd05eb8..d6fde36 100644 --- a/lib/Middleware/JoinMiddleware.php +++ b/lib/Middleware/JoinMiddleware.php @@ -1,4 +1,5 @@ request = $request; } - public function beforeController($controller, $methodName) - { + public function beforeController($controller, $methodName) { if (!($controller instanceof JoinController)) { return; } @@ -39,8 +37,7 @@ class JoinMiddleware extends Middleware throw new NotFoundException(); } - public function afterException($controller, $methodName, \Exception $exception) - { + public function afterException($controller, $methodName, \Exception $exception) { if (!($controller instanceof JoinController)) { throw $exception; } diff --git a/lib/Migration/Version000000Date20200416124731.php b/lib/Migration/Version000000Date20200416124731.php index cd02c92..e4eb013 100644 --- a/lib/Migration/Version000000Date20200416124731.php +++ b/lib/Migration/Version000000Date20200416124731.php @@ -9,8 +9,7 @@ use OCP\DB\ISchemaWrapper; use OCP\Migration\SimpleMigrationStep; use OCP\Migration\IOutput; -class Version000000Date20200416124731 extends SimpleMigrationStep -{ +class Version000000Date20200416124731 extends SimpleMigrationStep { /** * @param IOutput $output @@ -18,8 +17,7 @@ class Version000000Date20200416124731 extends SimpleMigrationStep * @param array $options * @return null|ISchemaWrapper */ - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) - { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version000000Date20200604130935.php b/lib/Migration/Version000000Date20200604130935.php index ec9f342..6e46571 100644 --- a/lib/Migration/Version000000Date20200604130935.php +++ b/lib/Migration/Version000000Date20200604130935.php @@ -13,16 +13,14 @@ use OCP\Migration\SimpleMigrationStep; /** * Auto-generated migration step: Please modify to your needs! */ -class Version000000Date20200604130935 extends SimpleMigrationStep -{ +class Version000000Date20200604130935 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) - { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version000000Date20200613111242.php b/lib/Migration/Version000000Date20200613111242.php index 58e1afb..1559abd 100644 --- a/lib/Migration/Version000000Date20200613111242.php +++ b/lib/Migration/Version000000Date20200613111242.php @@ -9,8 +9,7 @@ use OCP\DB\ISchemaWrapper; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -class Version000000Date20200613111242 extends SimpleMigrationStep -{ +class Version000000Date20200613111242 extends SimpleMigrationStep { /** * @param IOutput $output @@ -18,8 +17,7 @@ class Version000000Date20200613111242 extends SimpleMigrationStep * @param array $options * @return null|ISchemaWrapper */ - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) - { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version000000Date20200617055735.php b/lib/Migration/Version000000Date20200617055735.php index d722b89..ea2469b 100644 --- a/lib/Migration/Version000000Date20200617055735.php +++ b/lib/Migration/Version000000Date20200617055735.php @@ -9,8 +9,7 @@ use OCP\DB\ISchemaWrapper; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -class Version000000Date20200617055735 extends SimpleMigrationStep -{ +class Version000000Date20200617055735 extends SimpleMigrationStep { /** * @param IOutput $output @@ -18,8 +17,7 @@ class Version000000Date20200617055735 extends SimpleMigrationStep * @param array $options * @return null|ISchemaWrapper */ - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) - { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/NoPermissionException.php b/lib/NoPermissionException.php index c95d375..e80f8f1 100644 --- a/lib/NoPermissionException.php +++ b/lib/NoPermissionException.php @@ -2,6 +2,5 @@ namespace OCA\BigBlueButton; -class NoPermissionException extends \Exception -{ +class NoPermissionException extends \Exception { } diff --git a/lib/NoPermissionResponse.php b/lib/NoPermissionResponse.php index 6238247..0678be0 100644 --- a/lib/NoPermissionResponse.php +++ b/lib/NoPermissionResponse.php @@ -1,22 +1,20 @@ setContentSecurityPolicy(new ContentSecurityPolicy()); $this->setStatus(404); } - public function render() - { + public function render() { $template = new Template('core', '403', 'guest'); return $template->fetchPage(); } diff --git a/lib/NotFoundException.php b/lib/NotFoundException.php index 6a40214..add1609 100644 --- a/lib/NotFoundException.php +++ b/lib/NotFoundException.php @@ -2,6 +2,5 @@ namespace OCA\BigBlueButton; -class NotFoundException extends \Exception -{ +class NotFoundException extends \Exception { } diff --git a/lib/Permission.php b/lib/Permission.php index a6301eb..4bb79e1 100644 --- a/lib/Permission.php +++ b/lib/Permission.php @@ -8,8 +8,7 @@ use OCA\BigBlueButton\Db\Room; use OCA\BigBlueButton\Db\RoomShare; use OCP\IGroupManager; -class Permission -{ +class Permission { /** @var IGroupManager */ private $groupManager; @@ -25,15 +24,13 @@ class Permission $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 $share->hasUserPermission(); }); } - public function isModerator(Room $room, ?string $uid) - { + public function isModerator(Room $room, ?string $uid) { if ($room->everyoneIsModerator) { 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 $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) { return false; } diff --git a/lib/Service/RoomNotFound.php b/lib/Service/RoomNotFound.php index b642c44..49de7ef 100644 --- a/lib/Service/RoomNotFound.php +++ b/lib/Service/RoomNotFound.php @@ -2,6 +2,5 @@ namespace OCA\BigBlueButton\Service; -class RoomNotFound extends \Exception -{ +class RoomNotFound extends \Exception { } diff --git a/lib/Service/RoomService.php b/lib/Service/RoomService.php index 6598771..68d2217 100644 --- a/lib/Service/RoomService.php +++ b/lib/Service/RoomService.php @@ -1,4 +1,5 @@ mapper = $mapper; } - public function findAll(string $userId, array $groupIds): array - { + public function findAll(string $userId, array $groupIds): array { return $this->mapper->findAll($userId, $groupIds); } - private function handleException(Exception $e): void - { + private function handleException(Exception $e): void { if ($e instanceof DoesNotExistException || $e instanceof MultipleObjectsReturnedException) { throw new RoomNotFound($e->getMessage()); @@ -36,8 +32,7 @@ class RoomService } } - public function find($id): Room - { + public function find($id): Room { try { return $this->mapper->find($id); @@ -50,8 +45,7 @@ class RoomService } } - public function findByUid($uid) - { + public function findByUid($uid) { try { return $this->mapper->findByUid($uid); } 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->setUid(\OC::$server->getSecureRandom()->generate(16, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE)); @@ -76,8 +69,7 @@ class RoomService 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 { $room = $this->mapper->find($id); @@ -98,8 +90,7 @@ class RoomService } } - public function delete($id) - { + public function delete($id) { try { $room = $this->mapper->find($id); $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); } } diff --git a/lib/Service/RoomShareNotFound.php b/lib/Service/RoomShareNotFound.php index 7ae8fb8..f59b0cc 100644 --- a/lib/Service/RoomShareNotFound.php +++ b/lib/Service/RoomShareNotFound.php @@ -2,6 +2,5 @@ namespace OCA\BigBlueButton\Service; -class RoomShareNotFound extends \Exception -{ +class RoomShareNotFound extends \Exception { } diff --git a/lib/Service/RoomShareService.php b/lib/Service/RoomShareService.php index 9ba4f01..402c9e6 100644 --- a/lib/Service/RoomShareService.php +++ b/lib/Service/RoomShareService.php @@ -1,4 +1,5 @@ mapper = $mapper; } - public function findAll(int $roomId): array - { + public function findAll(int $roomId): array { return $this->mapper->findAll($roomId); } - private function handleException(Exception $e): void - { + private function handleException(Exception $e): void { if ($e instanceof DoesNotExistException || $e instanceof MultipleObjectsReturnedException) { throw new RoomShareNotFound($e->getMessage()); @@ -35,8 +32,7 @@ class RoomShareService } } - public function find($id): RoomShare - { + public function find($id): RoomShare { try { return $this->mapper->find($id); } 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 { $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 { $roomShare = $this->mapper->find($id); @@ -78,8 +72,7 @@ class RoomShareService } } - public function delete(int $id): RoomShare - { + public function delete(int $id): RoomShare { try { $roomShare = $this->mapper->find($id); $this->mapper->delete($roomShare); diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 881375d..f9a450d 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -1,12 +1,12 @@ config = $config; } /** * @return TemplateResponse */ - public function getForm() - { + public function getForm() { $parameters = [ - 'api.url' => $this->config->getAppValue('bbb', 'api.url'), - 'api.secret' => $this->config->getAppValue('bbb', 'api.secret'), - ]; + 'api.url' => $this->config->getAppValue('bbb', 'api.url'), + 'api.secret' => $this->config->getAppValue('bbb', 'api.secret'), + ]; return new TemplateResponse('bbb', 'admin', $parameters); } @@ -37,8 +35,7 @@ class Admin implements ISettings /** * @return string the section ID, e.g. 'sharing' */ - public function getSection() - { + public function getSection() { return 'additional'; } @@ -47,8 +44,7 @@ class Admin implements ISettings * 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. */ - public function getPriority() - { + public function getPriority() { return 50; } } diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php index f9d1e4b..bfdc4ab 100644 --- a/lib/Settings/Personal.php +++ b/lib/Settings/Personal.php @@ -7,8 +7,7 @@ use OCP\Settings\ISettings; use OCP\IConfig; use \OCP\IL10N; -class Personal implements ISettings -{ +class Personal implements ISettings { /** @var IConfig */ private $config; @@ -20,8 +19,7 @@ class Personal implements ISettings * * @param IConfig $config */ - public function __construct(IConfig $config, IL10N $l) - { + public function __construct(IConfig $config, IL10N $l) { $this->config = $config; $this->l = $l; } @@ -29,8 +27,7 @@ class Personal implements ISettings /** * @return TemplateResponse */ - public function getForm() - { + public function getForm() { $warning = ''; 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' */ - public function getSection() - { + public function getSection() { return 'bbb'; } @@ -55,8 +51,7 @@ class Personal implements ISettings * * E.g.: 70 */ - public function getPriority() - { + public function getPriority() { return 50; } } diff --git a/lib/Settings/Section.php b/lib/Settings/Section.php index d001f20..9e7edd0 100644 --- a/lib/Settings/Section.php +++ b/lib/Settings/Section.php @@ -6,15 +6,13 @@ use OCP\IL10N; use OCP\IURLGenerator; use OCP\Settings\IIconSection; -class Section implements IIconSection -{ +class Section implements IIconSection { /** @var IL10N */ private $l; /** @var IURLGenerator */ private $url; - public function __construct(IL10N $l, IURLGenerator $url) - { + public function __construct(IL10N $l, IURLGenerator $url) { $this->l = $l; $this->url = $url; } @@ -25,8 +23,7 @@ class Section implements IIconSection * * @returns string */ - public function getID() - { + public function getID() { return 'bbb'; } @@ -36,8 +33,7 @@ class Section implements IIconSection * * @return string */ - public function getName() - { + public function getName() { return "BigBlueButton"; } @@ -48,16 +44,14 @@ class Section implements IIconSection * * E.g.: 70 */ - public function getPriority() - { + public function getPriority() { return 50; } /** * {@inheritdoc} */ - public function getIcon() - { + public function getIcon() { return $this->url->imagePath('bbb', 'app-dark.svg'); } } diff --git a/templates/manager.php b/templates/manager.php index 2d059d3..28f0879 100644 --- a/templates/manager.php +++ b/templates/manager.php @@ -4,7 +4,7 @@ script('bbb', 'manager');
- +
diff --git a/tests/Integration/Db/RoomMapperTest.php b/tests/Integration/Db/RoomMapperTest.php index a4525d7..80fd508 100644 --- a/tests/Integration/Db/RoomMapperTest.php +++ b/tests/Integration/Db/RoomMapperTest.php @@ -1,4 +1,5 @@ db = OC::$server->getDatabaseConnection(); - $this->mapper = new RoomMapper($this->db); - $this->shareMapper = new RoomShareMapper($this->db); + $this->mapper = new RoomMapper($this->db); + $this->shareMapper = new RoomShareMapper($this->db); - $this->userId = $this->getRandomString(); - $this->uid = $this->getRandomString(); - } + $this->userId = $this->getRandomString(); + $this->uid = $this->getRandomString(); + } - public function testInsert() - { - $room = $this->insert($this->uid, $this->userId); + public function testInsert() { + $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 - */ - public function testFind() - { - $newRoom = $this->insert($this->uid, $this->userId); + /** + * @depends testInsert + */ + public function testFind() { + $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 - */ - public function testFindByUid() - { - $newRoom = $this->insert($this->uid, $this->userId); + /** + * @depends testInsert + */ + public function testFindByUid() { + $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 - */ - public function testFindAll() - { - $room = $this->insert($this->uid, $this->userId); + /** + * @depends testInsert + */ + public function testFindAll() { + $room = $this->insert($this->uid, $this->userId); - $foreignRoom1 = $this->insert($this->getRandomString(), $this->getRandomString()); - $foreignRoom2 = $this->insert($this->getRandomString(), $this->getRandomString()); - $foreignRoom3 = $this->insert($this->getRandomString(), $this->getRandomString()); + $foreignRoom1 = $this->insert($this->getRandomString(), $this->getRandomString()); + $foreignRoom2 = $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[] = $this->insertShare($foreignRoom1->getId(), RoomShare::SHARE_TYPE_USER, $this->userId); - $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($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_GROUP, 'foo bar', RoomShare::PERMISSION_USER); + $shares = []; + $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($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->userId, RoomShare::PERMISSION_MODERATOR); + $shares[] = $this->insertShare($foreignRoom3->getId(), RoomShare::SHARE_TYPE_GROUP, 'foo bar', RoomShare::PERMISSION_USER); - $rooms = $this->mapper->findAll($this->userId, ['foo bar']); - $this->assertCount(3, $rooms); + $rooms = $this->mapper->findAll($this->userId, ['foo bar']); + $this->assertCount(3, $rooms); - $this->mapper->delete($room); - $this->mapper->delete($foreignRoom1); - $this->mapper->delete($foreignRoom2); - $this->mapper->delete($foreignRoom3); + $this->mapper->delete($room); + $this->mapper->delete($foreignRoom1); + $this->mapper->delete($foreignRoom2); + $this->mapper->delete($foreignRoom3); - foreach($shares as $share) { - $this->shareMapper->delete($share); - } - } + foreach ($shares as $share) { + $this->shareMapper->delete($share); + } + } - private function getRandomString(): string - { - return \OC::$server->getSecureRandom()->generate(18, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE); - } + private function getRandomString(): string { + return \OC::$server->getSecureRandom()->generate(18, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE); + } - private function insert($uid, $userId): Room - { - $room = new Room(); - $room->setUid($uid); + private function insert($uid, $userId): Room { + $room = new Room(); + $room->setUid($uid); $room->setName('random name'); $room->setWelcome(''); $room->setMaxParticipants(0); $room->setAttendeePassword('1'); $room->setModeratorPassword('2'); $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 - { - $roomShare = new RoomShare(); + private function insertShare($id, $type, $with, $permission = RoomShare::PERMISSION_ADMIN): RoomShare { + $roomShare = new RoomShare(); $roomShare->setRoomId($id); $roomShare->setShareType($type); $roomShare->setShareWith($with); - $roomShare->setPermission($permission); + $roomShare->setPermission($permission); - return $this->shareMapper->insert($roomShare); - } -} \ No newline at end of file + return $this->shareMapper->insert($roomShare); + } +} diff --git a/tests/Unit/Controller/JoinControllerTest.php b/tests/Unit/Controller/JoinControllerTest.php index 43fb439..630815d 100644 --- a/tests/Unit/Controller/JoinControllerTest.php +++ b/tests/Unit/Controller/JoinControllerTest.php @@ -1,6 +1,6 @@ request = $this->createMock(IRequest::class); @@ -64,8 +62,7 @@ class JoinControllerTest extends TestCase $this->room->password = 'password_foo'; } - public function testNonExistingRoom() - { + public function testNonExistingRoom() { $this->expectException(NotFoundException::class); $this->service ->expects($this->once()) @@ -75,8 +72,7 @@ class JoinControllerTest extends TestCase $this->controller->index(null); } - public function testUserIsLoggedIn() - { + public function testUserIsLoggedIn() { $this->controller->setToken($this->room->uid); $this->service ->expects($this->once()) @@ -115,8 +111,7 @@ class JoinControllerTest extends TestCase $this->assertEquals($url, $result->getRedirectURL()); } - public function testUserNeedsToAuthenticateForInternal() - { + public function testUserNeedsToAuthenticateForInternal() { $this->room->setAccess(Room::ACCESS_INTERNAL); $this->controller->setToken($this->room->uid); @@ -144,8 +139,7 @@ class JoinControllerTest extends TestCase $this->assertEquals(Http::STATUS_SEE_OTHER, $result->getStatus()); } - public function testUserNeedsToAuthenticateForInternalRestricted() - { + public function testUserNeedsToAuthenticateForInternalRestricted() { $this->room->setAccess(Room::ACCESS_INTERNAL_RESTRICTED); $this->controller->setToken($this->room->uid); @@ -173,8 +167,7 @@ class JoinControllerTest extends TestCase $this->assertEquals(Http::STATUS_SEE_OTHER, $result->getStatus()); } - public function testDisplaynames() - { + public function testDisplaynames() { $this->controller->setToken($this->room->uid); $this->service ->expects($this->once()) @@ -202,8 +195,7 @@ class JoinControllerTest extends TestCase $this->assertInstanceOf(RedirectResponse::class, $response); } - private function invalidDisplayname($displayname) - { + private function invalidDisplayname($displayname) { $response = $this->controller->index($displayname); $this->assertInstanceOf(TemplateResponse::class, $response); @@ -211,8 +203,7 @@ class JoinControllerTest extends TestCase $this->assertTrue($response->getParams()['wrongdisplayname']); } - public function testPasswordRequired() - { + public function testPasswordRequired() { $this->room->setAccess(Room::ACCESS_PASSWORD); $this->room->setPassword('asdf'); diff --git a/tests/Unit/Controller/RoomShareControllerTest.php b/tests/Unit/Controller/RoomShareControllerTest.php index 6b0c6c5..314d0f3 100644 --- a/tests/Unit/Controller/RoomShareControllerTest.php +++ b/tests/Unit/Controller/RoomShareControllerTest.php @@ -1,6 +1,6 @@ request = $this->createMock(IRequest::class); @@ -42,15 +39,13 @@ class RoomShareControllerTest extends TestCase ); } - public function testIndexWithoutRoomId() - { + public function testIndexWithoutRoomId() { $response = $this->controller->index(); $this->assertEquals(Http::STATUS_BAD_REQUEST, $response->getStatus()); } - public function testIndexWithoutPermission() - { + public function testIndexWithoutPermission() { $this->request ->expects($this->once()) ->method('getParam') @@ -71,8 +66,7 @@ class RoomShareControllerTest extends TestCase $this->assertEquals(Http::STATUS_FORBIDDEN, $response->getStatus()); } - public function testIndexWithoutShares() - { + public function testIndexWithoutShares() { $roomId = 1234; $this->request ->expects($this->once()) @@ -100,8 +94,7 @@ class RoomShareControllerTest extends TestCase $this->assertEquals([], $response->getData()); } - public function testIndexWithShares() - { + public function testIndexWithShares() { $roomId = 1234; $this->request ->expects($this->once()) diff --git a/tests/Unit/PermissionTest.php b/tests/Unit/PermissionTest.php index 6d1decb..922626b 100644 --- a/tests/Unit/PermissionTest.php +++ b/tests/Unit/PermissionTest.php @@ -1,4 +1,5 @@ createRoom(1, 'foo'); $this->roomShareService @@ -67,8 +65,7 @@ class PermissionTest extends TestCase $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->setId($id); @@ -77,8 +74,7 @@ class PermissionTest extends TestCase 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->setShareType($type); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4020143..b51fc58 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,10 +1,10 @@