aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorskjnldsv <skjnldsv@protonmail.com>2024-08-22 10:02:37 +0200
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2024-09-11 11:48:25 +0000
commit338e0451413272c3a676da42eb81b5dfa2fa4d4d (patch)
tree1d93b1398fa5b48000dcb6688a7a0e2386da94e7 /apps
parent1e08f91408058686b970a46f7c30ace6b5e27bab (diff)
downloadnextcloud-server-338e0451413272c3a676da42eb81b5dfa2fa4d4d.tar.gz
nextcloud-server-338e0451413272c3a676da42eb81b5dfa2fa4d4d.zip
fix(files_sharing): adjust permissions from custom edit and delete check methodsbackport/47339/stable30
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php17
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php46
2 files changed, 63 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 8b7a711c0ee..1be1fdbbde9 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -158,6 +158,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 c47bb6d4395..85dfb9145cf 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -3770,6 +3770,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();
@@ -3830,6 +3836,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => '[{"scope":"permissions","key":"download","value":true}]',
], $share, [], false
];
@@ -3869,6 +3877,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => '[{"scope":"permissions","key":"download","value":true}]',
], $share, [
['owner', $owner],
@@ -3924,6 +3934,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, [], false
];
@@ -3975,6 +3987,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => true,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, [], false
];
@@ -4027,6 +4041,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, [], false
];
@@ -4076,6 +4092,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, [], false
];
@@ -4132,6 +4150,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, [], false
];
@@ -4188,6 +4208,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, [], false
];
@@ -4238,6 +4260,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, [], false
];
@@ -4288,6 +4312,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, [], false
];
@@ -4341,6 +4367,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, [], false
];
@@ -4391,6 +4419,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, [], false
];
@@ -4441,6 +4471,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, [], false
];
@@ -4508,6 +4540,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
];
@@ -4561,6 +4595,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
];
@@ -4612,6 +4648,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => true,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, [], false
];
@@ -4715,6 +4753,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);
@@ -4770,6 +4812,8 @@ class ShareAPIControllerTest extends TestCase {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
+ 'is-mount-root' => false,
+ 'mount-type' => '',
'attributes' => null,
], $share, false, []
];
@@ -4819,6 +4863,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'