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
6 changes: 5 additions & 1 deletion lib/Chat/AutoComplete/SearchPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public function setContext(array $context): void {
#[\Override]
public function search($search, $limit, $offset, ISearchResult $searchResult): bool {
if ($this->room->getObjectType() === 'file') {
$usersWithFileAccess = $this->util->getUsersWithAccessFile($this->room->getObjectId());
if ($this->userId === null) {
$usersWithFileAccess = $this->util->canGuestsAccessFile($this->room->getObjectId());
} else {
$usersWithFileAccess = $this->util->getUsersWithAccessFile($this->room->getObjectId(), $this->userId);
}
if (!empty($usersWithFileAccess)) {
$users = [];
foreach ($usersWithFileAccess as $userId) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/FilesIntegrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getRoomByFileId(string $fileId): DataResponse {
throw new OCSNotFoundException($this->l->t('File is not shared, or shared but not with the user'));
}

$users = $this->util->getUsersWithAccessFile($fileId);
$users = $this->util->getUsersWithAccessFile($fileId, $currentUser->getUID());
if (count($users) <= 1 && !$this->util->canGuestsAccessFile($fileId)) {
throw new OCSNotFoundException($this->l->t('File is not shared, or shared but not with the user'));
}
Expand Down
15 changes: 7 additions & 8 deletions lib/Files/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public function __construct(
/**
* @return string[]
*/
public function getUsersWithAccessFile(string $fileId): array {
public function getUsersWithAccessFile(string $fileId, string $userId): array {
if (!isset($this->accessLists[$fileId])) {
$nodes = $this->rootFolder->getById((int)$fileId);
$userFolder = $this->rootFolder->getUserFolder($userId);
$node = $userFolder->getFirstNodeById((int)$fileId);

if (empty($nodes)) {
if ($node === null) {
return [];
}

$node = array_shift($nodes);
$accessList = $this->shareManager->getAccessList($node);
$accessList['users'] ??= [];
if (!$node->getStorage()->instanceOfStorage(SharedStorage::class)) {
Expand All @@ -64,18 +64,17 @@ public function getUsersWithAccessFile(string $fileId): array {
}

public function canUserAccessFile(string $fileId, string $userId): bool {
return \in_array($userId, $this->getUsersWithAccessFile($fileId), true);
return \in_array($userId, $this->getUsersWithAccessFile($fileId, $userId), true);
}

public function canGuestsAccessFile(string $fileId): bool {
if (!isset($this->publicAccessLists[$fileId])) {
$nodes = $this->rootFolder->getById((int)$fileId);
$node = $this->rootFolder->getFirstNodeById((int)$fileId);

if (empty($nodes)) {
if ($node === null) {
return false;
}

$node = array_shift($nodes);
$accessList = $this->shareManager->getAccessList($node, false);
$this->publicAccessLists[$fileId] = $accessList['public'] ?? false;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/features/chat-2/mentions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,11 @@ Feature: chat-2/mentions
And user "guest" joins room "file last share room" with 200 (v4)
And user "participant2" is not participant of room "file last share room" (v4)
When user "participant3" sends message "hi @participant2" to room "file last share room" with 201
And user "participant2" is participant of room "file last share room" (v4)
And user "participant2" removes themselves from room "file last share room" with 200 (v4)
And user "participant2" is not participant of room "file last share room" (v4)
And user "guest" sends message "hello @participant2" to room "file last share room" with 201
Then user "participant2" is not participant of room "file last share room" (v4)
Then user "participant2" is participant of room "file last share room" (v4)

Scenario: mention a participant without access to the file but joined in a room for a file shared by link
Given user "participant1" shares "welcome.txt" with user "participant2" with OCS 100
Expand Down
Loading