From 316148480c5b6a55d5e4ab6401b019df97e3e282 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 26 Sep 2024 17:50:18 +0200 Subject: [PATCH 1/2] fix(federation): Update invitation information when receiving a re-invite Signed-off-by: Joas Schilling --- lib/Federation/FederationManager.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Federation/FederationManager.php b/lib/Federation/FederationManager.php index 4c3706b9d51..272f6f79b73 100644 --- a/lib/Federation/FederationManager.php +++ b/lib/Federation/FederationManager.php @@ -103,8 +103,14 @@ public function addRemoteRoom( if ($couldHaveInviteWithOtherCasing) { try { - $this->invitationMapper->getInvitationForUserByLocalRoom($room, $user->getUID(), true); - throw new ProviderCouldNotAddShareException('User already invited', '', Http::STATUS_BAD_REQUEST); + $invitation = $this->invitationMapper->getInvitationForUserByLocalRoom($room, $user->getUID(), true); + $invitation->setAccessToken($sharedSecret); + $invitation->setRemoteAttendeeId($remoteAttendeeId); + $invitation->setInviterCloudId($inviterCloudId); + $invitation->setInviterDisplayName($inviterDisplayName); + $this->invitationMapper->update($invitation); + + return $invitation; } catch (DoesNotExistException) { // Not invited with any casing already, so all good. } From 04febb2574f08be4a5eedc042aa6b3a1757b00b6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 26 Sep 2024 17:57:38 +0200 Subject: [PATCH 2/2] fix(federation): Also reset information for the attendee Signed-off-by: Joas Schilling --- lib/Federation/BackendNotifier.php | 3 +++ lib/Federation/FederationManager.php | 17 +++++++++++++++-- tests/php/Federation/FederationTest.php | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Federation/BackendNotifier.php b/lib/Federation/BackendNotifier.php index db891f07c92..809d55c2271 100644 --- a/lib/Federation/BackendNotifier.php +++ b/lib/Federation/BackendNotifier.php @@ -81,6 +81,9 @@ public function sendRemoteShare( $roomOwner = $this->userManager->get($roomOwnerAttendee->getActorId()); $remote = $this->prepareRemoteUrl($invitedCloudId->getRemote()); + if (str_starts_with($remote, 'https://')) { + $remote = substr($remote, 8); + } $shareWithCloudId = $invitedCloudId->getUser() . '@' . $remote; $share = $this->cloudFederationFactory->getCloudFederationShare( diff --git a/lib/Federation/FederationManager.php b/lib/Federation/FederationManager.php index 272f6f79b73..685dcfacea1 100644 --- a/lib/Federation/FederationManager.php +++ b/lib/Federation/FederationManager.php @@ -10,10 +10,12 @@ use OCA\Talk\AppInfo\Application; use OCA\Talk\Exceptions\CannotReachRemoteException; +use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Exceptions\UnauthorizedException; use OCA\Talk\Manager; use OCA\Talk\Model\Attendee; +use OCA\Talk\Model\AttendeeMapper; use OCA\Talk\Model\Invitation; use OCA\Talk\Model\InvitationMapper; use OCA\Talk\Participant; @@ -21,8 +23,6 @@ use OCA\Talk\Service\ParticipantService; use OCA\Talk\Service\RoomService; use OCP\AppFramework\Db\DoesNotExistException; -use OCP\AppFramework\Http; -use OCP\Federation\Exceptions\ProviderCouldNotAddShareException; use OCP\Federation\ICloudId; use OCP\Federation\ICloudIdManager; use OCP\IUser; @@ -53,6 +53,7 @@ public function __construct( private ParticipantService $participantService, private RoomService $roomService, private InvitationMapper $invitationMapper, + private AttendeeMapper $attendeeMapper, private BackendNotifier $backendNotifier, private IManager $notificationManager, private ICloudIdManager $cloudIdManager, @@ -108,6 +109,18 @@ public function addRemoteRoom( $invitation->setRemoteAttendeeId($remoteAttendeeId); $invitation->setInviterCloudId($inviterCloudId); $invitation->setInviterDisplayName($inviterDisplayName); + + if ($invitation->getState() === Invitation::STATE_ACCEPTED) { + try { + $participant = $this->participantService->getParticipantByActor($room, Attendee::ACTOR_USERS, $user->getUID()); + $attendee = $participant->getAttendee(); + $attendee->setAccessToken($sharedSecret); + $attendee->setRemoteId((string)$remoteAttendeeId); + $this->attendeeMapper->update($attendee); + } catch (ParticipantNotFoundException) { + $invitation->setState(Invitation::STATE_PENDING); + } + } $this->invitationMapper->update($invitation); return $invitation; diff --git a/tests/php/Federation/FederationTest.php b/tests/php/Federation/FederationTest.php index 94c465503e2..1724014347a 100644 --- a/tests/php/Federation/FederationTest.php +++ b/tests/php/Federation/FederationTest.php @@ -145,7 +145,7 @@ public function testSendRemoteShareWithOwner(): void { $providerId = '3'; $token = 'abcdefghijklmno'; - $shareWith = 'test@https://remote.test.local'; + $shareWith = 'test@remote.test.local'; $name = 'abcdefgh'; $owner = 'Owner\'s name'; $ownerId = 'owner';