mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Port synaps/rest/client/users.py to async/await
This commit is contained in:
parent
f95325e22a
commit
dfbb62c28d
@ -14,8 +14,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from twisted.internet import defer
|
|
||||||
|
|
||||||
from synapse.api.errors import SynapseError
|
from synapse.api.errors import SynapseError
|
||||||
from synapse.http.servlet import (
|
from synapse.http.servlet import (
|
||||||
RestServlet,
|
RestServlet,
|
||||||
@ -59,24 +57,22 @@ class UserAdminServlet(RestServlet):
|
|||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
self.handlers = hs.get_handlers()
|
self.handlers = hs.get_handlers()
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
async def on_GET(self, request, user_id):
|
||||||
def on_GET(self, request, user_id):
|
await assert_requester_is_admin(self.auth, request)
|
||||||
yield assert_requester_is_admin(self.auth, request)
|
|
||||||
|
|
||||||
target_user = UserID.from_string(user_id)
|
target_user = UserID.from_string(user_id)
|
||||||
|
|
||||||
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 = yield self.handlers.admin_handler.get_user_server_admin(target_user)
|
is_admin = await self.handlers.admin_handler.get_user_server_admin(target_user)
|
||||||
is_admin = bool(is_admin)
|
is_admin = bool(is_admin)
|
||||||
|
|
||||||
return 200, {"admin": is_admin}
|
return 200, {"admin": is_admin}
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
async def on_PUT(self, request, user_id):
|
||||||
def on_PUT(self, request, user_id):
|
requester = await self.auth.get_user_by_req(request)
|
||||||
requester = yield self.auth.get_user_by_req(request)
|
await assert_user_is_admin(self.auth, requester.user)
|
||||||
yield assert_user_is_admin(self.auth, requester.user)
|
|
||||||
auth_user = requester.user
|
auth_user = requester.user
|
||||||
|
|
||||||
target_user = UserID.from_string(user_id)
|
target_user = UserID.from_string(user_id)
|
||||||
@ -93,7 +89,7 @@ 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.")
|
||||||
|
|
||||||
yield self.handlers.admin_handler.set_user_server_admin(
|
await self.handlers.admin_handler.set_user_server_admin(
|
||||||
target_user, set_admin_to
|
target_user, set_admin_to
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user