Port synapse/rest/client/_base.py to async/await
This commit is contained in:
parent
3c2d6c708c
commit
2e97a4c197
|
@ -15,8 +15,6 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from twisted.internet import defer
|
|
||||||
|
|
||||||
from synapse.api.errors import AuthError
|
from synapse.api.errors import AuthError
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,8 +40,7 @@ def historical_admin_path_patterns(path_regex):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
async def assert_requester_is_admin(auth, request):
|
||||||
def assert_requester_is_admin(auth, request):
|
|
||||||
"""Verify that the requester is an admin user
|
"""Verify that the requester is an admin user
|
||||||
|
|
||||||
WARNING: MAKE SURE YOU YIELD ON THE RESULT!
|
WARNING: MAKE SURE YOU YIELD ON THE RESULT!
|
||||||
|
@ -58,12 +55,11 @@ def assert_requester_is_admin(auth, request):
|
||||||
Raises:
|
Raises:
|
||||||
AuthError if the requester is not an admin
|
AuthError if the requester is not an admin
|
||||||
"""
|
"""
|
||||||
requester = yield auth.get_user_by_req(request)
|
requester = await auth.get_user_by_req(request)
|
||||||
yield assert_user_is_admin(auth, requester.user)
|
await assert_user_is_admin(auth, requester.user)
|
||||||
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
async def assert_user_is_admin(auth, user_id):
|
||||||
def assert_user_is_admin(auth, user_id):
|
|
||||||
"""Verify that the given user is an admin user
|
"""Verify that the given user is an admin user
|
||||||
|
|
||||||
WARNING: MAKE SURE YOU YIELD ON THE RESULT!
|
WARNING: MAKE SURE YOU YIELD ON THE RESULT!
|
||||||
|
@ -79,6 +75,6 @@ def assert_user_is_admin(auth, user_id):
|
||||||
AuthError if the user is not an admin
|
AuthError if the user is not an admin
|
||||||
"""
|
"""
|
||||||
|
|
||||||
is_admin = yield auth.is_server_admin(user_id)
|
is_admin = await auth.is_server_admin(user_id)
|
||||||
if not is_admin:
|
if not is_admin:
|
||||||
raise AuthError(403, "You are not a server admin")
|
raise AuthError(403, "You are not a server admin")
|
||||||
|
|
Loading…
Reference in New Issue