Skip to content
Open
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
5 changes: 4 additions & 1 deletion lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,9 @@ private function _getSharedWith(
/*
* Resolve all group shares to user specific shares
*/
if ($shares2 === []) {
return [];
}
$shares = $this->resolveGroupShares($shares2, $userId, $path, $forChildren);
Comment on lines +1074 to 1077

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The test should be inside resolveGroupShares, if share list is empty it should early return.

} else {
throw new BackendError('Invalid backend');
Expand Down Expand Up @@ -1178,7 +1181,7 @@ private function createShare($data): IShare {
/**
* Update the data from group shares with any per-user modifications
*
* @param array<int, Share> $shareMap shares indexed by share id
* @param non-empty-array<int, Share> $shareMap shares indexed by share id
* @param $userId
* @return Share[] The updates shares if no update is found for a share return the original
*/
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/Share20/DefaultShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -1064,6 +1065,19 @@ public function testGetSharedWithUser($storageStringId, $fileName1, $fileName2):
$this->assertEquals(IShare::TYPE_USER, $share->getShareType());
}

#[TestWith([[], 0])]
#[TestWith([['group1', 'group2'], 1])]
public function testGetSharedWithGroupWithoutGroupShares(array $groups, int $expectedQueries): void {
$this->groupManager->method('getUserGroupIds')->willReturn($groups);
$connection = $this->dbConn->getInner();

$queriesBefore = $connection->getStats()['executed'];
$shares = $this->provider->getSharedWithByPath('sharedWith', IShare::TYPE_GROUP, '/sharedWith/files/target', false, -1, 0);

$this->assertSame([], $shares);
$this->assertSame($expectedQueries, $connection->getStats()['executed'] - $queriesBefore);
}

#[\PHPUnit\Framework\Attributes\DataProvider('storageAndFileNameProvider')]
public function testGetSharedWithGroup($storageStringId, $fileName1, $fileName2): void {
$storageId = $this->createTestStorageEntry($storageStringId);
Expand Down
Loading