Skip to content
Merged
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
57 changes: 52 additions & 5 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 @@ -81,21 +83,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 @@ -148,6 +152,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 @@ -2835,7 +2843,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 @@ -2919,13 +2928,51 @@ 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 {
$eventBuilder->createInCalendar($calendar);
} catch (\InvalidArgumentException|CalendarException $e) {
$this->logger->debug('Failed to get calendar to schedule a meeting', ['exception' => $e]);
$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->error('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 {
$client->put($calendarUri, $options);
} catch (\Exception $e) {
$this->logger->error('Failed to get calendar to schedule a meeting', ['exception' => $e]);
return new DataResponse(['error' => 'calendar'], Http::STATUS_BAD_REQUEST);
} finally {
$this->authTokenProvider->invalidateToken($token);
}


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 @@ -85,6 +85,7 @@
</UnimplementedInterfaceMethod>
</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 @@ -80,14 +80,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