diff options
author | Erik Johnston <erikj@jki.re> | 2016-06-30 15:57:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-30 15:57:29 +0100 |
commit | ab71589c0beb392333ec41c887d08a6c577121dd (patch) | |
tree | 199bef20aca0ca594d234ff61c16ab44e46be91f /synapse/rest/client/v1/admin.py | |
parent | Merge pull request #902 from matrix-org/erikj/expire_media (diff) | |
parent | Feature: Add deactivate account admin API (diff) | |
download | synapse-ab71589c0beb392333ec41c887d08a6c577121dd.tar.xz |
Merge pull request #903 from matrix-org/erikj/deactivate_user
Feature: Add deactivate account admin API
Diffstat (limited to 'synapse/rest/client/v1/admin.py')
-rw-r--r-- | synapse/rest/client/v1/admin.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/synapse/rest/client/v1/admin.py b/synapse/rest/client/v1/admin.py index 8ec8569a49..e54c472e08 100644 --- a/synapse/rest/client/v1/admin.py +++ b/synapse/rest/client/v1/admin.py @@ -77,6 +77,32 @@ class PurgeMediaCacheRestServlet(ClientV1RestServlet): defer.returnValue((200, ret)) +class DeactivateAccountRestServlet(ClientV1RestServlet): + PATTERNS = client_path_patterns("/admin/deactivate/(?P<target_user_id>[^/]*)") + + def __init__(self, hs): + self.store = hs.get_datastore() + super(DeactivateAccountRestServlet, self).__init__(hs) + + @defer.inlineCallbacks + def on_POST(self, request, target_user_id): + UserID.from_string(target_user_id) + requester = yield self.auth.get_user_by_req(request) + is_admin = yield self.auth.is_server_admin(requester.user) + + if not is_admin: + raise AuthError(403, "You are not a server admin") + + # FIXME: Theoretically there is a race here wherein user resets password + # using threepid. + yield self.store.user_delete_access_tokens(target_user_id) + yield self.store.user_delete_threepids(target_user_id) + yield self.store.user_set_password_hash(target_user_id, None) + + defer.returnValue((200, {})) + + def register_servlets(hs, http_server): WhoisRestServlet(hs).register(http_server) PurgeMediaCacheRestServlet(hs).register(http_server) + DeactivateAccountRestServlet(hs).register(http_server) |