Skip to content

Commit 01662d4

Browse files
authored
Merge pull request #11960 from Vitaliy-1/i11959_usergroups_stage
#11959 Filter user groups by stage IDs and role IDs
2 parents f12e19f + 6f2c53c commit 01662d4

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

api/v1/contexts/PKPContextController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,9 @@ public function delete(Request $illuminateRequest): JsonResponse
710710
return response()->json($contextProps, Response::HTTP_OK);
711711
}
712712

713+
/**
714+
* Get a list of available user groups
715+
*/
713716
public function getUserGroups(Request $illuminateRequest): JsonResponse
714717
{
715718
$contextId = (int) $illuminateRequest->route('contextId');
@@ -723,7 +726,20 @@ public function getUserGroups(Request $illuminateRequest): JsonResponse
723726
], Response::HTTP_NOT_FOUND);
724727
}
725728

726-
$userGroups = UserGroup::withContextIds([$context->getId()])->get();
729+
$collector = UserGroup::withContextIds([$context->getId()]);
730+
731+
foreach ($illuminateRequest->query() as $param => $val) {
732+
switch ($param) {
733+
case 'stageIds':
734+
$collector->withStageIds(array_map(intval(...), paramToArray($val)));
735+
break;
736+
case 'roleIds':
737+
$collector->withRoleIds(array_map(intval(...), paramToArray($val)));
738+
break;
739+
}
740+
}
741+
742+
$userGroups = $collector->get();
727743

728744
return response()->json(
729745
[

api/v1/contexts/resources/UserGroupResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function toArray($request)
2323
{
2424
return [
2525
'id' => $this->id,
26-
'roleId' => $this->contents,
26+
'roleId' => $this->roleId,
2727
'isDefault' => (bool) $this->is_default,
2828
'showTitle' => (bool) $this->show_title,
2929
'name' => $this->getLocalizedData('name'),

0 commit comments

Comments
 (0)