diff options
author | Joas Schilling <coding@schilljs.com> | 2019-09-15 13:14:44 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-09-19 15:55:59 +0300 |
commit | d4424477feaa4a6e383f7805a3f75be4f181f726 (patch) | |
tree | 6d4a1e84554505a2f9c7084aa11b796240688ffc /lib/Listener | |
parent | ffff5662644e383a31d63106d214317ffee2be11 (diff) |
Also prevent starting a call on API level
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Listener')
-rw-r--r-- | lib/Listener/RestrictStartingCalls.php | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/lib/Listener/RestrictStartingCalls.php b/lib/Listener/RestrictStartingCalls.php new file mode 100644 index 000000000..e9ccd10ee --- /dev/null +++ b/lib/Listener/RestrictStartingCalls.php @@ -0,0 +1,77 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Talk\Listener; + + +use OCA\Talk\Exceptions\ForbiddenException; +use OCA\Talk\Participant; +use OCA\Talk\Room; +use OCP\IConfig; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; + +class RestrictStartingCalls { + + /** @var IConfig */ + protected $config; + + public function __construct(IConfig $config) { + $this->config = $config; + } + + public static function register(EventDispatcherInterface $dispatcher): void { + $dispatcher->addListener(Room::class . '::preSessionJoinCall', function(GenericEvent $event) { + + /** @var self $listener */ + $listener = \OC::$server->query(self::class); + $listener->checkStartCallPermissions($event); + }); + } + + /** + * @param GenericEvent $event + * @throws ForbiddenException + */ + public function checkStartCallPermissions(GenericEvent $event): void { + /** @var Room $room */ + $room = $event->getSubject(); + /** @var string $sessionId */ + $sessionId = $event->getArgument('sessionId'); + /** @var Participant $participant */ + $participant = $room->getParticipantBySession($sessionId); + + $defaultStartCall = (int) $this->config->getAppValue('spreed', 'start_calls', Room::START_CALL_EVERYONE); + $canStartCall = false; + if ($defaultStartCall === Room::START_CALL_EVERYONE) { + $canStartCall = true; + } else if ($defaultStartCall === Room::START_CALL_USERS && (!$participant->isGuest() || $participant->hasModeratorPermissions())) { + $canStartCall = true; + } else if ($defaultStartCall === Room::START_CALL_MODERATORS && $participant->hasModeratorPermissions()) { + $canStartCall = true; + } + + if (!$canStartCall) { + throw new ForbiddenException('Can not start a call'); + } + } +} |