Skip to content

Commit

Permalink
fix(files_sharing): adjust permissions from custom edit and delete ch…
Browse files Browse the repository at this point in the history
…eck methods

Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Sep 6, 2024
1 parent 62630ed commit 9e58191
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
if ($isOwnShare) {
$result['item_permissions'] = $node->getPermissions();
}

// Fix permissions if needed
// 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)) {
$result['permissions'] |= Constants::PERMISSION_DELETE;
}
if ($this->canEditShare($share)) {
$result['permissions'] |= Constants::PERMISSION_UPDATE;
}

// See MOUNT_ROOT_PROPERTYNAME dav property
$result['is-mount-root'] = $node->getInternalPath() === '';
Expand Down
46 changes: 46 additions & 0 deletions apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3770,6 +3770,12 @@ public function dataFormatShare() {
$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();
Expand Down Expand Up @@ -3830,6 +3836,8 @@ public function dataFormatShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => '[{"scope":"permissions","key":"download","value":true}]',
], $share, [], false
];
Expand Down Expand Up @@ -3869,6 +3877,8 @@ public function dataFormatShare() {
'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],
Expand Down Expand Up @@ -3924,6 +3934,8 @@ public function dataFormatShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -3975,6 +3987,8 @@ public function dataFormatShare() {
'can_delete' => true,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4027,6 +4041,8 @@ public function dataFormatShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4076,6 +4092,8 @@ public function dataFormatShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4132,6 +4150,8 @@ public function dataFormatShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4188,6 +4208,8 @@ public function dataFormatShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4238,6 +4260,8 @@ public function dataFormatShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4288,6 +4312,8 @@ public function dataFormatShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4341,6 +4367,8 @@ public function dataFormatShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4391,6 +4419,8 @@ public function dataFormatShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4441,6 +4471,8 @@ public function dataFormatShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4508,6 +4540,8 @@ public function dataFormatShare() {
'password_expiration_time' => null,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4561,6 +4595,8 @@ public function dataFormatShare() {
'password_expiration_time' => null,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4612,6 +4648,8 @@ public function dataFormatShare() {
'can_delete' => true,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, [], false
];
Expand Down Expand Up @@ -4715,6 +4753,10 @@ public function dataFormatRoomShare() {
$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);
Expand Down Expand Up @@ -4770,6 +4812,8 @@ public function dataFormatRoomShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, false, []
];
Expand Down Expand Up @@ -4819,6 +4863,8 @@ public function dataFormatRoomShare() {
'can_delete' => false,
'item_size' => 123456,
'item_mtime' => 1234567890,
'is-mount-root' => false,
'mount-type' => '',
'attributes' => null,
], $share, true, [
'share_with_displayname' => 'recipientRoomName'
Expand Down

0 comments on commit 9e58191

Please sign in to comment.