UPSTREAM BASELINE: nextcloud/spreed v22.0.12 (без изменений)
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled

Источник: https://github.com/nextcloud/spreed/archive/refs/tags/v22.0.12.tar.gz
С этого коммита ветка официального Nextcloud Talk отрезана (решение владельца 2026-07-06).
Все дальнейшие изменения — только наши; версии релизов: 22.0.12-f7.N.
This commit is contained in:
2026-07-06 14:07:50 +00:00
commit 01acfa3b40
1716 changed files with 613013 additions and 0 deletions
+163
View File
@@ -0,0 +1,163 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Files;
use OCA\Talk\Events\BeforeGuestJoinedRoomEvent;
use OCA\Talk\Events\BeforeUserJoinedRoomEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\UnauthorizedException;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Room;
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\TalkSession;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IUserManager;
/**
* Custom behaviour for rooms for files.
*
* The rooms for files are intended to give the users a way to talk about a
* specific shared file, for example, when collaboratively editing it. The room
* is persistent and can be accessed simultaneously by any user or guest if the
* file is publicly shared (link share, for example), or by any user with direct
* access (user, group, circle and room share, but not link share, for example)
* to that file (or to an ancestor). The room has no owner, although self joined
* users with direct access become persistent participants automatically when
* they join until they explicitly leave or no longer have access to the file.
*
* These rooms are associated to a "file" object, and their custom behaviour is
* provided by calling the methods of this class as a response to different room
* events.
*
* @template-implements IEventListener<Event>
*/
class Listener implements IEventListener {
public function __construct(
protected Util $util,
protected ParticipantService $participantService,
protected IUserManager $userManager,
protected TalkSession $talkSession,
) {
}
#[\Override]
public function handle(Event $event): void {
match (get_class($event)) {
BeforeUserJoinedRoomEvent::class => $this->beforeUserJoinedRoomEvent($event),
BeforeGuestJoinedRoomEvent::class => $this->beforeGuestJoinedRoomEvent($event),
};
}
protected function beforeUserJoinedRoomEvent(BeforeUserJoinedRoomEvent $event): void {
try {
$this->preventUsersWithoutAccessToTheFileFromJoining($event->getRoom(), $event->getUser()->getUID());
$this->addUserAsPersistentParticipant($event->getRoom(), $event->getUser()->getUID());
} catch (UnauthorizedException) {
$event->setCancelJoin(true);
}
}
protected function beforeGuestJoinedRoomEvent(BeforeGuestJoinedRoomEvent $event): void {
try {
$this->preventGuestsFromJoiningIfNotPubliclyAccessible($event->getRoom());
} catch (UnauthorizedException) {
$event->setCancelJoin(true);
}
}
/**
* Prevents users from joining if they do not have access to the file.
*
* A user has access to the file if the file is publicly accessible (through
* a link share, for example) or if the user has direct access to it.
*
* A user has direct access to a file if they received the file (or an
* ancestor) through a user, group, circle or room share (but not through a
* link share, for example), or if they are the owner of such a file.
*
* This method should be called before a user joins a room.
*
* @param Room $room
* @param string $userId
* @throws UnauthorizedException
*/
protected function preventUsersWithoutAccessToTheFileFromJoining(Room $room, string $userId): void {
if ($room->getObjectType() !== 'file') {
return;
}
// If a guest can access the file then any user can too.
$shareToken = $this->talkSession->getFileShareTokenForRoom($room->getToken());
if ($shareToken && $this->util->canGuestAccessFile($shareToken)) {
return;
}
$node = $this->util->getAnyNodeOfFileAccessibleByUser($room->getObjectId(), $userId);
if ($node === null) {
throw new UnauthorizedException('User does not have access to the file');
}
}
/**
* Add user as a persistent participant of a file room.
*
* Only users with direct access to the file are added as persistent
* participants of the room.
*
* This method should be called before a user joins a room, but only if the
* user should be able to join the room.
*
* @param Room $room
* @param string $userId
*/
protected function addUserAsPersistentParticipant(Room $room, string $userId): void {
if ($room->getObjectType() !== 'file') {
return;
}
if ($this->util->getAnyNodeOfFileAccessibleByUser($room->getObjectId(), $userId) === null) {
return;
}
try {
$this->participantService->getParticipant($room, $userId, false);
} catch (ParticipantNotFoundException $e) {
$user = $this->userManager->get($userId);
$this->participantService->addUsers($room, [[
'actorType' => Attendee::ACTOR_USERS,
'actorId' => $userId,
'displayName' => $user ? $user->getDisplayName() : $userId,
]]);
}
}
/**
* Prevents guests from joining the room if it is not publicly accessible.
*
* This method should be called before a guest joins a room.
*
* @param Room $room
* @throws UnauthorizedException
*/
protected function preventGuestsFromJoiningIfNotPubliclyAccessible(Room $room): void {
if ($room->getObjectType() !== 'file') {
return;
}
$shareToken = $this->talkSession->getFileShareTokenForRoom($room->getToken());
if ($shareToken && $this->util->canGuestAccessFile($shareToken)) {
return;
}
throw new UnauthorizedException('Guests are not allowed in this room');
}
}
+92
View File
@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Files;
use OCA\Files\Event\LoadSidebar;
use OCA\Talk\AppInfo\Application;
use OCA\Talk\Config;
use OCA\Talk\TInitialState;
use OCP\App\IAppManager;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\IRootFolder;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Util;
use Psr\Log\LoggerInterface;
/**
* Helper class to add the Talk UI to the sidebar of the Files app.
*
* @template-implements IEventListener<Event>
*/
class TemplateLoader implements IEventListener {
use TInitialState;
public function __construct(
IInitialState $initialState,
ICacheFactory $memcacheFactory,
Config $talkConfig,
IConfig $serverConfig,
private IAppManager $appManager,
private IRootFolder $rootFolder,
private IUserSession $userSession,
IGroupManager $groupManager,
protected IRequest $request,
LoggerInterface $logger,
) {
$this->initialState = $initialState;
$this->memcacheFactory = $memcacheFactory;
$this->talkConfig = $talkConfig;
$this->serverConfig = $serverConfig;
$this->groupManager = $groupManager;
$this->logger = $logger;
}
/**
* Loads the Talk UI in the sidebar of the Files app.
*
* This method should be called when handling the LoadSidebar event of the
* Files app.
*
* @param Event $event
*/
#[\Override]
public function handle(Event $event): void {
if (!($event instanceof LoadSidebar)) {
return;
}
if ($this->serverConfig->getAppValue('spreed', 'conversations_files', '1') !== '1') {
return;
}
$user = $this->userSession->getUser();
if ($user instanceof IUser && $this->talkConfig->isDisabledForUser($user)) {
return;
}
Util::addStyle(Application::APP_ID, 'talk-icons');
if (!str_starts_with($this->request->getPathInfo(), '/apps/maps')) {
Util::addScript(Application::APP_ID, 'talk-files-sidebar');
Util::addStyle(Application::APP_ID, 'talk-files-sidebar');
}
if ($user instanceof IUser) {
$this->publishInitialStateForUser($user, $this->rootFolder, $this->appManager);
} else {
$this->publishInitialStateForGuest();
}
}
}
+122
View File
@@ -0,0 +1,122 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Files;
use OCA\Files_Sharing\SharedStorage;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\FileInfo;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\ISession;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager as IShareManager;
class Util {
/** @var array[] */
private array $accessLists = [];
/** @var bool[] */
private array $publicAccessLists = [];
public function __construct(
private IRootFolder $rootFolder,
private ISession $session,
private IShareManager $shareManager,
private IUserMountCache $userMountCache,
) {
}
/**
* @return string[]
*/
public function getUsersWithAccessFile(string $fileId): array {
if (!isset($this->accessLists[$fileId])) {
$nodes = $this->rootFolder->getById((int)$fileId);
if (empty($nodes)) {
return [];
}
$node = array_shift($nodes);
$accessList = $this->shareManager->getAccessList($node);
$accessList['users'] ??= [];
if (!$node->getStorage()->instanceOfStorage(SharedStorage::class)) {
// The file is not a shared file,
// let's check the accesslist for mount points of groupfolders and external storages
$mountsForFile = $this->userMountCache->getMountsForFileId($fileId);
$affectedUserIds = array_map(function (ICachedMountInfo $mount) {
return $mount->getUser()->getUID();
}, $mountsForFile);
$accessList['users'] = array_unique(array_merge($affectedUserIds, $accessList['users']));
}
$this->accessLists[$fileId] = $accessList['users'];
}
return $this->accessLists[$fileId];
}
public function canUserAccessFile(string $fileId, string $userId): bool {
return \in_array($userId, $this->getUsersWithAccessFile($fileId), true);
}
public function canGuestsAccessFile(string $fileId): bool {
if (!isset($this->publicAccessLists[$fileId])) {
$nodes = $this->rootFolder->getById((int)$fileId);
if (empty($nodes)) {
return false;
}
$node = array_shift($nodes);
$accessList = $this->shareManager->getAccessList($node, false);
$this->publicAccessLists[$fileId] = $accessList['public'] ?? false;
}
return $this->publicAccessLists[$fileId] === true;
}
public function canGuestAccessFile(string $shareToken): bool {
try {
$share = $this->shareManager->getShareByToken($shareToken);
if ($share->getPassword() !== null) {
$shareId = $this->session->get('public_link_authenticated');
if ($share->getId() !== $shareId) {
throw new ShareNotFound();
}
}
return true;
} catch (ShareNotFound $e) {
return false;
}
}
/**
* Returns any node of the file that is public and owned by the user, or
* that the user has direct access to.
*
* @param string $fileId
* @param string $userId
* @return Node|null
*/
public function getAnyNodeOfFileAccessibleByUser(string $fileId, string $userId): ?Node {
$userFolder = $this->rootFolder->getUserFolder($userId);
$nodes = $userFolder->getById((int)$fileId);
$nodes = array_filter($nodes, static function (Node $node) {
return $node->getType() === FileInfo::TYPE_FILE;
});
if (empty($nodes)) {
return null;
}
return array_shift($nodes);
}
}