diff options
author | provokateurin <kate@provokateurin.de> | 2024-10-22 13:18:17 +0200 |
---|---|---|
committer | provokateurin <kate@provokateurin.de> | 2024-11-25 10:27:31 +0100 |
commit | a978e0a806901588a008ac2b71d825aae7541322 (patch) | |
tree | 705088b94fc21882750afcc85a0e35f8a065733c | |
parent | 762b09049be3abdd8326e0b395faa76226f88612 (diff) | |
download | nextcloud-server-a978e0a806901588a008ac2b71d825aae7541322.tar.gz nextcloud-server-a978e0a806901588a008ac2b71d825aae7541322.zip |
fix(Share20\DefaultShareProvider): Return link shares in getSharesByPath()
Signed-off-by: provokateurin <kate@provokateurin.de>
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 3 | ||||
-rw-r--r-- | tests/lib/Share20/DefaultShareProviderTest.php | 85 |
2 files changed, 87 insertions, 1 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 0a22c6e6a4c..40fbae541ce 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -798,7 +798,8 @@ class DefaultShareProvider implements IShareProviderWithNotification, IShareProv ->andWhere( $qb->expr()->orX( $qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_USER)), - $qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)) + $qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_GROUP)), + $qb->expr()->eq('share_type', $qb->createNamedParameter(IShare::TYPE_LINK)), ) ) ->andWhere($qb->expr()->orX( diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index 0351504e1a7..394ca41c1ae 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -7,6 +7,7 @@ namespace Test\Share20; +use OC\Files\Node\Node; use OC\Share20\DefaultShareProvider; use OC\Share20\ShareAttributes; use OCP\AppFramework\Utility\ITimeFactory; @@ -3013,4 +3014,88 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals('token5', $share->getToken()); $this->assertEquals('myTarget5', $share->getTarget()); } + + + public function testGetSharesByPath(): void { + $qb = $this->dbConn->getQueryBuilder(); + + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(IShare::TYPE_USER), + 'uid_owner' => $qb->expr()->literal('user1'), + 'uid_initiator' => $qb->expr()->literal('user1'), + 'share_with' => $qb->expr()->literal('user2'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(1), + ]); + $qb->execute(); + + $id1 = $qb->getLastInsertId(); + + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(IShare::TYPE_GROUP), + 'uid_owner' => $qb->expr()->literal('user1'), + 'uid_initiator' => $qb->expr()->literal('user1'), + 'share_with' => $qb->expr()->literal('user2'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(1), + ]); + $qb->execute(); + + $id2 = $qb->getLastInsertId(); + + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(IShare::TYPE_LINK), + 'uid_owner' => $qb->expr()->literal('user1'), + 'uid_initiator' => $qb->expr()->literal('user1'), + 'share_with' => $qb->expr()->literal('user2'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(1), + ]); + $qb->execute(); + + $id3 = $qb->getLastInsertId(); + + $ownerPath1 = $this->createMock(File::class); + $shareOwner1Folder = $this->createMock(Folder::class); + $shareOwner1Folder->method('getFirstNodeById')->willReturn($ownerPath1); + + $ownerPath2 = $this->createMock(File::class); + $shareOwner2Folder = $this->createMock(Folder::class); + $shareOwner2Folder->method('getFirstNodeById')->willReturn($ownerPath2); + + $ownerPath3 = $this->createMock(File::class); + $shareOwner3Folder = $this->createMock(Folder::class); + $shareOwner3Folder->method('getFirstNodeById')->willReturn($ownerPath3); + + $this->rootFolder + ->method('getUserFolder') + ->willReturnMap( + [ + ['shareOwner1', $shareOwner1Folder], + ['shareOwner2', $shareOwner2Folder], + ['shareOwner3', $shareOwner3Folder], + ] + ); + + $node = $this->createMock(Node::class); + $node + ->expects($this->once()) + ->method('getId') + ->willReturn(1); + + $shares = $this->provider->getSharesByPath($node); + $this->assertCount(3, $shares); + + $this->assertEquals($id1, $shares[0]->getId()); + $this->assertEquals(IShare::TYPE_USER, $shares[0]->getShareType()); + + $this->assertEquals($id2, $shares[1]->getId()); + $this->assertEquals(IShare::TYPE_GROUP, $shares[1]->getShareType()); + + $this->assertEquals($id3, $shares[2]->getId()); + $this->assertEquals(IShare::TYPE_LINK, $shares[2]->getShareType()); + } } |