Skip to content

Commit 6c07065

Browse files
committed
returns membership
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 541cd43 commit 6c07065

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

appinfo/routes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
],
7474
'ocs' => [
7575
['name' => 'OcsApi#circles', 'url' => '/circles/', 'verb' => 'GET'],
76-
['name' => 'OcsApi#members', 'url' => '/circles/{circleId}/members/', 'verb' => 'GET']
76+
['name' => 'OcsApi#members', 'url' => '/circles/{circleId}/members/', 'verb' => 'GET'],
77+
['name' => 'OcsApi#usersMembership', 'url' => '/users/{userId}/circles', 'verb' => 'GET']
7778
]
7879
];

lib/Controller/OcsApiController.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,27 @@ public function members(string $circleId): DataResponse {
128128
}
129129
}
130130

131+
132+
/**
133+
* @NoAdminRequired
134+
*
135+
* @param string $userId
136+
*
137+
* @return DataResponse
138+
*/
139+
public function usersMembership(string $userId): DataResponse {
140+
try {
141+
$circles = array_map(
142+
function(Circle $circle): string {
143+
return $circle->getUniqueId();
144+
}, $this->membersService->getCirclesAvailableToUserId($userId)
145+
);
146+
147+
return new DataResponse(json_decode(json_encode(['circles' => $circles]), true));
148+
} catch (Exception $e) {
149+
return new DataResponse(['message' => $$e->getMessage()], Http::STATUS_BAD_REQUEST);
150+
}
151+
}
152+
131153
}
132154

lib/Service/MembersService.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,5 +792,17 @@ private function filterDuplicate(array $curr, array $new): array {
792792
}
793793

794794

795+
/**
796+
* @param string $userId
797+
*
798+
* @return Circle[]
799+
* @throws ConfigNoCircleAvailableException
800+
* @throws GSStatusException
801+
*/
802+
public function getCirclesAvailableToUserId(string $userId): array {
803+
return $this->circlesRequest->getCircles($userId, 0, '', 1, true);
804+
}
805+
806+
795807
}
796808

0 commit comments

Comments
 (0)