Skip to content

Commit beea885

Browse files
committed
feat(files_sharing): Allow users with share permission to manage shares on IShareOwnerlessMount
Signed-off-by: provokateurin <[email protected]>
1 parent b658ab7 commit beea885

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use OCP\Files\Folder;
3636
use OCP\Files\InvalidPathException;
3737
use OCP\Files\IRootFolder;
38+
use OCP\Files\Mount\IShareOwnerlessMount;
3839
use OCP\Files\Node;
3940
use OCP\Files\NotFoundException;
4041
use OCP\HintException;
@@ -1541,6 +1542,12 @@ protected function canEditShare(IShare $share): bool {
15411542
return true;
15421543
}
15431544

1545+
$userFolder = $this->rootFolder->getUserFolder($this->userId);
1546+
$file = $userFolder->getFirstNodeById($share->getNodeId());
1547+
if ($file?->getMountPoint() instanceof IShareOwnerlessMount && $this->shareProviderResharingRights($this->userId, $share, $file)) {
1548+
return true;
1549+
}
1550+
15441551
//! we do NOT support some kind of `admin` in groups.
15451552
//! You cannot edit shares shared to a group you're
15461553
//! a member of if you're not the share owner or the file owner!
@@ -1576,6 +1583,12 @@ protected function canDeleteShare(IShare $share): bool {
15761583
return true;
15771584
}
15781585

1586+
$userFolder = $this->rootFolder->getUserFolder($this->userId);
1587+
$file = $userFolder->getFirstNodeById($share->getNodeId());
1588+
if ($file?->getMountPoint() instanceof IShareOwnerlessMount && $this->shareProviderResharingRights($this->userId, $share, $file)) {
1589+
return true;
1590+
}
1591+
15791592
return false;
15801593
}
15811594

apps/files_sharing/tests/Controller/ShareAPIControllerTest.php

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCP\Files\Folder;
1919
use OCP\Files\IRootFolder;
2020
use OCP\Files\Mount\IMountPoint;
21+
use OCP\Files\Mount\IShareOwnerlessMount;
2122
use OCP\Files\NotFoundException;
2223
use OCP\Files\Storage\IStorage;
2324
use OCP\IConfig;
@@ -232,10 +233,20 @@ public function testDeleteShareLocked(): void {
232233
$this->expectExceptionMessage('Could not delete share');
233234

234235
$node = $this->getMockBuilder(File::class)->getMock();
236+
$node->method('getId')->willReturn(1);
235237

236238
$share = $this->newShare();
237239
$share->setNode($node);
238240

241+
$userFolder = $this->getMockBuilder(Folder::class)->getMock();
242+
$this->rootFolder->method('getUserFolder')
243+
->with($this->currentUser)
244+
->willReturn($userFolder);
245+
246+
$userFolder->method('getFirstNodeById')
247+
->with($share->getNodeId())
248+
->willReturn($node);
249+
239250
$this->shareManager
240251
->expects($this->once())
241252
->method('getShareById')
@@ -476,6 +487,62 @@ public function testDeleteSharedWithGroupIDontBelongTo(): void {
476487
$this->ocs->deleteShare(42);
477488
}
478489

490+
public function testDeleteShareOwnerless(): void {
491+
$ocs = $this->mockFormatShare();
492+
493+
$mount = $this->createMock(IShareOwnerlessMount::class);
494+
495+
$file = $this->createMock(File::class);
496+
$file
497+
->expects($this->exactly(2))
498+
->method('getPermissions')
499+
->willReturn(Constants::PERMISSION_SHARE);
500+
$file
501+
->expects($this->once())
502+
->method('getMountPoint')
503+
->willReturn($mount);
504+
505+
$userFolder = $this->createMock(Folder::class);
506+
$userFolder
507+
->expects($this->exactly(2))
508+
->method('getFirstNodeById')
509+
->with(2)
510+
->willReturn($file);
511+
512+
$this->rootFolder
513+
->method('getUserFolder')
514+
->with($this->currentUser)
515+
->willReturn($userFolder);
516+
517+
$share = $this->createMock(IShare::class);
518+
$share
519+
->expects($this->once())
520+
->method('getNode')
521+
->willReturn($file);
522+
$share
523+
->expects($this->exactly(2))
524+
->method('getNodeId')
525+
->willReturn(2);
526+
$share
527+
->expects($this->exactly(2))
528+
->method('getPermissions')
529+
->willReturn(Constants::PERMISSION_SHARE);
530+
531+
$this->shareManager
532+
->expects($this->once())
533+
->method('getShareById')
534+
->with('ocinternal:1', $this->currentUser)
535+
->willReturn($share);
536+
537+
$this->shareManager
538+
->expects($this->once())
539+
->method('deleteShare')
540+
->with($share);
541+
542+
$result = $ocs->deleteShare(1);
543+
$this->assertInstanceOf(DataResponse::class, $result);
544+
}
545+
479546
/*
480547
* FIXME: Enable once we have a federated Share Provider
481548
@@ -3748,6 +3815,63 @@ public function testUpdateShareCanIncreasePermissionsIfOwner(): void {
37483815
$this->assertInstanceOf(DataResponse::class, $result);
37493816
}
37503817

3818+
public function testUpdateShareOwnerless(): void {
3819+
$ocs = $this->mockFormatShare();
3820+
3821+
$mount = $this->createMock(IShareOwnerlessMount::class);
3822+
3823+
$file = $this->createMock(File::class);
3824+
$file
3825+
->expects($this->exactly(2))
3826+
->method('getPermissions')
3827+
->willReturn(Constants::PERMISSION_SHARE);
3828+
$file
3829+
->expects($this->once())
3830+
->method('getMountPoint')
3831+
->willReturn($mount);
3832+
3833+
$userFolder = $this->createMock(Folder::class);
3834+
$userFolder
3835+
->expects($this->exactly(2))
3836+
->method('getFirstNodeById')
3837+
->with(2)
3838+
->willReturn($file);
3839+
3840+
$this->rootFolder
3841+
->method('getUserFolder')
3842+
->with($this->currentUser)
3843+
->willReturn($userFolder);
3844+
3845+
$share = $this->createMock(IShare::class);
3846+
$share
3847+
->expects($this->once())
3848+
->method('getNode')
3849+
->willReturn($file);
3850+
$share
3851+
->expects($this->exactly(2))
3852+
->method('getNodeId')
3853+
->willReturn(2);
3854+
$share
3855+
->expects($this->exactly(2))
3856+
->method('getPermissions')
3857+
->willReturn(Constants::PERMISSION_SHARE);
3858+
3859+
$this->shareManager
3860+
->expects($this->once())
3861+
->method('getShareById')
3862+
->with('ocinternal:1', $this->currentUser)
3863+
->willReturn($share);
3864+
3865+
$this->shareManager
3866+
->expects($this->once())
3867+
->method('updateShare')
3868+
->with($share)
3869+
->willReturn($share);
3870+
3871+
$result = $ocs->updateShare(1, Constants::PERMISSION_ALL);
3872+
$this->assertInstanceOf(DataResponse::class, $result);
3873+
}
3874+
37513875
public function dataFormatShare() {
37523876
$file = $this->getMockBuilder(File::class)->getMock();
37533877
$folder = $this->getMockBuilder(Folder::class)->getMock();

0 commit comments

Comments
 (0)