mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2024-10-01 03:35:38 -04:00
daemon: Handle invalid order by fields for the search.
This commit is contained in:
parent
8927bb0c90
commit
818db73a48
@ -98,6 +98,9 @@ def validate_json(instance, schema):
|
||||
class UnknownRoomError(Exception):
|
||||
pass
|
||||
|
||||
class InvalidOrderByError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class PanClient(AsyncClient):
|
||||
"""A wrapper class around a nio AsyncClient extending its functionality."""
|
||||
@ -599,6 +602,10 @@ class PanClient(AsyncClient):
|
||||
term = search_terms["search_term"]
|
||||
search_filter = search_terms["filter"]
|
||||
limit = search_filter.get("limit", 10)
|
||||
order_by = search_terms.get("order_by")
|
||||
|
||||
if order_by not in ["rank", "recent"]:
|
||||
raise InvalidOrderByError(f"Invalid order by: {order_by}")
|
||||
|
||||
before_limit = 0
|
||||
after_limit = 0
|
||||
|
@ -28,7 +28,7 @@ from multidict import CIMultiDict
|
||||
from nio import (Api, EncryptionError, LoginResponse, OlmTrustError,
|
||||
SendRetryError)
|
||||
|
||||
from pantalaimon.client import PanClient, UnknownRoomError
|
||||
from pantalaimon.client import PanClient, UnknownRoomError, InvalidOrderByError
|
||||
from pantalaimon.log import logger
|
||||
from pantalaimon.store import ClientInfo, PanStore
|
||||
from pantalaimon.thread_messages import (AcceptSasMessage, CancelSasMessage,
|
||||
@ -616,11 +616,11 @@ class ProxyDaemon:
|
||||
@property
|
||||
def _unknown_token(self):
|
||||
return web.json_response(
|
||||
{
|
||||
"errcode": "M_UNKNOWN_TOKEN",
|
||||
"error": "Unrecognised access token."
|
||||
},
|
||||
status=401,
|
||||
{
|
||||
"errcode": "M_UNKNOWN_TOKEN",
|
||||
"error": "Unrecognised access token."
|
||||
},
|
||||
status=401,
|
||||
)
|
||||
|
||||
@property
|
||||
@ -920,12 +920,20 @@ class ProxyDaemon:
|
||||
},
|
||||
status=400,
|
||||
)
|
||||
except InvalidOrderByError as e:
|
||||
return web.json_response(
|
||||
{
|
||||
"errcode": "M_INVALID_PARAM",
|
||||
"error": str(e)
|
||||
},
|
||||
status=400,
|
||||
)
|
||||
except UnknownRoomError:
|
||||
return await self.forward_to_web(request)
|
||||
|
||||
return web.json_response(result, status=200)
|
||||
|
||||
async def shutdown(self, app):
|
||||
async def shutdown(self, _):
|
||||
"""Shut the daemon down closing all the client sessions it has.
|
||||
|
||||
This method is called when we shut the whole app down.
|
||||
|
Loading…
Reference in New Issue
Block a user