Skip to content

Commit

Permalink
Fix provisioning API
Browse files Browse the repository at this point in the history
Fixes #19964
  • Loading branch information
rullzer committed May 24, 2016
1 parent c3c1fa0 commit 95415fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
18 changes: 11 additions & 7 deletions apps/provisioning_api/lib/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,24 @@ public function getUsers() {
$users = $this->userManager->search($search, $limit, $offset);
} else if ($subAdminManager->isSubAdmin($user)) {
$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
foreach ($subAdminOfGroups as $key => $group) {
$subAdminOfGroups[$key] = $group->getGID();
}
$groups = array_map(function(\OCP\IGroup $group) {
return $group->getGID();
}, $subAdminOfGroups);

if($offset === null) {
$offset = 0;
}

$users = [];
foreach ($subAdminOfGroups as $group) {
$users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search));
if ($limit === null) {
$limit = -1;
}

$users = array_slice($users, $offset, $limit);
$result = $this->groupManager->displayNamesInGroups($groups, $search, $limit, $offset);

$users = [];
foreach ($result as $user) {
$users[$user->getUID()] = $user->getDisplayName();
}
} else {
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
}
Expand Down
10 changes: 8 additions & 2 deletions apps/provisioning_api/tests/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,16 @@ public function testGetUsersAsSubAdmin() {
->expects($this->once())
->method('getSubAdmin')
->will($this->returnValue($subAdminManager));

$user1 = $this->getMock('\OCP\IUser');
$user1->method('getUID')->willReturn('AnotherUserInTheFirstGroup');
$user2 = $this->getMock('\OCP\IUser');
$user2->method('getUID')->willReturn('UserInTheSecondGroup');

$this->groupManager
->expects($this->any())
->method('displayNamesInGroup')
->will($this->onConsecutiveCalls(['AnotherUserInTheFirstGroup' => []], ['UserInTheSecondGroup' => []]));
->method('displayNamesInGroups')
->willReturn([$user1, $user2]);

$expected = new \OC_OCS_Result([
'users' => [
Expand Down

0 comments on commit 95415fc

Please sign in to comment.