mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Remove unnecessary abstractions in admin handler (#6751)
This commit is contained in:
parent
33f7e5ce2a
commit
ce84dd9e20
1
changelog.d/6751.misc
Normal file
1
changelog.d/6751.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Remove some unnecessary admin handler abstraction methods.
|
@ -62,68 +62,6 @@ class AdminHandler(BaseHandler):
|
|||||||
ret["avatar_url"] = profile.avatar_url
|
ret["avatar_url"] = profile.avatar_url
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
async def get_users(self):
|
|
||||||
"""Function to retrieve a list of users in users table.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
Returns:
|
|
||||||
defer.Deferred: resolves to list[dict[str, Any]]
|
|
||||||
"""
|
|
||||||
ret = await self.store.get_users()
|
|
||||||
|
|
||||||
return ret
|
|
||||||
|
|
||||||
async def get_users_paginate(self, start, limit, name, guests, deactivated):
|
|
||||||
"""Function to retrieve a paginated list of users from
|
|
||||||
users list. This will return a json list of users.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
start (int): start number to begin the query from
|
|
||||||
limit (int): number of rows to retrieve
|
|
||||||
name (string): filter for user names
|
|
||||||
guests (bool): whether to in include guest users
|
|
||||||
deactivated (bool): whether to include deactivated users
|
|
||||||
Returns:
|
|
||||||
defer.Deferred: resolves to json list[dict[str, Any]]
|
|
||||||
"""
|
|
||||||
ret = await self.store.get_users_paginate(
|
|
||||||
start, limit, name, guests, deactivated
|
|
||||||
)
|
|
||||||
|
|
||||||
return ret
|
|
||||||
|
|
||||||
async def search_users(self, term):
|
|
||||||
"""Function to search users list for one or more users with
|
|
||||||
the matched term.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
term (str): search term
|
|
||||||
Returns:
|
|
||||||
defer.Deferred: resolves to list[dict[str, Any]]
|
|
||||||
"""
|
|
||||||
ret = await self.store.search_users(term)
|
|
||||||
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def get_user_server_admin(self, user):
|
|
||||||
"""
|
|
||||||
Get the admin bit on a user.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
user_id (UserID): the (necessarily local) user to manipulate
|
|
||||||
"""
|
|
||||||
return self.store.is_server_admin(user)
|
|
||||||
|
|
||||||
def set_user_server_admin(self, user, admin):
|
|
||||||
"""
|
|
||||||
Set the admin bit on a user.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
user_id (UserID): the (necessarily local) user to manipulate
|
|
||||||
admin (bool): whether or not the user should be an admin of this server
|
|
||||||
"""
|
|
||||||
return self.store.set_server_admin(user, admin)
|
|
||||||
|
|
||||||
async def export_user_data(self, user_id, writer):
|
async def export_user_data(self, user_id, writer):
|
||||||
"""Write all data we have on the user to the given writer.
|
"""Write all data we have on the user to the given writer.
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ class UsersRestServlet(RestServlet):
|
|||||||
|
|
||||||
def __init__(self, hs):
|
def __init__(self, hs):
|
||||||
self.hs = hs
|
self.hs = hs
|
||||||
|
self.store = hs.get_datastore()
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
self.admin_handler = hs.get_handlers().admin_handler
|
self.admin_handler = hs.get_handlers().admin_handler
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ class UsersRestServlet(RestServlet):
|
|||||||
if not self.hs.is_mine(target_user):
|
if not self.hs.is_mine(target_user):
|
||||||
raise SynapseError(400, "Can only users a local user")
|
raise SynapseError(400, "Can only users a local user")
|
||||||
|
|
||||||
ret = await self.admin_handler.get_users()
|
ret = await self.store.get_users()
|
||||||
|
|
||||||
return 200, ret
|
return 200, ret
|
||||||
|
|
||||||
@ -80,6 +81,7 @@ class UsersRestServletV2(RestServlet):
|
|||||||
|
|
||||||
def __init__(self, hs):
|
def __init__(self, hs):
|
||||||
self.hs = hs
|
self.hs = hs
|
||||||
|
self.store = hs.get_datastore()
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
self.admin_handler = hs.get_handlers().admin_handler
|
self.admin_handler = hs.get_handlers().admin_handler
|
||||||
|
|
||||||
@ -92,7 +94,7 @@ class UsersRestServletV2(RestServlet):
|
|||||||
guests = parse_boolean(request, "guests", default=True)
|
guests = parse_boolean(request, "guests", default=True)
|
||||||
deactivated = parse_boolean(request, "deactivated", default=False)
|
deactivated = parse_boolean(request, "deactivated", default=False)
|
||||||
|
|
||||||
users = await self.admin_handler.get_users_paginate(
|
users = await self.store.get_users_paginate(
|
||||||
start, limit, user_id, guests, deactivated
|
start, limit, user_id, guests, deactivated
|
||||||
)
|
)
|
||||||
ret = {"users": users}
|
ret = {"users": users}
|
||||||
@ -516,8 +518,8 @@ class SearchUsersRestServlet(RestServlet):
|
|||||||
PATTERNS = historical_admin_path_patterns("/search_users/(?P<target_user_id>[^/]*)")
|
PATTERNS = historical_admin_path_patterns("/search_users/(?P<target_user_id>[^/]*)")
|
||||||
|
|
||||||
def __init__(self, hs):
|
def __init__(self, hs):
|
||||||
self.store = hs.get_datastore()
|
|
||||||
self.hs = hs
|
self.hs = hs
|
||||||
|
self.store = hs.get_datastore()
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
self.handlers = hs.get_handlers()
|
self.handlers = hs.get_handlers()
|
||||||
|
|
||||||
@ -540,7 +542,7 @@ class SearchUsersRestServlet(RestServlet):
|
|||||||
term = parse_string(request, "term", required=True)
|
term = parse_string(request, "term", required=True)
|
||||||
logger.info("term: %s ", term)
|
logger.info("term: %s ", term)
|
||||||
|
|
||||||
ret = await self.handlers.admin_handler.search_users(term)
|
ret = await self.handlers.store.search_users(term)
|
||||||
return 200, ret
|
return 200, ret
|
||||||
|
|
||||||
|
|
||||||
@ -574,8 +576,8 @@ class UserAdminServlet(RestServlet):
|
|||||||
|
|
||||||
def __init__(self, hs):
|
def __init__(self, hs):
|
||||||
self.hs = hs
|
self.hs = hs
|
||||||
|
self.store = hs.get_datastore()
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
self.handlers = hs.get_handlers()
|
|
||||||
|
|
||||||
async def on_GET(self, request, user_id):
|
async def on_GET(self, request, user_id):
|
||||||
await assert_requester_is_admin(self.auth, request)
|
await assert_requester_is_admin(self.auth, request)
|
||||||
@ -585,8 +587,7 @@ class UserAdminServlet(RestServlet):
|
|||||||
if not self.hs.is_mine(target_user):
|
if not self.hs.is_mine(target_user):
|
||||||
raise SynapseError(400, "Only local users can be admins of this homeserver")
|
raise SynapseError(400, "Only local users can be admins of this homeserver")
|
||||||
|
|
||||||
is_admin = await self.handlers.admin_handler.get_user_server_admin(target_user)
|
is_admin = await self.store.is_server_admin(target_user)
|
||||||
is_admin = bool(is_admin)
|
|
||||||
|
|
||||||
return 200, {"admin": is_admin}
|
return 200, {"admin": is_admin}
|
||||||
|
|
||||||
@ -609,8 +610,6 @@ class UserAdminServlet(RestServlet):
|
|||||||
if target_user == auth_user and not set_admin_to:
|
if target_user == auth_user and not set_admin_to:
|
||||||
raise SynapseError(400, "You may not demote yourself.")
|
raise SynapseError(400, "You may not demote yourself.")
|
||||||
|
|
||||||
await self.handlers.admin_handler.set_user_server_admin(
|
await self.store.set_user_server_admin(target_user, set_admin_to)
|
||||||
target_user, set_admin_to
|
|
||||||
)
|
|
||||||
|
|
||||||
return 200, {}
|
return 200, {}
|
||||||
|
@ -291,7 +291,7 @@ class RegistrationWorkerStore(SQLBaseStore):
|
|||||||
desc="is_server_admin",
|
desc="is_server_admin",
|
||||||
)
|
)
|
||||||
|
|
||||||
return res if res else False
|
return bool(res) if res else False
|
||||||
|
|
||||||
def set_server_admin(self, user, admin):
|
def set_server_admin(self, user, admin):
|
||||||
"""Sets whether a user is an admin of this homeserver.
|
"""Sets whether a user is an admin of this homeserver.
|
||||||
|
Loading…
Reference in New Issue
Block a user