diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php index a6baa353e8..73cb8bc23e 100644 --- a/apps/files_sharing/api/share20ocs.php +++ b/apps/files_sharing/api/share20ocs.php @@ -292,6 +292,10 @@ class Share20OCS { $share->setSharedWith($shareWith); $share->setPermissions($permissions); } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { + if (!$this->shareManager->allowGroupSharing()) { + return new \OC_OCS_Result(null, 404, 'group sharing is disabled by the administrator'); + } + // Valid group is required to share if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { return new \OC_OCS_Result(null, 404, 'please specify a valid group'); diff --git a/apps/files_sharing/tests/api/share20ocstest.php b/apps/files_sharing/tests/api/share20ocstest.php index a2c70d7673..a354b01299 100644 --- a/apps/files_sharing/tests/api/share20ocstest.php +++ b/apps/files_sharing/tests/api/share20ocstest.php @@ -759,9 +759,12 @@ class Share20OCSTest extends \Test\TestCase { ->with('valid-path') ->willReturn($path); - $group = $this->getMock('\OCP\IGroup'); $this->groupManager->method('groupExists')->with('validGroup')->willReturn(true); + $this->shareManager->expects($this->once()) + ->method('allowGroupSharing') + ->willReturn(true); + $share->method('setPath')->with($path); $share->method('setPermissions')->with(\OCP\Constants::PERMISSION_ALL); $share->method('setShareType')->with(\OCP\Share::SHARE_TYPE_GROUP); @@ -775,6 +778,51 @@ class Share20OCSTest extends \Test\TestCase { $this->assertEquals($expected->getData(), $result->getData()); } + public function testCreateShareGroupNotAllowed() { + $share = $this->getMock('\OCP\Share\IShare'); + $this->shareManager->method('newShare')->willReturn($share); + + $this->request + ->method('getParam') + ->will($this->returnValueMap([ + ['path', null, 'valid-path'], + ['permissions', null, \OCP\Constants::PERMISSION_ALL], + ['shareType', '-1', \OCP\Share::SHARE_TYPE_GROUP], + ['shareWith', null, 'validGroup'], + ])); + + $userFolder = $this->getMock('\OCP\Files\Folder'); + $this->rootFolder->expects($this->once()) + ->method('getUserFolder') + ->with('currentUser') + ->willReturn($userFolder); + + $path = $this->getMock('\OCP\Files\Folder'); + $storage = $this->getMock('OCP\Files\Storage'); + $storage->method('instanceOfStorage') + ->with('OCA\Files_Sharing\External\Storage') + ->willReturn(false); + $path->method('getStorage')->willReturn($storage); + $userFolder->expects($this->once()) + ->method('get') + ->with('valid-path') + ->willReturn($path); + + $this->groupManager->method('groupExists')->with('validGroup')->willReturn(true); + + $this->shareManager->expects($this->once()) + ->method('allowGroupSharing') + ->willReturn(false); + + $share->method('setPath')->with($path); + + $expected = new \OC_OCS_Result(null, 404, 'group sharing is disabled by the administrator'); + $result = $this->ocs->createShare(); + + $this->assertEquals($expected->getMeta(), $result->getMeta()); + $this->assertEquals($expected->getData(), $result->getData()); + } + public function testCreateShareLinkNoLinksAllowed() { $this->request ->method('getParam') diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index 4733167cb1..5e40acefbe 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -361,6 +361,11 @@ class Manager implements IManager { * @throws \Exception */ protected function groupCreateChecks(\OCP\Share\IShare $share) { + // Verify group shares are allowed + if (!$this->allowGroupSharing()) { + throw new \Exception('Group sharing is now allowed'); + } + // Verify if the user can share with this group if ($this->shareWithGroupMembersOnly()) { $sharedBy = $this->userManager->get($share->getSharedBy()); diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php index 4f23dd0e6d..2f45de86b9 100644 --- a/tests/lib/share20/managertest.php +++ b/tests/lib/share20/managertest.php @@ -1147,6 +1147,22 @@ class ManagerTest extends \Test\TestCase { $this->invokePrivate($this->manager, 'userCreateChecks', [$share]); } + /** + * @expectedException Exception + * @expectedExceptionMessage Group sharing is now allowed + */ + public function testGroupCreateChecksShareWithGroupMembersGroupSharingNotAllowed() { + $share = $this->manager->newShare(); + + $this->config + ->method('getAppValue') + ->will($this->returnValueMap([ + ['core', 'shareapi_allow_group_sharing', 'yes', 'no'], + ])); + + $this->invokePrivate($this->manager, 'groupCreateChecks', [$share]); + } + /** * @expectedException Exception * @expectedExceptionMessage Only sharing within your own groups is allowed @@ -1167,6 +1183,7 @@ class ManagerTest extends \Test\TestCase { ->method('getAppValue') ->will($this->returnValueMap([ ['core', 'shareapi_only_share_with_group_members', 'no', 'yes'], + ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'], ])); $this->invokePrivate($this->manager, 'groupCreateChecks', [$share]); @@ -1195,6 +1212,7 @@ class ManagerTest extends \Test\TestCase { ->method('getAppValue') ->will($this->returnValueMap([ ['core', 'shareapi_only_share_with_group_members', 'no', 'yes'], + ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'], ])); $this->invokePrivate($this->manager, 'groupCreateChecks', [$share]); @@ -1222,6 +1240,12 @@ class ManagerTest extends \Test\TestCase { ->with($path) ->willReturn([$share2]); + $this->config + ->method('getAppValue') + ->will($this->returnValueMap([ + ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'], + ])); + $this->invokePrivate($this->manager, 'groupCreateChecks', [$share]); } @@ -1240,6 +1264,12 @@ class ManagerTest extends \Test\TestCase { ->with($path) ->willReturn([$share2]); + $this->config + ->method('getAppValue') + ->will($this->returnValueMap([ + ['core', 'shareapi_allow_group_sharing', 'yes', 'yes'], + ])); + $this->invokePrivate($this->manager, 'groupCreateChecks', [$share]); }