SYN-48: Implement WHOIS rest servlet

This commit is contained in:
Erik Johnston 2014-09-29 14:59:52 +01:00
parent c65306f877
commit 3ccb17ce59
9 changed files with 190 additions and 25 deletions

View file

@ -88,7 +88,6 @@ class RegistrationStore(SQLBaseStore):
query, user_id
)
@defer.inlineCallbacks
def get_user_by_token(self, token):
"""Get a user from the given access token.
@ -99,11 +98,11 @@ class RegistrationStore(SQLBaseStore):
Raises:
StoreError if no user was found.
"""
user_id = yield self.runInteraction(self._query_for_auth,
token)
defer.returnValue(user_id)
return self.runInteraction(
self._query_for_auth,
token
)
@defer.inlineCallbacks
def is_server_admin(self, user):
return self._simple_select_one_onecol(
table="users",
@ -112,11 +111,16 @@ class RegistrationStore(SQLBaseStore):
)
def _query_for_auth(self, txn, token):
txn.execute("SELECT users.name FROM access_tokens LEFT JOIN users" +
" ON users.id = access_tokens.user_id WHERE token = ?",
[token])
row = txn.fetchone()
if row:
return row[0]
sql = (
"SELECT users.name, users.admin, access_tokens.device_id "
"FROM users "
"INNER JOIN access_tokens on users.id = access_tokens.user_id "
"WHERE token = ?"
)
cursor = txn.execute(sql, (token,))
rows = self.cursor_to_dict(cursor)
if rows:
return rows[0]
raise StoreError(404, "Token not found.")