Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions lib/Controller/RoomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->logger->debug('Failed to get calendar to schedule a meeting', ['exception' => $e]);
$this->logger->error('Failed to get calendar to schedule a meeting', ['exception' => $e]);

return new DataResponse(['error' => 'calendar'], Http::STATUS_BAD_REQUEST);
}

$this->authTokenProvider->invalidateToken($token);
Copy link
Member

Choose a reason for hiding this comment

The 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?
Should we add a sanity background job to clear those up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I think a finally will work.


return new DataResponse(null, Http::STATUS_OK);
}
}
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
</UndefinedDocblockClass>
</issueHandlers>
<stubs>
<file name="tests/stubs/oc_authentication_token_provider.php" />
<file name="tests/stubs/oc_comments_comment.php" />
<file name="tests/stubs/oc_comments_manager.php" />
<file name="tests/stubs/oc_core_command_base.php" />
Expand Down
8 changes: 0 additions & 8 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@
<code><![CDATA[EditingCircleEvent]]></code>
</UndefinedClass>
</file>
<file src="lib/MatterbridgeManager.php">
<UndefinedClass>
<code><![CDATA[$this->tokenProvider]]></code>
<code><![CDATA[$this->tokenProvider]]></code>
<code><![CDATA[$this->tokenProvider]]></code>
<code><![CDATA[private]]></code>
</UndefinedClass>
</file>
<file src="lib/Migration/Version2001Date20170707115443.php">
<InvalidArrayAccess>
<code><![CDATA[$return['num_rooms']]]></code>
Expand Down
35 changes: 35 additions & 0 deletions tests/stubs/oc_authentication_token_provider.php
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;
}
}
Loading