diff options
author | Patrick Cloke <patrickc@matrix.org> | 2020-09-17 16:30:47 -0400 |
---|---|---|
committer | Patrick Cloke <patrickc@matrix.org> | 2020-09-17 16:30:47 -0400 |
commit | c39941cd6e3727d5571d01bc6f72d7d439f41d13 (patch) | |
tree | fdc74fd9f1879c403f5d0fe256ee8d96d172c52e /synapse/rest | |
parent | Remove obsolete __future__ imports (#8337) (diff) | |
download | synapse-github/clokep/schema-validate.tar.xz |
Proof-of-concept for using jsonschema on an endpoint. github/clokep/schema-validate clokep/schema-validate
Diffstat (limited to 'synapse/rest')
-rw-r--r-- | synapse/rest/client/v1/profile.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/synapse/rest/client/v1/profile.py b/synapse/rest/client/v1/profile.py index e7fe50ed72..78a3bebc7f 100644 --- a/synapse/rest/client/v1/profile.py +++ b/synapse/rest/client/v1/profile.py @@ -24,6 +24,14 @@ from synapse.types import UserID class ProfileDisplaynameRestServlet(RestServlet): PATTERNS = client_patterns("/profile/(?P<user_id>[^/]*)/displayname", v1=True) + PUT_SCHEMA = { + "type": "object", + "properties": { + "displayname": {"oneOf": [{"type": "string"}, {"type": "null"}]}, + "required": ["displayname"], + }, + } + def __init__(self, hs): super(ProfileDisplaynameRestServlet, self).__init__() self.hs = hs @@ -54,12 +62,8 @@ class ProfileDisplaynameRestServlet(RestServlet): user = UserID.from_string(user_id) is_admin = await self.auth.is_server_admin(requester.user) - content = parse_json_object_from_request(request) - - try: - new_name = content["displayname"] - except Exception: - return 400, "Unable to parse name" + content = parse_json_object_from_request(request, validator=self.PUT_VALIDATOR) + new_name = content["displayname"] await self.profile_handler.set_displayname(user, requester, new_name, is_admin) |