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
4 changes: 2 additions & 2 deletions apps/dav/lib/Connector/Sabre/ShareTypeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ShareTypeList implements Element {
public const NS_OWNCLOUD = 'http://owncloud.org/ns';

/**
* @param int[] $shareTypes
* @param list<int> $shareTypes
*/
public function __construct(
/**
Expand All @@ -34,7 +34,7 @@ public function __construct(
/**
* Returns the share types
*
* @return int[]
* @return list<int>
*/
public function getShareTypes() {
return $this->shareTypes;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/SharesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function handleGetProperties(

$propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode): ShareTypeList {
$shares = $this->getShares($sabreNode);
$shareTypes = array_unique(array_map(static fn (IShare $share): int => $share->getShareType(), $shares));
$shareTypes = array_values(array_unique(array_map(static fn (IShare $share): int => $share->getShareType(), $shares)));

return new ShareTypeList($shareTypes);
});
Expand Down
35 changes: 35 additions & 0 deletions apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,41 @@ public function testPreloadThenGetProperties(array $shareTypes): void {
$this->assertEquals($shareTypes, $result[200][self::SHARETYPES_PROPERTYNAME]->getShareTypes());
}

public function testGetPropertiesReturnsListWithRepeatedShareTypes(): void {
$sabreNode = $this->createMock(Node::class);
$sabreNode->method('getId')->willReturn(123);
$sabreNode->method('getPath')->willReturn('/subdir');
$sabreNode->method('getNode')->willReturn($this->createMock(Folder::class));

// Two user shares and one link share on the same node
$shareOfType = function (int $type): IShare {
$share = $this->createMock(IShare::class);
$share->method('getShareType')->willReturn($type);
return $share;
};
$this->shareManager->method('getSharesBy')
->willReturnCallback(fn ($userId, int $requestedShareType) => match ($requestedShareType) {
IShare::TYPE_USER => [$shareOfType(IShare::TYPE_USER), $shareOfType(IShare::TYPE_USER)],
IShare::TYPE_LINK => [$shareOfType(IShare::TYPE_LINK)],
default => [],
});
$this->shareManager->method('getSharedWith')->willReturn([]);

$propFind = new \Sabre\DAV\PropFind(
'/dummyPath',
[self::SHARETYPES_PROPERTYNAME],
0
);

$this->plugin->handleGetProperties(
$propFind,
$sabreNode
);

$result = $propFind->getResultForMultiStatus();
$this->assertSame([IShare::TYPE_USER, IShare::TYPE_LINK], $result[200][self::SHARETYPES_PROPERTYNAME]->getShareTypes());
}

public static function sharesGetPropertiesDataProvider(): array {
return [
[[]],
Expand Down
Loading