This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
A second batch of Pydantic models for rest/client/account.py #13687
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b5cb8b1
Pydantic for MsisdnThreepidRequestTokenRestServlet
98f534b
Pydantic for experimental `account_status` endpoint
6180af6
Fixup comment in the light of #13563
714ee54
Changelog
b861950
Relax length constraint on user_ids
eff0ffa
Sneak in extra validation for `country`
1ed5544
Fix lint
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve validation of request bodies for the following client-server API endpoints: [`/account/3pid/msisdn/requestToken`](https://spec.matrix.org/v1.3/client-server-api/#post_matrixclientv3account3pidmsisdnrequesttoken) and [`/org.matrix.msc3720/account_status`](https://github.com/matrix-org/matrix-spec-proposals/blob/babolivier/user_status/proposals/3720-account-status.md#post-_matrixclientv1account_status). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,8 @@ class AuthenticationData(RequestBodyModel): | |
|
||
(The name "Authentication Data" is taken directly from the spec.) | ||
|
||
Additional keys will be present, depending on the `type` field. Use `.dict()` to | ||
access them. | ||
Additional keys will be present, depending on the `type` field. Use | ||
`.dict(exclude_unset=True)` to access them. | ||
""" | ||
|
||
class Config: | ||
|
@@ -36,7 +36,7 @@ class Config: | |
type: Optional[StrictStr] = None | ||
|
||
|
||
class EmailRequestTokenBody(RequestBodyModel): | ||
class ThreePidRequestTokenBody(RequestBodyModel): | ||
if TYPE_CHECKING: | ||
client_secret: StrictStr | ||
else: | ||
|
@@ -47,7 +47,7 @@ class EmailRequestTokenBody(RequestBodyModel): | |
max_length=255, | ||
strict=True, | ||
) | ||
email: StrictStr | ||
|
||
id_server: Optional[StrictStr] | ||
id_access_token: Optional[StrictStr] | ||
next_link: Optional[StrictStr] | ||
|
@@ -61,9 +61,25 @@ def token_required_for_identity_server( | |
raise ValueError("id_access_token is required if an id_server is supplied.") | ||
return token | ||
|
||
|
||
class EmailRequestTokenBody(ThreePidRequestTokenBody): | ||
email: StrictStr | ||
|
||
# Canonicalise the email address. The addresses are all stored canonicalised | ||
# in the database. This allows the user to reset his password without having to | ||
# know the exact spelling (eg. upper and lower case) of address in the database. | ||
# Without this, an email stored in the database as "[email protected]" would cause | ||
# user requests for "[email protected]" to raise a Not Found error. | ||
_email_validator = validator("email", allow_reuse=True)(validate_email) | ||
|
||
|
||
if TYPE_CHECKING: | ||
ISO3116_1_Alpha_2 = StrictStr | ||
else: | ||
# Per spec: two-letter uppercase ISO-3166-1-alpha-2 | ||
ISO3116_1_Alpha_2 = constr(regex="[A-Z]{2}", strict=True) | ||
|
||
|
||
class MsisdnRequestTokenBody(ThreePidRequestTokenBody): | ||
country: ISO3116_1_Alpha_2 | ||
phone_number: StrictStr |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not accurate indeed. Looks like the previous error message raised in this case was mis-interpreted in #3789.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wondered if this was possibly intended as a spam deterrent.