Skip to content

Commit a87e3d8

Browse files
authored
Merge pull request #146 from punktDeForks/feature/group-by-path-endpoint
feat: group by path endpoint and group members endpoint
2 parents e7244fb + 5ccb119 commit a87e3d8

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,14 @@ $myCustomRepresentation = $myCustomResource->myCustomEndpoint();
127127
| ------------------------------------------------- | ----------------------------------------------------- | --------------------------------------------- |
128128
| `GET /admin/realms/{realm}/groups` | [GroupCollection](src/Collection/GroupCollection.php) | [Groups::all()](src/Resource/Groups.php) |
129129
| `GET /admin/realms/{realm}/groups/{id}/children` | [GroupCollection](src/Collection/GroupCollection.php) | [Groups::children()](src/Resource/Groups.php) |
130+
| `GET /admin/realms/{realm}/groups/{id}/members` | [UserCollection](src/Collection/UserCollection.php) | [Groups::members()](src/Resource/Groups.php) |
130131
| `GET /admin/realms/{realm}/groups/{id}` | [Group](src/Representation/Group.php) | [Groups::get()](src/Resource/Groups.php) |
131132
| `PUT /admin/realms/{realm}/groups/{id}` | `n/a` | [Groups::update()](src/Resource/Groups.php) |
132133
| `POST /admin/realms/{realm}/groups` | `n/a` | [Groups::create()](src/Resource/Groups.php) |
133134
| `POST /admin/realms/{realm}/groups/{id}/children` | `n/a` | [Groups::create()](src/Resource/Groups.php) |
134135
| `DELETE /admin/realms/{realm}/groups` | `n/a` | [Groups::delete()](src/Resource/Groups.php) |
136+
| `GET /admin/realms/{realm}/group-by-path/{path}` | [Group](src/Representation/Group.php) | [Groups::byPath()](src/Resource/Groups.php) |
137+
135138

136139
### [Organizations](https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_organizations)
137140

src/Resource/Groups.php

+30
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Fschmtt\Keycloak\Resource;
66

77
use Fschmtt\Keycloak\Collection\GroupCollection;
8+
use Fschmtt\Keycloak\Collection\UserCollection;
89
use Fschmtt\Keycloak\Http\Command;
910
use Fschmtt\Keycloak\Http\Criteria;
1011
use Fschmtt\Keycloak\Http\Method;
@@ -27,6 +28,20 @@ public function all(string $realm, ?Criteria $criteria = null): GroupCollection
2728
);
2829
}
2930

31+
public function byPath(string $realm, string $path = ''): Group
32+
{
33+
return $this->queryExecutor->executeQuery(
34+
new Query(
35+
'/admin/realms/{realm}/group-by-path/{path}',
36+
Group::class,
37+
[
38+
'realm' => $realm,
39+
'path' => $path,
40+
]
41+
)
42+
);
43+
}
44+
3045
public function children(string $realm, string $groupId, ?Criteria $criteria = null): GroupCollection
3146
{
3247
return $this->queryExecutor->executeQuery(
@@ -42,6 +57,21 @@ public function children(string $realm, string $groupId, ?Criteria $criteria = n
4257
);
4358
}
4459

60+
public function members(string $realm, string $groupId, ?Criteria $criteria = null): UserCollection
61+
{
62+
return $this->queryExecutor->executeQuery(
63+
new Query(
64+
'/admin/realms/{realm}/groups/{groupId}/members',
65+
UserCollection::class,
66+
[
67+
'realm' => $realm,
68+
'groupId' => $groupId,
69+
],
70+
$criteria
71+
)
72+
);
73+
}
74+
4575
public function get(string $realm, string $groupId): Group
4676
{
4777
return $this->queryExecutor->executeQuery(

tests/Integration/Resource/GroupsTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,10 @@ public function testCreateChildGroup(): void
7777
$childGroup = $childGroups->first();
7878
static::assertInstanceOf(Group::class, $childGroup);
7979
static::assertSame($childGroupName, $childGroup->getName());
80+
81+
// get child group by path
82+
$pathGroup = $groups->byPath('master', $importedGroupName.'/'.$childGroupName);
83+
static::assertInstanceOf(Group::class, $pathGroup);
84+
static::assertSame($childGroup->getId(), $pathGroup->getId());
8085
}
8186
}

tests/Integration/Resource/UsersTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ public function testJoinRetrieveLeaveGroupUser(): void
9292
static::assertInstanceOf(Group::class, $userFirstGroup);
9393
static::assertSame($group->getId(), $userFirstGroup->getId());
9494

95+
// get group members
96+
$groupMembers = $groups->members('master', $group->getId());
97+
static::assertSame(1, $groupMembers->count());
98+
static::assertInstanceOf(User::class, $groupMembers->first());
99+
static::assertSame($user->getId(), $groupMembers->first()->getId());
100+
95101
// leave group
96102
$users->leaveGroup('master', $user->getId(), $group->getId());
97103

0 commit comments

Comments
 (0)