diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2024-08-22 10:02:37 +0200 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2024-09-11 13:49:08 +0200 |
commit | 903f717f7d22c73dc50c0470cbd826f74014d3c5 (patch) | |
tree | 04a5833d486634aa94ad0d06b1501a5d021885a9 /apps | |
parent | 0c647d36f0026fda4863f119d47e27a617ccfbe6 (diff) | |
download | nextcloud-server-903f717f7d22c73dc50c0470cbd826f74014d3c5.tar.gz nextcloud-server-903f717f7d22c73dc50c0470cbd826f74014d3c5.zip |
fix(files_sharing): adjust permissions from custom edit and delete check methodsbackport/47339/stable28
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php | 17 | ||||
-rw-r--r-- | apps/files_sharing/tests/Controller/ShareAPIControllerTest.php | 42 |
2 files changed, 59 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 5b32de90787..266c1f9474c 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -190,6 +190,23 @@ class ShareAPIController extends OCSController { if ($isOwnShare) { $result['item_permissions'] = $node->getPermissions(); } + + // If we're on the recipient side, the node permissions + // are bound to the share permissions. So we need to + // adjust the permissions to the share permissions if necessary. + if (!$isOwnShare) { + $result['item_permissions'] = $share->getPermissions(); + + // For some reason, single files share are forbidden to have the delete permission + // since we have custom methods to check those, let's adjust straight away. + // DAV permissions does not have that issue though. + if ($this->canDeleteShare($share) || $this->canDeleteShareFromSelf($share)) { + $result['item_permissions'] |= Constants::PERMISSION_DELETE; + } + if ($this->canEditShare($share)) { + $result['item_permissions'] |= Constants::PERMISSION_UPDATE; + } + } // See MOUNT_ROOT_PROPERTYNAME dav property $result['is-mount-root'] = $node->getInternalPath() === ''; diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index 0a0e2678573..139c8996ae0 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -3757,6 +3757,12 @@ class ShareAPIControllerTest extends TestCase { $folder->method('getStorage')->willReturn($storage); $fileWithPreview->method('getStorage')->willReturn($storage); + + $mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock(); + $mountPoint->method('getMountType')->willReturn(''); + $file->method('getMountPoint')->willReturn($mountPoint); + $folder->method('getMountPoint')->willReturn($mountPoint); + $owner = $this->getMockBuilder(IUser::class)->getMock(); $owner->method('getDisplayName')->willReturn('ownerDN'); $initiator = $this->getMockBuilder(IUser::class)->getMock(); @@ -3911,6 +3917,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -3962,6 +3970,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => true, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4014,6 +4024,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4063,6 +4075,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4119,6 +4133,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4175,6 +4191,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4225,6 +4243,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4275,6 +4295,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4328,6 +4350,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4378,6 +4402,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4428,6 +4454,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4495,6 +4523,8 @@ class ShareAPIControllerTest extends TestCase { 'password_expiration_time' => null, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4548,6 +4578,8 @@ class ShareAPIControllerTest extends TestCase { 'password_expiration_time' => null, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4599,6 +4631,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => true, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, [], false ]; @@ -4702,6 +4736,10 @@ class ShareAPIControllerTest extends TestCase { $file->method('getSize')->willReturn(123456); $file->method('getMTime')->willReturn(1234567890); + $mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock(); + $mountPoint->method('getMountType')->willReturn(''); + $file->method('getMountPoint')->willReturn($mountPoint); + $cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock(); $cache->method('getNumericStorageId')->willReturn(100); $storage = $this->createMock(Storage::class); @@ -4757,6 +4795,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, false, [] ]; @@ -4806,6 +4846,8 @@ class ShareAPIControllerTest extends TestCase { 'can_delete' => false, 'item_size' => 123456, 'item_mtime' => 1234567890, + 'is-mount-root' => false, + 'mount-type' => '', 'attributes' => null, ], $share, true, [ 'share_with_displayname' => 'recipientRoomName' |