diff options
author | Joas Schilling <coding@schilljs.com> | 2018-12-06 18:52:17 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2018-12-06 20:05:47 +0300 |
commit | 1890687981cef4686cedbef857e6475cd9ea0c96 (patch) | |
tree | 0bcbe14fb3d672d901817e8c299ad5040f4dba46 /lib/Files | |
parent | e5d580c1a42854567ad8d5ffc66c27c158d87263 (diff) |
Also leave the room when the user tries to join and can not access the file anymore
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Files')
-rw-r--r-- | lib/Files/Listener.php | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/Files/Listener.php b/lib/Files/Listener.php index 29d59db7e..5ee4016a8 100644 --- a/lib/Files/Listener.php +++ b/lib/Files/Listener.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace OCA\Spreed\Files; +use OCA\Spreed\Exceptions\UnauthorizedException; use OCA\Spreed\Room; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; @@ -37,7 +38,7 @@ use Symfony\Component\EventDispatcher\GenericEvent; * access (user, group, circle and room share, but not link share, for example) * to that file. The room has no owner, although self joined users become * persistent participants automatically when they join until they explicitly - * leave. + * leave or no longer have access to the file. * * These rooms are associated to a "file" object, and their custom behaviour is * provided by calling the methods of this class as a response to different room @@ -59,14 +60,22 @@ class Listener { $listener = function(GenericEvent $event) { /** @var Room $room */ $room = $event->getSubject(); - $this->preventUsersWithoutDirectAccessToTheFileFromJoining($room, $event->getArgument('userId')); + try { + $this->preventUsersWithoutDirectAccessToTheFileFromJoining($room, $event->getArgument('userId')); + } catch (UnauthorizedException $e) { + $event->setArgument('cancel', true); + } }; $this->dispatcher->addListener(Room::class . '::preJoinRoom', $listener); $listener = function(GenericEvent $event) { /** @var Room $room */ $room = $event->getSubject(); - $this->preventGuestsFromJoining($room); + try { + $this->preventGuestsFromJoining($room); + } catch (UnauthorizedException $e) { + $event->setArgument('cancel', true); + } }; $this->dispatcher->addListener(Room::class . '::preJoinRoomGuest', $listener); } @@ -83,7 +92,7 @@ class Listener { * * @param Room $room * @param string $userId - * @throws \Exception + * @throws UnauthorizedException */ public function preventUsersWithoutDirectAccessToTheFileFromJoining(Room $room, string $userId) { if ($room->getObjectType() !== 'file') { @@ -92,7 +101,7 @@ class Listener { $share = $this->util->getAnyDirectShareOfFileAccessibleByUser($room->getObjectId(), $userId); if (!$share) { - throw new \Exception('User does not have direct access to the file'); + throw new UnauthorizedException('User does not have direct access to the file'); } } @@ -102,14 +111,14 @@ class Listener { * This method should be called before a guest joins a room. * * @param Room $room - * @throws \Exception + * @throws UnauthorizedException */ public function preventGuestsFromJoining(Room $room) { if ($room->getObjectType() !== 'file') { return; } - throw new \Exception('Guests are not allowed in rooms for files'); + throw new UnauthorizedException('Guests are not allowed in rooms for files'); } } |