allow_facet, allow_download, suggest_facets boolean --config

Refs #284
This commit is contained in:
Simon Willison 2018-05-24 18:12:27 -07:00
commit 50920cfe3d
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
9 changed files with 177 additions and 55 deletions

View file

@ -4,7 +4,7 @@ from sanic import response
from datasette.utils import to_css_class, validate_sql_select
from .base import BaseView
from .base import BaseView, DatasetteError
class DatabaseView(BaseView):
@ -29,6 +29,7 @@ class DatabaseView(BaseView):
{"name": query_name, "sql": query_sql}
for query_name, query_sql in (metadata.get("queries") or {}).items()
],
"config": self.ds.config,
}, {
"database_hash": hash,
"show_hidden": request.args.get("_show_hidden"),
@ -42,6 +43,8 @@ class DatabaseView(BaseView):
class DatabaseDownload(BaseView):
async def view_get(self, request, name, hash, **kwargs):
if not self.ds.config["allow_download"]:
raise DatasetteError("Database download is forbidden", status=403)
filepath = self.ds.inspect()[name]["file"]
return await response.file_stream(
filepath,