diff --git a/apps/files_sharing/lib/Cache.php b/apps/files_sharing/lib/Cache.php index 352001ecbd4c1..f3712ead58b66 100644 --- a/apps/files_sharing/lib/Cache.php +++ b/apps/files_sharing/lib/Cache.php @@ -142,7 +142,7 @@ protected function formatCacheEntry($entry, $path = null) { } else { $entry['path'] = $path; } - $sharePermissions = $this->storage->getPermissions($path); + $sharePermissions = $this->storage->getPermissions($entry['path']); if (isset($entry['permissions'])) { $entry['permissions'] &= $sharePermissions; } else { diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index 2d2f14fc55423..34a21fcd63749 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -195,7 +195,8 @@ public function getPermissions($target = '') { if (!$this->isValid()) { return 0; } - $permissions = $this->superShare->getPermissions(); + $permissions = parent::getPermissions($target) & $this->superShare->getPermissions(); + // part files and the mount point always have delete permissions if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') { $permissions |= \OCP\Constants::PERMISSION_DELETE; @@ -257,11 +258,17 @@ public function fopen($path, $mode) { case 'xb': case 'a': case 'ab': - $creatable = $this->isCreatable($path); + $creatable = $this->isCreatable(dirname($path)); $updatable = $this->isUpdatable($path); // if neither permissions given, no need to continue if (!$creatable && !$updatable) { - return false; + if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { + $updatable = $this->isUpdatable(dirname($path)); + } + + if (!$updatable) { + return false; + } } $exists = $this->file_exists($path); diff --git a/apps/files_sharing/tests/PermissionsTest.php b/apps/files_sharing/tests/PermissionsTest.php index 2eca474e966a5..5c0086646de3d 100644 --- a/apps/files_sharing/tests/PermissionsTest.php +++ b/apps/files_sharing/tests/PermissionsTest.php @@ -134,14 +134,14 @@ protected function tearDown() { * Test that the permissions of shared directory are returned correctly */ function testGetPermissions() { - $sharedDirPerms = $this->sharedStorage->getPermissions('shareddir'); + $sharedDirPerms = $this->sharedStorage->getPermissions(''); $this->assertEquals(31, $sharedDirPerms); - $sharedDirPerms = $this->sharedStorage->getPermissions('shareddir/textfile.txt'); - $this->assertEquals(31, $sharedDirPerms); - $sharedDirRestrictedPerms = $this->sharedStorageRestrictedShare->getPermissions('shareddirrestricted'); - $this->assertEquals(7, $sharedDirRestrictedPerms); - $sharedDirRestrictedPerms = $this->sharedStorageRestrictedShare->getPermissions('shareddirrestricted/textfile.txt'); - $this->assertEquals(7, $sharedDirRestrictedPerms); + $sharedDirPerms = $this->sharedStorage->getPermissions('textfile.txt'); + $this->assertEquals(27, $sharedDirPerms); + $sharedDirRestrictedPerms = $this->sharedStorageRestrictedShare->getPermissions(''); + $this->assertEquals(15, $sharedDirRestrictedPerms); + $sharedDirRestrictedPerms = $this->sharedStorageRestrictedShare->getPermissions('textfile1.txt'); + $this->assertEquals(3, $sharedDirRestrictedPerms); } /**