diff options
author | Joas Schilling <coding@schilljs.com> | 2024-03-12 17:40:56 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2024-03-13 10:51:18 +0100 |
commit | a2ee00c94ce775495bdfbe692076fd48b9e1fe38 (patch) | |
tree | b85c95edd3e8fb043a4c6f44e6e28f902a2782b5 /lib | |
parent | 3aba674cb5e3f32c73feddbc54d2b407efd03eee (diff) |
fix(federation): Use shared logic when removing self from a room
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/RoomController.php | 10 | ||||
-rw-r--r-- | lib/Federation/FederationManager.php | 28 | ||||
-rw-r--r-- | lib/Middleware/InjectionMiddleware.php | 2 | ||||
-rw-r--r-- | lib/Model/InvitationMapper.php | 2 |
4 files changed, 30 insertions, 12 deletions
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index e725eb663..e9ba26e55 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -39,7 +39,7 @@ use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Exceptions\UnauthorizedException; use OCA\Talk\Federation\Authenticator; -use OCA\Talk\Federation\BackendNotifier; +use OCA\Talk\Federation\FederationManager; use OCA\Talk\GuestManager; use OCA\Talk\Manager; use OCA\Talk\MatterbridgeManager; @@ -126,7 +126,7 @@ class RoomController extends AEnvironmentAwareController { protected LoggerInterface $logger, protected Authenticator $federationAuthenticator, protected Capabilities $capabilities, - protected BackendNotifier $federationBackendNotifier, + protected FederationManager $federationManager, ) { parent::__construct($appName, $request); } @@ -1263,11 +1263,7 @@ class RoomController extends AEnvironmentAwareController { */ protected function removeSelfFromRoomLogic(Room $room, Participant $participant): DataResponse { if ($room->getRemoteServer() !== '') { - $this->federationBackendNotifier->sendShareDeclined( - $room->getRemoteServer(), - (int) $participant->getAttendee()->getRemoteId(), - $participant->getAttendee()->getAccessToken(), - ); + $this->federationManager->rejectByRemoveSelf($room, $this->userId); } if ($room->getType() !== Room::TYPE_ONE_TO_ONE && $room->getType() !== Room::TYPE_ONE_TO_ONE_FORMER) { diff --git a/lib/Federation/FederationManager.php b/lib/Federation/FederationManager.php index 6dfaf27ff..3bfe8824b 100644 --- a/lib/Federation/FederationManager.php +++ b/lib/Federation/FederationManager.php @@ -178,16 +178,38 @@ class FederationManager { throw new \InvalidArgumentException('invitation'); } + if ($invitation->getUserId() !== $user->getUID()) { + throw new UnauthorizedException('user'); + } + if ($invitation->getState() !== Invitation::STATE_PENDING) { throw new \InvalidArgumentException('state'); } - if ($invitation->getUserId() !== $user->getUID()) { - throw new UnauthorizedException('user'); + $this->rejectInvitation($invitation, $user->getUID()); + } + + /** + * @throws \InvalidArgumentException + * @throws UnauthorizedException + */ + public function rejectByRemoveSelf(Room $room, string $userId): void { + try { + $invitation = $this->invitationMapper->getInvitationForUserByLocalRoom($room, $userId); + } catch (DoesNotExistException $e) { + throw new \InvalidArgumentException('invitation'); } + $this->rejectInvitation($invitation, $userId); + } + + /** + * @throws \InvalidArgumentException + * @throws UnauthorizedException + */ + protected function rejectInvitation(Invitation $invitation, string $userId): void { $this->invitationMapper->delete($invitation); - $this->markNotificationProcessed($user->getUID(), $shareId); + $this->markNotificationProcessed($userId, $invitation->getId()); $this->backendNotifier->sendShareDeclined($invitation->getRemoteServerUrl(), $invitation->getRemoteAttendeeId(), $invitation->getAccessToken()); } diff --git a/lib/Middleware/InjectionMiddleware.php b/lib/Middleware/InjectionMiddleware.php index 31b961d24..d908d9122 100644 --- a/lib/Middleware/InjectionMiddleware.php +++ b/lib/Middleware/InjectionMiddleware.php @@ -264,7 +264,7 @@ class InjectionMiddleware extends Middleware { $participant = $controller->getParticipant(); if (!$participant instanceof Participant) { try { - $invitation = $this->invitationMapper->getInvitationsForUserByLocalRoom($room, $this->userId); + $invitation = $this->invitationMapper->getInvitationForUserByLocalRoom($room, $this->userId); $controller->setRoom($room); $controller->setInvitation($invitation); } catch (DoesNotExistException $e) { diff --git a/lib/Model/InvitationMapper.php b/lib/Model/InvitationMapper.php index ceb4593f7..5568f2fab 100644 --- a/lib/Model/InvitationMapper.php +++ b/lib/Model/InvitationMapper.php @@ -98,7 +98,7 @@ class InvitationMapper extends QBMapper { /** * @throws DoesNotExistException */ - public function getInvitationsForUserByLocalRoom(Room $room, string $userId): Invitation { + public function getInvitationForUserByLocalRoom(Room $room, string $userId): Invitation { $query = $this->db->getQueryBuilder(); $query->select('*') |