diff --git a/kinto_elasticsearch/views.py b/kinto_elasticsearch/views.py index ce31282..365b854 100644 --- a/kinto_elasticsearch/views.py +++ b/kinto_elasticsearch/views.py @@ -26,6 +26,12 @@ def __init__(self, request): @search.post(permission=authorization.DYNAMIC) def get_search(request): bucket_id = request.matchdict['bucket_id'] + if bucket_id == "default": + try: + bucket_id = request.default_bucket_id + except AttributeError as e: # pragma: no cover + pass # `default` bucket without default_bucket plugin. + collection_id = request.matchdict['collection_id'] query = request.body diff --git a/tests/config.ini b/tests/config.ini index 31df9a9..e92658f 100644 --- a/tests/config.ini +++ b/tests/config.ini @@ -3,6 +3,7 @@ use = egg:kinto kinto.userid_hmac_secret = some-secret-string kinto.includes = kinto_elasticsearch + kinto.plugins.default_bucket kinto.plugins.flush # We need indices to be refreshed immediately for assertions. kinto.elasticsearch.force_refresh = true \ No newline at end of file diff --git a/tests/test_elasticsearch.py b/tests/test_elasticsearch.py index 01ed307..72a8203 100644 --- a/tests/test_elasticsearch.py +++ b/tests/test_elasticsearch.py @@ -92,6 +92,12 @@ def test_search_on_empty_collection_returns_empty_list(self): result = resp.json assert len(result["hits"]["hits"]) == 0 + def test_search_on_default_bucket_implicit_collection_returns_empty_list(self): + resp = self.app.post("/buckets/default/collections/yeah/search", + headers=self.headers) + result = resp.json + assert len(result["hits"]["hits"]) == 0 + class PermissionsCheck(BaseWebTest, unittest.TestCase): def test_search_is_allowed_if_write_on_bucket(self):