Skip to content

Commit ea05d97

Browse files
committed
fix: pass query params in get groups
1 parent 216d7fe commit ea05d97

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

src/keycloak/keycloak_admin.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,27 +1701,27 @@ def update_user(self, user_id: str, payload: dict) -> dict:
17011701

17021702
return res
17031703

1704-
def disable_user(self, user_id: str) -> dict | bytes:
1704+
def disable_user(self, user_id: str) -> dict:
17051705
"""
17061706
Disable the user from the realm. Disabled users can not log in.
17071707

17081708
:param user_id: User id
17091709
:type user_id: str
17101710

17111711
:return: Http response
1712-
:rtype: bytes
1712+
:rtype: dict
17131713
"""
17141714
return self.update_user(user_id=user_id, payload={"enabled": False})
17151715

1716-
def enable_user(self, user_id: str) -> dict | bytes:
1716+
def enable_user(self, user_id: str) -> dict:
17171717
"""
17181718
Enable the user from the realm.
17191719

17201720
:param user_id: User id
17211721
:type user_id: str
17221722

17231723
:return: Http response
1724-
:rtype: bytes
1724+
:rtype: dict
17251725
"""
17261726
return self.update_user(user_id=user_id, payload={"enabled": True})
17271727

@@ -2228,11 +2228,14 @@ def get_groups(self, query: dict | None = None, full_hierarchy: bool = False) ->
22282228
group["subGroups"] = self.get_group_children(
22292229
group_id=group.get("id"),
22302230
full_hierarchy=full_hierarchy,
2231+
query=query,
22312232
)
22322233

22332234
return groups
22342235

2235-
def get_group(self, group_id: str, full_hierarchy: bool = False) -> dict:
2236+
def get_group(
2237+
self, group_id: str, full_hierarchy: bool = False, query: dict | None = None
2238+
) -> dict:
22362239
"""
22372240
Get group by id.
22382241

@@ -2246,9 +2249,12 @@ def get_group(self, group_id: str, full_hierarchy: bool = False) -> dict:
22462249
:param full_hierarchy: If True, return all of the nested children groups, otherwise only
22472250
the first level children are returned
22482251
:type full_hierarchy: bool
2252+
:param query: Additional query parameters passed into the subgroup fetch requests
2253+
:type query: dict | None
22492254
:return: Keycloak server response (GroupRepresentation)
22502255
:rtype: dict
22512256
"""
2257+
query = query or {}
22522258
params_path = {"realm-name": self.connection.realm_name, "id": group_id}
22532259
response = self.connection.raw_get(urls_patterns.URL_ADMIN_GROUP.format(**params_path))
22542260

@@ -2259,8 +2265,7 @@ def get_group(self, group_id: str, full_hierarchy: bool = False) -> dict:
22592265
group = response.json()
22602266
if group.get("subGroupCount"):
22612267
group["subGroups"] = self.get_group_children(
2262-
group.get("id"),
2263-
full_hierarchy=full_hierarchy,
2268+
group.get("id"), full_hierarchy=full_hierarchy, query=query
22642269
)
22652270

22662271
return group
@@ -2334,6 +2339,7 @@ def get_group_children(
23342339
group["subGroups"] = self.get_group_children(
23352340
group_id=group.get("id"),
23362341
full_hierarchy=full_hierarchy,
2342+
query=query,
23372343
)
23382344

23392345
return res
@@ -5397,7 +5403,7 @@ def get_authentication_flow_for_id(self, flow_id: str) -> dict:
53975403

53985404
return res
53995405

5400-
def create_authentication_flow(self, payload: dict, skip_exists: bool = False) -> bytes | dict:
5406+
def create_authentication_flow(self, payload: dict, skip_exists: bool = False) -> bytes:
54015407
"""
54025408
Create a new authentication flow.
54035409

@@ -5409,7 +5415,7 @@ def create_authentication_flow(self, payload: dict, skip_exists: bool = False) -
54095415
:param skip_exists: Do not raise an error if authentication flow already exists
54105416
:type skip_exists: bool
54115417
:return: Keycloak server response (RoleRepresentation)
5412-
:rtype: bytes | dict
5418+
:rtype: bytes
54135419
"""
54145420
params_path = {"realm-name": self.connection.realm_name}
54155421
data_raw = self.connection.raw_post(
@@ -9087,13 +9093,14 @@ async def a_get_groups(self, query: dict | None = None, full_hierarchy: bool = F
90879093
for group in groups:
90889094
if group.get("subGroupCount"):
90899095
group["subGroups"] = await self.a_get_group_children(
9090-
group_id=group.get("id"),
9091-
full_hierarchy=full_hierarchy,
9096+
group_id=group.get("id"), full_hierarchy=full_hierarchy, query=query
90929097
)
90939098

90949099
return groups
90959100

9096-
async def a_get_group(self, group_id: str, full_hierarchy: bool = False) -> dict:
9101+
async def a_get_group(
9102+
self, group_id: str, full_hierarchy: bool = False, query: dict | None = None
9103+
) -> dict:
90979104
"""
90989105
Get group by id asynchronously.
90999106

@@ -9107,9 +9114,12 @@ async def a_get_group(self, group_id: str, full_hierarchy: bool = False) -> dict
91079114
:param full_hierarchy: If True, return all of the nested children groups, otherwise only
91089115
the first level children are returned
91099116
:type full_hierarchy: bool
9117+
:param query: Additional query parameters to pass into the subgroups fetch requests.
9118+
:type query: dict | None
91109119
:return: Keycloak server response (GroupRepresentation)
91119120
:rtype: dict
91129121
"""
9122+
query = query or {}
91139123
params_path = {"realm-name": self.connection.realm_name, "id": group_id}
91149124
response = await self.connection.a_raw_get(
91159125
urls_patterns.URL_ADMIN_GROUP.format(**params_path),
@@ -9122,8 +9132,7 @@ async def a_get_group(self, group_id: str, full_hierarchy: bool = False) -> dict
91229132
group = response.json()
91239133
if group.get("subGroupCount"):
91249134
group["subGroups"] = await self.a_get_group_children(
9125-
group.get("id"),
9126-
full_hierarchy=full_hierarchy,
9135+
group.get("id"), full_hierarchy=full_hierarchy, query=query
91279136
)
91289137

91299138
return group
@@ -9193,8 +9202,7 @@ async def a_get_group_children(
91939202
for group in res:
91949203
if group.get("subGroupCount"):
91959204
group["subGroups"] = await self.a_get_group_children(
9196-
group_id=group.get("id"),
9197-
full_hierarchy=full_hierarchy,
9205+
group_id=group.get("id"), full_hierarchy=full_hierarchy, query=query
91989206
)
91999207

92009208
return res

0 commit comments

Comments
 (0)