Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/provisioning_api/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

// Groups
['root' => '/cloud', 'name' => 'Groups#getGroups', 'url' => '/groups', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Groups#getGroupsDetails', 'url' => '/groups/details', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Groups#getGroup', 'url' => '/groups/{groupId}', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Groups#addGroup', 'url' => '/groups', 'verb' => 'POST'],
['root' => '/cloud', 'name' => 'Groups#deleteGroup', 'url' => '/groups/{groupId}', 'verb' => 'DELETE'],
Expand Down
27 changes: 27 additions & 0 deletions apps/provisioning_api/lib/Controller/GroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,33 @@ public function getGroups(string $search = '', $limit = null, $offset = null): D
return new DataResponse(['groups' => $groups]);
}

/**
* returns a list of groups details with ids and displaynames
*
* @NoAdminRequired
*
* @param string $search
* @param int $limit
* @param int $offset
* @return DataResponse
*/
public function getGroupsDetails(string $search = '', $limit = null, $offset = null): DataResponse {
if ($limit !== null) {
$limit = (int)$limit;
}
if ($offset !== null) {
$offset = (int)$offset;
}

$groups = $this->groupManager->search($search, $limit, $offset);
$groups = array_map(function($group) {
/** @var IGroup $group */
return ['id' => $group->getGID(), 'displayname' => $group->getDisplayName()];
}, $groups);

return new DataResponse(['groups' => $groups]);
}

/**
* returns an array of users in the group specified
*
Expand Down
31 changes: 31 additions & 0 deletions apps/provisioning_api/tests/Controller/GroupsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ private function createGroup($gid) {
$group
->method('getGID')
->willReturn($gid);
$group
->method('getDisplayName')
->willReturn($gid.'-name');

return $group;
}

Expand Down Expand Up @@ -165,6 +169,33 @@ public function testGetGroups($search, $limit, $offset) {

$result = $this->api->getGroups($search, $limit, $offset);
$this->assertEquals(['groups' => ['group1', 'group2']], $result->getData());

}

/**
* @dataProvider dataGetGroups
*
* @param string|null $search
* @param int|null $limit
* @param int|null $offset
*/
public function testGetGroupsDetails($search, $limit, $offset) {
$groups = [$this->createGroup('group1'), $this->createGroup('group2')];

$search = $search === null ? '' : $search;

$this->groupManager
->expects($this->once())
->method('search')
->with($search, $limit, $offset)
->willReturn($groups);

$result = $this->api->getGroupsDetails($search, $limit, $offset);
$this->assertEquals(['groups' => [
Array('id' => 'group1', 'displayname' => 'group1-name'),
Array('id' => 'group2', 'displayname' => 'group2-name')
]], $result->getData());

}

public function testGetGroupAsSubadmin() {
Expand Down