Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ protected function linkCreateChecks(IShare $share) {
}

// 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');
}
Expand Down Expand Up @@ -1544,7 +1544,7 @@ public function getShareByToken($token) {
* 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));
}

Expand Down
29 changes: 28 additions & 1 deletion tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1915,13 +1915,31 @@ public function testLinkCreateChecksNoLinkSharesAllowed() {
}


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')
Expand All @@ -1937,6 +1955,9 @@ public function testLinkCreateChecksPublicUpload() {
$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')
Expand All @@ -1953,6 +1974,9 @@ public function testLinkCreateChecksReadOnly() {
$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')
Expand Down Expand Up @@ -2947,6 +2971,9 @@ public function testGetShareByTokenPublicUploadDisabled() {
$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))
Expand Down