take group creation result into consideration

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2019-10-08 18:05:13 +02:00
parent 20ec763337
commit 7b1eedb11e
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
2 changed files with 40 additions and 9 deletions

View File

@ -180,7 +180,7 @@ class Manager extends PublicEmitter implements IGroupManager {
protected function getGroupObject($gid, $displayName = null) { protected function getGroupObject($gid, $displayName = null) {
$backends = []; $backends = [];
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
if ($backend->implementsActions(\OC\Group\Backend::GROUP_DETAILS)) { if ($backend->implementsActions(Backend::GROUP_DETAILS)) {
$groupData = $backend->getGroupDetails($gid); $groupData = $backend->getGroupDetails($gid);
if (is_array($groupData) && !empty($groupData)) { if (is_array($groupData) && !empty($groupData)) {
// take the display name from the first backend that has a non-null one // take the display name from the first backend that has a non-null one
@ -210,7 +210,7 @@ class Manager extends PublicEmitter implements IGroupManager {
/** /**
* @param string $gid * @param string $gid
* @return \OC\Group\Group * @return IGroup|bool|null
*/ */
public function createGroup($gid) { public function createGroup($gid) {
if ($gid === '' || $gid === null) { if ($gid === '' || $gid === null) {
@ -218,13 +218,14 @@ class Manager extends PublicEmitter implements IGroupManager {
} else if ($group = $this->get($gid)) { } else if ($group = $this->get($gid)) {
return $group; return $group;
} else { } else {
$this->emit('\OC\Group', 'preCreate', array($gid)); $this->emit('\OC\Group', 'preCreate', [$gid]);
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
if ($backend->implementsActions(\OC\Group\Backend::CREATE_GROUP)) { if ($backend->implementsActions(Backend::CREATE_GROUP)) {
$backend->createGroup($gid); if($backend->createGroup($gid)) {
$group = $this->getGroupObject($gid); $group = $this->getGroupObject($gid);
$this->emit('\OC\Group', 'postCreate', array($group)); $this->emit('\OC\Group', 'postCreate', [$group]);
return $group; return $group;
}
} }
} }
return null; return null;
@ -300,7 +301,7 @@ class Manager extends PublicEmitter implements IGroupManager {
*/ */
public function isAdmin($userId) { public function isAdmin($userId) {
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
if ($backend->implementsActions(\OC\Group\Backend::IS_ADMIN) && $backend->isAdmin($userId)) { if ($backend->implementsActions(Backend::IS_ADMIN) && $backend->isAdmin($userId)) {
return true; return true;
} }
} }

View File

@ -190,6 +190,7 @@ class ManagerTest extends TestCase {
->method('createGroup') ->method('createGroup')
->will($this->returnCallback(function () use (&$backendGroupCreated) { ->will($this->returnCallback(function () use (&$backendGroupCreated) {
$backendGroupCreated = true; $backendGroupCreated = true;
return true;
})); }));
$manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger); $manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
@ -199,6 +200,35 @@ class ManagerTest extends TestCase {
$this->assertEquals('group1', $group->getGID()); $this->assertEquals('group1', $group->getGID());
} }
public function testCreateFailure() {
/**@var \PHPUnit_Framework_MockObject_MockObject|\OC\Group\Backend $backend */
$backendGroupCreated = false;
$backend = $this->getTestBackend(
GroupInterface::ADD_TO_GROUP |
GroupInterface::REMOVE_FROM_GOUP |
GroupInterface::COUNT_USERS |
GroupInterface::CREATE_GROUP |
GroupInterface::DELETE_GROUP |
GroupInterface::GROUP_DETAILS
);
$backend->expects($this->any())
->method('groupExists')
->with('group1')
->willReturn(false);
$backend->expects($this->once())
->method('createGroup')
->willReturn(false);
$backend->expects($this->once())
->method('getGroupDetails')
->willReturn([]);
$manager = new \OC\Group\Manager($this->userManager, $this->dispatcher, $this->logger);
$manager->addBackend($backend);
$group = $manager->createGroup('group1');
$this->assertEquals(null, $group);
}
public function testCreateExists() { public function testCreateExists() {
/** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Group\Backend $backend */ /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Group\Backend $backend */
$backend = $this->getTestBackend(); $backend = $this->getTestBackend();