Skip to content

Commit 5f38cfb

Browse files
committed
Return groups displayname in provisioning api
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 3cac791 commit 5f38cfb

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

apps/provisioning_api/appinfo/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
// Groups
3636
['root' => '/cloud', 'name' => 'Groups#getGroups', 'url' => '/groups', 'verb' => 'GET'],
37+
['root' => '/cloud', 'name' => 'Groups#getGroupsDetails', 'url' => '/groups/details', 'verb' => 'GET'],
3738
['root' => '/cloud', 'name' => 'Groups#getGroup', 'url' => '/groups/{groupId}', 'verb' => 'GET'],
3839
['root' => '/cloud', 'name' => 'Groups#addGroup', 'url' => '/groups', 'verb' => 'POST'],
3940
['root' => '/cloud', 'name' => 'Groups#deleteGroup', 'url' => '/groups/{groupId}', 'verb' => 'DELETE'],

apps/provisioning_api/lib/Controller/GroupsController.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,33 @@ public function getGroups(string $search = '', $limit = null, $offset = null): D
9696
return new DataResponse(['groups' => $groups]);
9797
}
9898

99+
/**
100+
* returns a list of groups details with ids and displaynames
101+
*
102+
* @NoAdminRequired
103+
*
104+
* @param string $search
105+
* @param int $limit
106+
* @param int $offset
107+
* @return DataResponse
108+
*/
109+
public function getGroupsDetails(string $search = '', $limit = null, $offset = null): DataResponse {
110+
if ($limit !== null) {
111+
$limit = (int)$limit;
112+
}
113+
if ($offset !== null) {
114+
$offset = (int)$offset;
115+
}
116+
117+
$groups = $this->groupManager->search($search, $limit, $offset);
118+
$groups = array_map(function($group) {
119+
/** @var IGroup $group */
120+
return ['id' => $group->getGID(), 'displayname' => $group->getDisplayName()];
121+
}, $groups);
122+
123+
return new DataResponse(['groups' => $groups]);
124+
}
125+
99126
/**
100127
* returns an array of users in the group specified
101128
*

apps/provisioning_api/tests/Controller/GroupsControllerTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ private function createGroup($gid) {
8585
$group
8686
->method('getGID')
8787
->willReturn($gid);
88+
$group
89+
->method('getDisplayName')
90+
->willReturn($gid.'-name');
91+
8892
return $group;
8993
}
9094

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

166170
$result = $this->api->getGroups($search, $limit, $offset);
167171
$this->assertEquals(['groups' => ['group1', 'group2']], $result->getData());
172+
173+
}
174+
175+
/**
176+
* @dataProvider dataGetGroups
177+
*
178+
* @param string|null $search
179+
* @param int|null $limit
180+
* @param int|null $offset
181+
*/
182+
public function testGetGroupsDetails($search, $limit, $offset) {
183+
$groups = [$this->createGroup('group1'), $this->createGroup('group2')];
184+
185+
$search = $search === null ? '' : $search;
186+
187+
$this->groupManager
188+
->expects($this->once())
189+
->method('search')
190+
->with($search, $limit, $offset)
191+
->willReturn($groups);
192+
193+
$result = $this->api->getGroupsDetails($search, $limit, $offset);
194+
$this->assertEquals(['groups' => [
195+
Array('id' => 'group1', 'displayname' => 'group1-name'),
196+
Array('id' => 'group2', 'displayname' => 'group2-name')
197+
]], $result->getData());
198+
168199
}
169200

170201
public function testGetGroupAsSubadmin() {

0 commit comments

Comments
 (0)