diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-08-02 17:49:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-02 17:49:27 +0300 |
commit | 9475cc02b218f7cab402ec0b2b370ed6c68650c1 (patch) | |
tree | bfc7a1b7c128df697e3fe186586d2a373023e3be | |
parent | 5cce1dfc6083b7f95a905dd5afd9c74e2984ba7c (diff) | |
parent | acc68e9f937e93a483ddfbb3fb5555dacf7a9ace (diff) |
Merge pull request #32958 from nextcloud/fix/noid/permission-update-allow-public-uploads
-rw-r--r-- | lib/private/Share20/Manager.php | 4 | ||||
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 29 |
2 files changed, 30 insertions, 3 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index a46126b7ac4..2ef61cf3404 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -650,7 +650,7 @@ class Manager implements IManager { } // Check if public upload is allowed - if (!$this->shareApiLinkAllowPublicUpload() && + if ($share->getNodeType() === 'folder' && !$this->shareApiLinkAllowPublicUpload() && ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { throw new \InvalidArgumentException('Public upload is not allowed'); } @@ -1544,7 +1544,7 @@ class Manager implements IManager { * Reduce the permissions for link or email shares if public upload is not enabled */ if (($share->getShareType() === IShare::TYPE_LINK || $share->getShareType() === IShare::TYPE_EMAIL) - && !$this->shareApiLinkAllowPublicUpload()) { + && $share->getNodeType() === 'folder' && !$this->shareApiLinkAllowPublicUpload()) { $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); } diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index ab296172a3c..4e613d1cf5c 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -1915,13 +1915,31 @@ class ManagerTest extends \Test\TestCase { } - public function testLinkCreateChecksNoPublicUpload() { + public function testFileLinkCreateChecksNoPublicUpload() { + $share = $this->manager->newShare(); + + $share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); + $share->setNodeType('file'); + + $this->config + ->method('getAppValue') + ->willReturnMap([ + ['core', 'shareapi_allow_links', 'yes', 'yes'], + ['core', 'shareapi_allow_public_upload', 'yes', 'no'] + ]); + + self::invokePrivate($this->manager, 'linkCreateChecks', [$share]); + $this->addToAssertionCount(1); + } + + public function testFolderLinkCreateChecksNoPublicUpload() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Public upload is not allowed'); $share = $this->manager->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); + $share->setNodeType('folder'); $this->config ->method('getAppValue') @@ -1937,6 +1955,9 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); + $share->setSharedWith('sharedWith'); + $folder = $this->createMock(\OC\Files\Node\Folder::class); + $share->setNode($folder); $this->config ->method('getAppValue') @@ -1953,6 +1974,9 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_READ); + $share->setSharedWith('sharedWith'); + $folder = $this->createMock(\OC\Files\Node\Folder::class); + $share->setNode($folder); $this->config ->method('getAppValue') @@ -2947,6 +2971,9 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share->setShareType(IShare::TYPE_LINK) ->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE); + $share->setSharedWith('sharedWith'); + $folder = $this->createMock(\OC\Files\Node\Folder::class); + $share->setNode($folder); $this->config ->expects($this->at(1)) |