-
Notifications
You must be signed in to change notification settings - Fork 509
fix: Calendar invitation emails for Events created from Talk #15575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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]); | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| return new DataResponse(['error' => 'calendar'], Http::STATUS_BAD_REQUEST); | ||||||
| } | ||||||
|
|
||||||
| $this->authTokenProvider->invalidateToken($token); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to be in a finally block or also inside the catch?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I think a |
||||||
|
|
||||||
| return new DataResponse(null, Http::STATUS_OK); | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OC\Authentication\Token { | ||
|
|
||
| use OCP\Authentication\Token\IToken as OCPIToken; | ||
|
|
||
| interface IToken extends \JsonSerializable { | ||
| public const TEMPORARY_TOKEN = 0; | ||
| public const DO_NOT_REMEMBER = 0; | ||
|
|
||
| } | ||
|
|
||
| interface IProvider { | ||
| public function generateToken(string $token, | ||
| string $uid, | ||
| string $loginName, | ||
| ?string $password, | ||
| string $name, | ||
| int $type = OCPIToken::TEMPORARY_TOKEN, | ||
| int $remember = OCPIToken::DO_NOT_REMEMBER, | ||
| ?array $scope = null, | ||
| ): IToken; | ||
|
|
||
| public function invalidateToken(string $token); | ||
|
|
||
| public function invalidateTokenById(string $uid, int $id); | ||
|
|
||
| public function getTokenByUser(string $uid): array; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.