diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-10 10:43:32 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-10 10:43:32 +0100 |
commit | 2e94d34dfd99378bfaa39243a265a55a1b8038ba (patch) | |
tree | 4cef15e963fa2d89d9474460f4c928d0d75b3da3 | |
parent | 29820176825c41acef30fa6942922aeb36cfcec3 (diff) | |
download | nextcloud-server-2e94d34dfd99378bfaa39243a265a55a1b8038ba.tar.gz nextcloud-server-2e94d34dfd99378bfaa39243a265a55a1b8038ba.zip |
Fix group principal
-rw-r--r-- | apps/dav/lib/connector/sabre/principal.php | 18 | ||||
-rw-r--r-- | apps/dav/tests/unit/connector/sabre/principal.php | 14 |
2 files changed, 24 insertions, 8 deletions
diff --git a/apps/dav/lib/connector/sabre/principal.php b/apps/dav/lib/connector/sabre/principal.php index 4f26390e3cc..a573124007d 100644 --- a/apps/dav/lib/connector/sabre/principal.php +++ b/apps/dav/lib/connector/sabre/principal.php @@ -49,6 +49,9 @@ class Principal implements BackendInterface { /** @var string */ private $principalPrefix; + /** @var bool */ + private $hasGroups; + /** * @param IUserManager $userManager * @param IGroupManager $groupManager @@ -60,6 +63,7 @@ class Principal implements BackendInterface { $this->userManager = $userManager; $this->groupManager = $groupManager; $this->principalPrefix = trim($principalPrefix, '/'); + $this->hasGroups = ($principalPrefix === 'principals/users/'); } /** @@ -141,13 +145,15 @@ class Principal implements BackendInterface { throw new Exception('Principal not found'); } - $groups = $this->groupManager->getUserGroups($user); - $groups = array_map(function($group) { - /** @var IGroup $group */ - return $this->principalPrefix . '/' . $group->getGID(); - }, $groups); + if ($this->hasGroups) { + $groups = $this->groupManager->getUserGroups($user); + $groups = array_map(function($group) { + /** @var IGroup $group */ + return 'principals/groups/' . $group->getGID(); + }, $groups); - return $groups; + return $groups; + } } return []; } diff --git a/apps/dav/tests/unit/connector/sabre/principal.php b/apps/dav/tests/unit/connector/sabre/principal.php index 07bfd5d263b..1747885240a 100644 --- a/apps/dav/tests/unit/connector/sabre/principal.php +++ b/apps/dav/tests/unit/connector/sabre/principal.php @@ -202,16 +202,26 @@ class Principal extends TestCase { public function testGetGroupMembership() { $fooUser = $this->getMockBuilder('\OC\User\User') ->disableOriginalConstructor()->getMock(); + $group = $this->getMockBuilder('\OCP\IGroup') + ->disableOriginalConstructor()->getMock(); + $group->expects($this->once()) + ->method('getGID') + ->willReturn('group1'); $this->userManager ->expects($this->once()) ->method('get') ->with('foo') ->willReturn($fooUser); $this->groupManager + ->expects($this->once()) ->method('getUserGroups') - ->willReturn([]); + ->willReturn([ + $group + ]); - $expectedResponse = []; + $expectedResponse = [ + 'principals/groups/group1' + ]; $response = $this->connector->getGroupMembership('principals/users/foo'); $this->assertSame($expectedResponse, $response); } |