Fix group principal

This commit is contained in:
Thomas Müller 2016-02-10 10:43:32 +01:00
parent 2982017682
commit 2e94d34dfd
2 changed files with 24 additions and 8 deletions

View file

@ -49,6 +49,9 @@ class Principal implements BackendInterface {
/** @var string */ /** @var string */
private $principalPrefix; private $principalPrefix;
/** @var bool */
private $hasGroups;
/** /**
* @param IUserManager $userManager * @param IUserManager $userManager
* @param IGroupManager $groupManager * @param IGroupManager $groupManager
@ -60,6 +63,7 @@ class Principal implements BackendInterface {
$this->userManager = $userManager; $this->userManager = $userManager;
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->principalPrefix = trim($principalPrefix, '/'); $this->principalPrefix = trim($principalPrefix, '/');
$this->hasGroups = ($principalPrefix === 'principals/users/');
} }
/** /**
@ -141,14 +145,16 @@ class Principal implements BackendInterface {
throw new Exception('Principal not found'); throw new Exception('Principal not found');
} }
if ($this->hasGroups) {
$groups = $this->groupManager->getUserGroups($user); $groups = $this->groupManager->getUserGroups($user);
$groups = array_map(function($group) { $groups = array_map(function($group) {
/** @var IGroup $group */ /** @var IGroup $group */
return $this->principalPrefix . '/' . $group->getGID(); return 'principals/groups/' . $group->getGID();
}, $groups); }, $groups);
return $groups; return $groups;
} }
}
return []; return [];
} }

View file

@ -202,16 +202,26 @@ class Principal extends TestCase {
public function testGetGroupMembership() { public function testGetGroupMembership() {
$fooUser = $this->getMockBuilder('\OC\User\User') $fooUser = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$group = $this->getMockBuilder('\OCP\IGroup')
->disableOriginalConstructor()->getMock();
$group->expects($this->once())
->method('getGID')
->willReturn('group1');
$this->userManager $this->userManager
->expects($this->once()) ->expects($this->once())
->method('get') ->method('get')
->with('foo') ->with('foo')
->willReturn($fooUser); ->willReturn($fooUser);
$this->groupManager $this->groupManager
->expects($this->once())
->method('getUserGroups') ->method('getUserGroups')
->willReturn([]); ->willReturn([
$group
]);
$expectedResponse = []; $expectedResponse = [
'principals/groups/group1'
];
$response = $this->connector->getGroupMembership('principals/users/foo'); $response = $this->connector->getGroupMembership('principals/users/foo');
$this->assertSame($expectedResponse, $response); $this->assertSame($expectedResponse, $response);
} }