Skip to content

Commit 3306cfb

Browse files
committed
feat: adds support for group get all roles endpoint
1 parent de1ed16 commit 3306cfb

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/keycloak/keycloak_admin.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3993,6 +3993,25 @@ def get_group_client_roles(self, group_id: str, client_id: str) -> list:
39933993
)
39943994
return raise_error_from_response(data_raw, KeycloakGetError)
39953995

3996+
def get_all_roles_of_group(self, group_id: str, brief_representation: bool = True) -> dict:
3997+
"""
3998+
Get all roles of a group.
3999+
4000+
:param group_id: id of the group
4001+
:type group_id: str
4002+
:param brief_representation: whether to omit role attributes in the response
4003+
:type brief_representation: bool
4004+
:return: Keycloak server response
4005+
:rtype: list
4006+
"""
4007+
params_path = {"realm-name": self.connection.realm_name, "id": group_id}
4008+
params = {"briefRepresentation": brief_representation}
4009+
data_raw = self.connection.raw_get(
4010+
urls_patterns.URL_ADMIN_GROUP_ALL_ROLES.format(**params_path),
4011+
**params
4012+
)
4013+
return raise_error_from_response(data_raw, KeycloakGetError)
4014+
39964015
def delete_group_client_roles(self, group_id: str, client_id: str, roles: str | list) -> bytes:
39974016
"""
39984017
Delete client roles of a group.
@@ -9278,6 +9297,25 @@ async def a_get_group_client_roles(self, group_id: str, client_id: str) -> list:
92789297
)
92799298
return raise_error_from_response(data_raw, KeycloakGetError)
92809299

9300+
async def a_get_all_roles_of_group(self, group_id: str, brief_representation: bool = True) -> dict:
9301+
"""
9302+
Get all roles of a group asynchronously.
9303+
9304+
:param group_id: id of the group
9305+
:type group_id: str
9306+
:param brief_representation: whether to omit role attributes in the response
9307+
:type brief_representation: bool
9308+
:return: Keycloak server response
9309+
:rtype: list
9310+
"""
9311+
params_path = {"realm-name": self.connection.realm_name, "id": group_id}
9312+
params = {"briefRepresentation": brief_representation}
9313+
data_raw = await self.connection.a_raw_get(
9314+
urls_patterns.URL_ADMIN_GROUP_ALL_ROLES.format(**params_path),
9315+
**params
9316+
)
9317+
return raise_error_from_response(data_raw, KeycloakGetError)
9318+
92819319
async def a_delete_group_client_roles(
92829320
self,
92839321
group_id: str,

src/keycloak/urls_patterns.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
URL_ADMIN_USER_REALM_ROLES_COMPOSITE = (
6363
"admin/realms/{realm-name}/users/{id}/role-mappings/realm/composite"
6464
)
65+
URL_ADMIN_GROUP_ALL_ROLES = (
66+
"admin/realms/{realm-name}/groups/{id}/role-mappings"
67+
)
6568
URL_ADMIN_GROUPS_REALM_ROLES = "admin/realms/{realm-name}/groups/{id}/role-mappings/realm"
6669
URL_ADMIN_GROUPS_CLIENT_ROLES = (
6770
"admin/realms/{realm-name}/groups/{id}/role-mappings/clients/{client-id}"

0 commit comments

Comments
 (0)