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

Commit 61f8f25

Browse files
author
David Robertson
committed
Move the models into the servlet classes
1 parent dc1f188 commit 61f8f25

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

synapse/rest/client/account.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,6 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
147147
return 200, ret
148148

149149

150-
class PasswordBody(BaseModel):
151-
auth: Optional[AuthenticationData] = None
152-
logout_devices: StrictBool = True
153-
if TYPE_CHECKING:
154-
# workaround for https://github.com/samuelcolvin/pydantic/issues/156
155-
new_password: Optional[str] = None
156-
else:
157-
new_password: Optional[constr(max_length=512)] = None
158-
159-
160150
class PasswordRestServlet(RestServlet):
161151
PATTERNS = client_patterns("/account/password$")
162152

@@ -169,9 +159,18 @@ def __init__(self, hs: "HomeServer"):
169159
self.password_policy_handler = hs.get_password_policy_handler()
170160
self._set_password_handler = hs.get_set_password_handler()
171161

162+
class PostBody(BaseModel):
163+
auth: Optional[AuthenticationData] = None
164+
logout_devices: StrictBool = True
165+
if TYPE_CHECKING:
166+
# workaround for https://github.com/samuelcolvin/pydantic/issues/156
167+
new_password: Optional[str] = None
168+
else:
169+
new_password: Optional[constr(max_length=512)] = None
170+
172171
@interactive_auth_handler
173172
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
174-
body = parse_and_validate_json_object_from_request(request, PasswordBody)
173+
body = parse_and_validate_json_object_from_request(request, self.PostBody)
175174

176175
# we do basic sanity checks here because the auth layer will store these
177176
# in sessions. Pull out the new password provided to us.
@@ -284,13 +283,6 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
284283
return 200, {}
285284

286285

287-
class DeactivateAccountBody(BaseModel):
288-
auth: Optional[AuthenticationData] = None
289-
id_server: Optional[StrictStr] = None
290-
# Not specced, see https://github.com/matrix-org/matrix-spec/issues/297
291-
erase: StrictBool = False
292-
293-
294286
class DeactivateAccountRestServlet(RestServlet):
295287
PATTERNS = client_patterns("/account/deactivate$")
296288

@@ -301,10 +293,16 @@ def __init__(self, hs: "HomeServer"):
301293
self.auth_handler = hs.get_auth_handler()
302294
self._deactivate_account_handler = hs.get_deactivate_account_handler()
303295

296+
class PostBody(BaseModel):
297+
auth: Optional[AuthenticationData] = None
298+
id_server: Optional[StrictStr] = None
299+
# Not specced, see https://github.com/matrix-org/matrix-spec/issues/297
300+
erase: StrictBool = False
301+
304302
@interactive_auth_handler
305303
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
306304
body = parse_and_validate_json_object_from_request(
307-
request, DeactivateAccountBody
305+
request, self.PostBody
308306
)
309307

310308
requester = await self.auth.get_user_by_req(request)

0 commit comments

Comments
 (0)