Block group sharing in API and in share manager
* Fix tests
This commit is contained in:
parent
195efc12eb
commit
52826d0e24
|
@ -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');
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue