mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-09-09 13:11:52 +00:00
Fix type information on assert_*_is_admin
methods (#7645)
These things don't return Deferreds.
This commit is contained in:
parent
b4f8dcb4bd
commit
eea124370b
1
changelog.d/7645.misc
Normal file
1
changelog.d/7645.misc
Normal file
@ -0,0 +1 @@
|
||||
Fix type information on `assert_*_is_admin` methods.
|
@ -510,16 +510,16 @@ class Auth(object):
|
||||
request.authenticated_entity = service.sender
|
||||
return defer.succeed(service)
|
||||
|
||||
def is_server_admin(self, user):
|
||||
async def is_server_admin(self, user: UserID) -> bool:
|
||||
""" Check if the given user is a local server admin.
|
||||
|
||||
Args:
|
||||
user (UserID): user to check
|
||||
user: user to check
|
||||
|
||||
Returns:
|
||||
bool: True if the user is an admin
|
||||
True if the user is an admin
|
||||
"""
|
||||
return self.store.is_server_admin(user)
|
||||
return await self.store.is_server_admin(user)
|
||||
|
||||
def compute_auth_events(
|
||||
self, event, current_state_ids: StateMap[str], for_verification: bool = False,
|
||||
|
@ -15,7 +15,11 @@
|
||||
|
||||
import re
|
||||
|
||||
import twisted.web.server
|
||||
|
||||
import synapse.api.auth
|
||||
from synapse.api.errors import AuthError
|
||||
from synapse.types import UserID
|
||||
|
||||
|
||||
def historical_admin_path_patterns(path_regex):
|
||||
@ -55,41 +59,32 @@ def admin_patterns(path_regex: str):
|
||||
return patterns
|
||||
|
||||
|
||||
async def assert_requester_is_admin(auth, request):
|
||||
async def assert_requester_is_admin(
|
||||
auth: synapse.api.auth.Auth, request: twisted.web.server.Request
|
||||
) -> None:
|
||||
"""Verify that the requester is an admin user
|
||||
|
||||
WARNING: MAKE SURE YOU YIELD ON THE RESULT!
|
||||
|
||||
Args:
|
||||
auth (synapse.api.auth.Auth):
|
||||
request (twisted.web.server.Request): incoming request
|
||||
|
||||
Returns:
|
||||
Deferred
|
||||
auth: api.auth.Auth singleton
|
||||
request: incoming request
|
||||
|
||||
Raises:
|
||||
AuthError if the requester is not an admin
|
||||
AuthError if the requester is not a server admin
|
||||
"""
|
||||
requester = await auth.get_user_by_req(request)
|
||||
await assert_user_is_admin(auth, requester.user)
|
||||
|
||||
|
||||
async def assert_user_is_admin(auth, user_id):
|
||||
async def assert_user_is_admin(auth: synapse.api.auth.Auth, user_id: UserID) -> None:
|
||||
"""Verify that the given user is an admin user
|
||||
|
||||
WARNING: MAKE SURE YOU YIELD ON THE RESULT!
|
||||
|
||||
Args:
|
||||
auth (synapse.api.auth.Auth):
|
||||
user_id (UserID):
|
||||
|
||||
Returns:
|
||||
Deferred
|
||||
auth: api.auth.Auth singleton
|
||||
user_id: user to check
|
||||
|
||||
Raises:
|
||||
AuthError if the user is not an admin
|
||||
AuthError if the user is not a server admin
|
||||
"""
|
||||
|
||||
is_admin = await auth.is_server_admin(user_id)
|
||||
if not is_admin:
|
||||
raise AuthError(403, "You are not a server admin")
|
||||
|
Loading…
Reference in New Issue
Block a user