diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index 8764407fbb5..71cbf5eee06 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -8,6 +8,8 @@ namespace OCA\Talk\Controller; +use OC\Authentication\Token\IProvider; +use OC\Authentication\Token\IToken; use OCA\Circles\Model\Circle; use OCA\Talk\Capabilities; use OCA\Talk\Config; @@ -82,21 +84,23 @@ use OCP\AppFramework\Services\IAppConfig; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Calendar\CalendarEventStatus; -use OCP\Calendar\Exceptions\CalendarException; use OCP\Calendar\ICreateFromString; use OCP\Calendar\IManager as ICalendarManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudIdManager; +use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; use OCP\IL10N; use OCP\IPhoneNumberUtil; use OCP\IRequest; +use OCP\ISession; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\Security\Bruteforce\IThrottler; +use OCP\Security\ISecureRandom; use OCP\User\Events\UserLiveStatusEvent; use OCP\UserStatus\IManager as IUserStatusManager; use OCP\UserStatus\IUserStatus; @@ -149,6 +153,10 @@ public function __construct( protected BanService $banService, protected IURLGenerator $url, protected IL10N $l, + protected IClientService $clientService, + protected IProvider $authTokenProvider, + protected ISession $serverSession, + protected ISecureRandom $random, ) { parent::__construct($appName, $request); } @@ -2854,7 +2862,8 @@ public function scheduleMeeting(string $calendarUri, int $start, ?array $attende } $eventBuilder = $this->calendarManager->createEventBuilder(); - $calendars = $this->calendarManager->getCalendarsForPrincipal('principals/users/' . $this->userId, [$calendarUri]); + $principalUri = 'principals/users/' . $this->userId; + $calendars = $this->calendarManager->getCalendarsForPrincipal($principalUri, [$calendarUri]); if (empty($calendars)) { return new DataResponse(['error' => 'calendar'], Http::STATUS_BAD_REQUEST); @@ -2936,13 +2945,50 @@ public function scheduleMeeting(string $calendarUri, int $start, ?array $attende ); } + $ics = $eventBuilder->toIcs(); + $name = $this->room->getToken() . '-' . $this->timeFactory->getTime() . '.ics'; + $calendarUri = $this->url->getBaseUrl() . '/remote.php/dav/calendars/' . $user->getUID() . '/' . $calendar->getUri() . '/' . $name; + + try { + $loginname = $this->serverSession->get('loginname'); + $token = $this->random->generate(72, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); + + $this->authTokenProvider->generateToken( + $token, + $user->getUID(), + $loginname, + null, + 'Nextcloud Spreed Calendar Integration', + IToken::TEMPORARY_TOKEN, + IToken::DO_NOT_REMEMBER + ); + } catch (\Exception $e) { + $this->logger->debug('Failed to get calendar to schedule a meeting', ['exception' => $e]); + return new DataResponse(['error' => 'calendar'], Http::STATUS_BAD_REQUEST); + } + + $client = $this->clientService->newClient(); + $options = [ + 'headers' => [ + 'Content-Type' => 'text/html; charset=UTF-8', + ], + 'nextcloud' => [ + 'allow_local_address' => true, + ], + 'body' => $ics, + 'verify' => false, + 'auth' => [$loginname, $token], + ]; + try { - $eventBuilder->createInCalendar($calendar); - } catch (\InvalidArgumentException|CalendarException $e) { + $client->put($calendarUri, $options); + } catch (\Exception $e) { $this->logger->debug('Failed to get calendar to schedule a meeting', ['exception' => $e]); return new DataResponse(['error' => 'calendar'], Http::STATUS_BAD_REQUEST); } + $this->authTokenProvider->invalidateToken($token); + return new DataResponse(null, Http::STATUS_OK); } } diff --git a/psalm.xml b/psalm.xml index 641e397c11f..d103ac56efa 100644 --- a/psalm.xml +++ b/psalm.xml @@ -70,6 +70,7 @@ + diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index d0014c298eb..83a56d6206b 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -85,14 +85,6 @@ - - - tokenProvider]]> - tokenProvider]]> - tokenProvider]]> - - - diff --git a/tests/stubs/oc_authentication_token_provider.php b/tests/stubs/oc_authentication_token_provider.php new file mode 100644 index 00000000000..fba6e97ad48 --- /dev/null +++ b/tests/stubs/oc_authentication_token_provider.php @@ -0,0 +1,35 @@ +