From f16a0c26a977df531d7930b87df780c773646825 Mon Sep 17 00:00:00 2001 From: Manuel Stahl Date: Fri, 30 Aug 2019 14:10:37 +0200 Subject: [PATCH] Move UsersRestServlet into rest/admin/users.py Signed-off-by: Manuel Stahl --- synapse/rest/admin/__init__.py | 38 +--------------------------- synapse/rest/admin/users.py | 46 +++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/synapse/rest/admin/__init__.py b/synapse/rest/admin/__init__.py index 036e5a75ae85..066ca27fb1ba 100644 --- a/synapse/rest/admin/__init__.py +++ b/synapse/rest/admin/__init__.py @@ -44,49 +44,13 @@ from synapse.rest.admin.media import register_servlets_for_media_repo from synapse.rest.admin.purge_room_servlet import PurgeRoomServlet from synapse.rest.admin.server_notice_servlet import SendServerNoticeServlet -from synapse.rest.admin.users import UserAdminServlet +from synapse.rest.admin.users import UserAdminServlet, UsersRestServlet from synapse.types import UserID, create_requester from synapse.util.versionstring import get_version_string logger = logging.getLogger(__name__) -class UsersRestServlet(RestServlet): - PATTERNS = historical_admin_path_patterns("/users$") - - """Get request to list all local users. - This needs user to have administrator access in Synapse. - - GET /_synapse/admin/v1/users?access_token=admin_access_token&start=0&limit=10 - - returns: - 200 OK with list of users if success otherwise an error. - - The parameters `start` and `limit` are optional if you want to use pagination. - """ - - def __init__(self, hs): - self.hs = hs - self.auth = hs.get_auth() - self.handlers = hs.get_handlers() - - @defer.inlineCallbacks - def on_GET(self, request): - yield assert_requester_is_admin(self.auth, request) - - order = "name" # order by name in user table - start = parse_integer(request, "start") - limit = parse_integer(request, "limit") - - ret = None - if (start != None and limit != None): - logger.info("limit: %s, start: %s", limit, start) - ret = yield self.handlers.admin_handler.get_users_paginate(order, start, limit) - else: - ret = yield self.handlers.admin_handler.get_users() - return (200, ret) - - class VersionServlet(RestServlet): PATTERNS = (re.compile("^/_synapse/admin/v1/server_version$"),) diff --git a/synapse/rest/admin/users.py b/synapse/rest/admin/users.py index 536411742095..1a57b896ea3c 100644 --- a/synapse/rest/admin/users.py +++ b/synapse/rest/admin/users.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import re +import logging from twisted.internet import defer @@ -20,11 +21,54 @@ from synapse.http.servlet import ( RestServlet, assert_params_in_dict, + parse_integer, parse_json_object_from_request, ) -from synapse.rest.admin import assert_requester_is_admin, assert_user_is_admin +from synapse.rest.admin import ( + assert_requester_is_admin, + assert_user_is_admin, + historical_admin_path_patterns, +) from synapse.types import UserID +logger = logging.getLogger(__name__) + + +class UsersRestServlet(RestServlet): + PATTERNS = historical_admin_path_patterns("/users$") + + """Get request to list all local users. + This needs user to have administrator access in Synapse. + + GET /_synapse/admin/v1/users?access_token=admin_access_token&start=0&limit=10 + + returns: + 200 OK with list of users if success otherwise an error. + + The parameters `start` and `limit` are optional if you want to use pagination. + """ + + def __init__(self, hs): + self.hs = hs + self.auth = hs.get_auth() + self.handlers = hs.get_handlers() + + @defer.inlineCallbacks + def on_GET(self, request): + yield assert_requester_is_admin(self.auth, request) + + order = "name" # order by name in user table + start = parse_integer(request, "start") + limit = parse_integer(request, "limit") + + ret = None + if (start != None and limit != None): + logger.info("limit: %s, start: %s", limit, start) + ret = yield self.handlers.admin_handler.get_users_paginate(order, start, limit) + else: + ret = yield self.handlers.admin_handler.get_users() + return (200, ret) + class UserAdminServlet(RestServlet): """