From 82791b7b064a00cc1dc8364ed727900e62167af8 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 15 Aug 2017 10:19:15 +0200 Subject: [PATCH 1/2] Public upload share permission handling If you set the permissions on a public share the SHARE permission makes no sense. So instead of throwing a warning. Just filter out the share permission. Signed-off-by: Roeland Jago Douma --- apps/files_sharing/lib/Controller/ShareAPIController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index c57a738457..8f65c1c559 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -700,6 +700,7 @@ class ShareAPIController extends OCSController { if ($permissions !== null) { $newPermissions = (int)$permissions; + $newPermissions = $newPermissions & ~\OCP\Constants::PERMISSION_SHARE; } if ($newPermissions !== null && From 6e7865d05b04bf232d49cfdc28d62c29f5d926e0 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 16 Aug 2017 21:21:50 +0200 Subject: [PATCH 2/2] Update to new test case Signed-off-by: Roeland Jago Douma --- .../Controller/ShareAPIControllerTest.php | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index f5df9b62b1..fc6e457284 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -1541,11 +1541,7 @@ class ShareAPIControllerTest extends TestCase { $this->assertEquals($expected->getData(), $result->getData()); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSBadRequestException - * @expectedExceptionMessage Can't change permissions for public share links - */ - public function testUpdateLinkShareInvalidPermissions() { + public function testUpdateLinkSharePermissionsShare() { $ocs = $this->mockFormatShare(); $date = new \DateTime('2000-01-01'); @@ -1558,13 +1554,27 @@ class ShareAPIControllerTest extends TestCase { ->setShareType(\OCP\Share::SHARE_TYPE_LINK) ->setPassword('password') ->setExpirationDate($date) - ->setPermissions(\OCP\Constants::PERMISSION_ALL) + ->setPermissions(\OCP\Constants::PERMISSION_READ) ->setNode($folder); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); - $ocs->updateShare(42, 31); + $this->shareManager->expects($this->once())->method('updateShare')->with( + $this->callback(function (\OCP\Share\IShare $share) use ($date) { + return $share->getPermissions() === (\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE) && + $share->getPassword() === 'password' && + $share->getExpirationDate() === $date; + }) + )->will($this->returnArgument(0)); + + $this->shareManager->method('getSharedWith')->willReturn([]); + + $expected = new DataResponse(null); + $result = $ocs->updateShare(42, 31, null, null, null); + + $this->assertInstanceOf(get_class($expected), $result); + $this->assertEquals($expected->getData(), $result->getData()); } public function testUpdateOtherPermissions() {