Skip to content

Commit 43efac3

Browse files
committed
Use the correct mountpoint to calculate
If we use the owners mount point this results in null. And then the rest of the checks get called with null. Which doesn't work. Signed-off-by: Roeland Jago Douma <[email protected]>
1 parent 8f4d533 commit 43efac3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/private/Share20/Manager.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,20 @@ protected function generalCreateChecks(IShare $share) {
298298

299299
$isFederatedShare = $share->getNode()->getStorage()->instanceOfStorage('\OCA\Files_Sharing\External\Storage');
300300
$permissions = 0;
301-
$mount = $share->getNode()->getMountPoint();
301+
302+
$userMounts = $userFolder->getById($share->getNode()->getId());
303+
$userMount = array_shift($userMounts);
304+
$mount = $userMount->getMountPoint();
302305
if (!$isFederatedShare && $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy()) {
303306
// When it's a reshare use the parent share permissions as maximum
304307
$userMountPointId = $mount->getStorageRootId();
305308
$userMountPoints = $userFolder->getById($userMountPointId);
306309
$userMountPoint = array_shift($userMountPoints);
307310

311+
if ($userMountPoint === null) {
312+
throw new GenericShareException('Could not get proper user mount for ' . $userMountPointId . '. Failing since else the next calls are called with null');
313+
}
314+
308315
/* Check if this is an incoming share */
309316
$incomingShares = $this->getSharedWith($share->getSharedBy(), IShare::TYPE_USER, $userMountPoint, -1, 0);
310317
$incomingShares = array_merge($incomingShares, $this->getSharedWith($share->getSharedBy(), IShare::TYPE_GROUP, $userMountPoint, -1, 0));

tests/lib/Share20/ManagerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ public function dataGeneralChecks() {
613613
$limitedPermssions = $this->createMock(File::class);
614614
$limitedPermssions->method('isShareable')->willReturn(true);
615615
$limitedPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ);
616+
$limitedPermssions->method('getId')->willReturn(108);
616617
$limitedPermssions->method('getPath')->willReturn('path');
617618
$limitedPermssions->method('getOwner')
618619
->willReturn($owner);
@@ -634,6 +635,7 @@ public function dataGeneralChecks() {
634635
$nonMoveableMountPermssions = $this->createMock(Folder::class);
635636
$nonMoveableMountPermssions->method('isShareable')->willReturn(true);
636637
$nonMoveableMountPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ);
638+
$nonMoveableMountPermssions->method('getId')->willReturn(108);
637639
$nonMoveableMountPermssions->method('getPath')->willReturn('path');
638640
$nonMoveableMountPermssions->method('getOwner')
639641
->willReturn($owner);
@@ -655,6 +657,7 @@ public function dataGeneralChecks() {
655657
$allPermssions = $this->createMock(Folder::class);
656658
$allPermssions->method('isShareable')->willReturn(true);
657659
$allPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL);
660+
$allPermssions->method('getId')->willReturn(108);
658661
$allPermssions->method('getOwner')
659662
->willReturn($owner);
660663
$allPermssions->method('getStorage')
@@ -675,6 +678,7 @@ public function dataGeneralChecks() {
675678
$remoteFile = $this->createMock(Folder::class);
676679
$remoteFile->method('isShareable')->willReturn(true);
677680
$remoteFile->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ ^ \OCP\Constants::PERMISSION_UPDATE);
681+
$remoteFile->method('getId')->willReturn(108);
678682
$remoteFile->method('getOwner')
679683
->willReturn($owner);
680684
$remoteFile->method('getStorage')
@@ -709,6 +713,11 @@ public function testGeneralChecks($share, $exceptionMessage, $exception) {
709713
$userFolder->expects($this->any())
710714
->method('getId')
711715
->willReturn(42);
716+
// Id 108 is used in the data to refer to the node of the share.
717+
$userFolder->expects($this->any())
718+
->method('getById')
719+
->with(108)
720+
->willReturn([$share->getNode()]);
712721
$userFolder->expects($this->any())
713722
->method('getRelativePath')
714723
->willReturnArgument(0);

0 commit comments

Comments
 (0)