api: Add USER_DEACTIVATED error code.

In validate_account_and_subdomain we check if
user's account is not deactivated. In case of
failure of this check we raise our standard
JsonableError. While this works well in most
cases but it creates difficulties in handling
of deactivated accounts for non-browser clients.

So we register a new USER_DEACTIVATED error
code so that clients can distinguish if error
is because of deactivated account. Following
these changes `validate_account_and_subdomain`
raises UserDeactivatedError if user's account
is deactivated.

This error is also documented in
`/api/rest-error-handling`.

Testing: I have mostly relied on automated
backend tests to test this.

Partially addresses issue #17763.
This commit is contained in:
m-e-l-u-h-a-n
2021-03-31 15:30:56 +05:30
committed by Tim Abbott
parent 66d7e711b2
commit 2eeb82edba
7 changed files with 71 additions and 7 deletions

View File

@@ -1224,6 +1224,15 @@ def test_missing_request_argument(client: Client) -> None:
validate_against_openapi_schema(result, "/rest-error-handling", "post", "400_1")
def test_user_account_deactivated(client: Client) -> None:
request = {
"content": "**foo**",
}
result = client.render_message(request)
validate_against_openapi_schema(result, "/rest-error-handling", "post", "403_0")
def test_invalid_stream_error(client: Client) -> None:
result = client.get_stream_id("nonexistent")