summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-03-18 16:36:27 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-03-22 17:13:34 +0100
commit52826d0e24b354a38220a904fd21bb1860c70870 (patch)
tree4ad114e54d249d200d987bbfbc2c2c05d7325066
parent195efc12eb8c4be01d3160bcb1b8cd3d78a0767b (diff)
downloadnextcloud-server-52826d0e24b354a38220a904fd21bb1860c70870.tar.gz
nextcloud-server-52826d0e24b354a38220a904fd21bb1860c70870.zip
Block group sharing in API and in share manager
* Fix tests
-rw-r--r--apps/files_sharing/api/share20ocs.php4
-rw-r--r--apps/files_sharing/tests/api/share20ocstest.php50
-rw-r--r--lib/private/Share20/Manager.php5
-rw-r--r--tests/lib/share20/managertest.php30
4 files changed, 88 insertions, 1 deletions
diff --git a/apps/files_sharing/api/share20ocs.php b/apps/files_sharing/api/share20ocs.php
index 5a2af48d6f5..915022f7d96 100644
--- a/apps/files_sharing/api/share20ocs.php
+++ b/apps/files_sharing/api/share20ocs.php
@@ -264,6 +264,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 a2c70d7673c..a354b01299d 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 bd4b6d7cfc0..4737de002cb 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 4f23dd0e6d0..2f45de86b98 100644
--- a/tests/lib/share20/managertest.php
+++ b/tests/lib/share20/managertest.php
@@ -1149,6 +1149,22 @@ class ManagerTest extends \Test\TestCase {
/**
* @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
*/
public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() {
@@ -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]);
}