Add auth check to test if a user is an admin or not.
parent
f7d80930f2
commit
c65306f877
|
@ -259,6 +259,9 @@ class Auth(object):
|
||||||
raise AuthError(403, "Unrecognised access token.",
|
raise AuthError(403, "Unrecognised access token.",
|
||||||
errcode=Codes.UNKNOWN_TOKEN)
|
errcode=Codes.UNKNOWN_TOKEN)
|
||||||
|
|
||||||
|
def is_server_admin(self, user):
|
||||||
|
return self.store.is_server_admin(user)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def _can_send_event(self, event):
|
def _can_send_event(self, event):
|
||||||
|
|
|
@ -103,6 +103,14 @@ class RegistrationStore(SQLBaseStore):
|
||||||
token)
|
token)
|
||||||
defer.returnValue(user_id)
|
defer.returnValue(user_id)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def is_server_admin(self, user):
|
||||||
|
return self._simple_select_one_onecol(
|
||||||
|
table="users",
|
||||||
|
keyvalues={"name": user.to_string()},
|
||||||
|
retcol="admin",
|
||||||
|
)
|
||||||
|
|
||||||
def _query_for_auth(self, txn, token):
|
def _query_for_auth(self, txn, token):
|
||||||
txn.execute("SELECT users.name FROM access_tokens LEFT JOIN users" +
|
txn.execute("SELECT users.name FROM access_tokens LEFT JOIN users" +
|
||||||
" ON users.id = access_tokens.user_id WHERE token = ?",
|
" ON users.id = access_tokens.user_id WHERE token = ?",
|
||||||
|
|
Loading…
Reference in New Issue