Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Move UsersRestServlet into rest/admin/users.py
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Stahl <manuel.stahl@awesome-technologies.de>
  • Loading branch information
awesome-manuel committed Aug 30, 2019
1 parent 2081156 commit f16a0c2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
38 changes: 1 addition & 37 deletions synapse/rest/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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$"),)

Expand Down
46 changes: 45 additions & 1 deletion synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,62 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import re
import logging

from twisted.internet import defer

from synapse.api.errors import SynapseError
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):
"""
Expand Down

0 comments on commit f16a0c2

Please sign in to comment.