Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 508a3c3

Browse files
author
David Robertson
committed
Use Pydantic to validate PUT /directory/list/appservice/NETWORK/ROOM_ID
1 parent fb9b361 commit 508a3c3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

synapse/rest/client/directory.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,14 @@ def __init__(self, hs: "HomeServer"):
170170
self.directory_handler = hs.get_directory_handler()
171171
self.auth = hs.get_auth()
172172

173+
class PutBody(RequestBodyModel):
174+
visibility: Literal["public", "private"] = "public"
175+
173176
async def on_PUT(
174177
self, request: SynapseRequest, network_id: str, room_id: str
175178
) -> Tuple[int, JsonDict]:
176-
content = parse_json_object_from_request(request)
177-
visibility = content.get("visibility", "public")
178-
return await self._edit(request, network_id, room_id, visibility)
179+
content = parse_and_validate_json_object_from_request(request, self.PutBody)
180+
return await self._edit(request, network_id, room_id, content.visibility)
179181

180182
async def on_DELETE(
181183
self, request: SynapseRequest, network_id: str, room_id: str

0 commit comments

Comments
 (0)