Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ class PermissionCheck:
"Time limit for calculating a suggested facet",
),
Setting(
"allow_facet",
"default_allow_facet",
True,
"Allow users to specify columns to facet using ?_facet= parameter",
),
Setting(
"allow_download",
"default_allow_download",
True,
"Allow users to download the original SQLite database files",
),
Expand All @@ -274,7 +274,7 @@ class PermissionCheck:
),
Setting("cache_size_kb", 0, "SQLite cache size in KB (0 == use SQLite default)"),
Setting(
"allow_stream",
"default_allow_stream",
True,
"Allow ?_stream=1 to export all rows (ignoring max_returned_rows)",
),
Expand Down Expand Up @@ -310,7 +310,9 @@ class PermissionCheck:
# names. The old names are not documented but still work everywhere a
# setting can be set or read.
SETTING_ALIASES = {
"allow_csv_stream": "allow_stream",
"allow_facet": "default_allow_facet",
"allow_download": "default_allow_download",
"allow_csv_stream": "default_allow_stream",
"max_csv_mb": "max_stream_mb",
}

Expand Down
2 changes: 1 addition & 1 deletion datasette/templates/_export_dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{% set export_later = export_rows.later if export_rows else false %}
{#- "Include all rows" streams every row from the first one, so offer it on
every later page, and on the first page when CSV would stop short -#}
{% set csv_stream = export_rows and display_rows and (export_later or (next_url and not (export_rows.total is not none and export_rows.total <= export_rows.max))) and settings.allow_stream %}
{% set csv_stream = export_rows and display_rows and (export_later or (next_url and not (export_rows.total is not none and export_rows.total <= export_rows.max))) and settings.default_allow_stream %}
{% macro rows_text(n) %}{{ "{:,}".format(n) }} row{{ "" if n == 1 else "s" }}{% endmacro %}
{#- How many rows an export returns. JSON and plugin formats return the rows
on this page; TSV and CSV ask for _size=max, starting from this page.
Expand Down
2 changes: 1 addition & 1 deletion datasette/templates/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% endif %}
<script src="{{ static('table-layout.js') }}" defer></script>
<script src="{{ static('mobile-column-actions.js') }}" defer></script>
<script>DATASETTE_ALLOW_FACET = {{ datasette_allow_facet }};</script>
<script>DATASETTE_ALLOW_FACET = {{ settings.default_allow_facet|tojson }};</script>
<style>
@media only screen and (max-width: 576px) {
{% for column in display_columns -%}
Expand Down
2 changes: 1 addition & 1 deletion datasette/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def stream_requested(datasette, request, format_):
return False
if not datasette._renderer_can_stream.get(format_):
return False
if not datasette.setting("allow_stream"):
if not datasette.setting("default_allow_stream"):
raise BadRequest("Streaming is disabled")
if request.args.get("_next"):
raise BadRequest("_next not allowed when streaming")
Expand Down
4 changes: 2 additions & 2 deletions datasette/views/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ async def database_actions():
database_actions=database_actions,
show_hidden=request.args.get("_show_hidden"),
editable=True,
allow_download=datasette.setting("allow_download")
allow_download=datasette.setting("default_allow_download")
and not db.is_mutable
and not db.is_memory,
attached_databases=attached_databases,
Expand Down Expand Up @@ -596,7 +596,7 @@ async def database_download(request, datasette):

if db.is_memory:
raise DatasetteError("Cannot download in-memory databases", status=404)
if not datasette.setting("allow_download") or db.is_mutable:
if not datasette.setting("default_allow_download") or db.is_mutable:
raise Forbidden("Database download is forbidden")
if not db.path:
raise DatasetteError("Cannot download database", status=404)
Expand Down
10 changes: 1 addition & 9 deletions datasette/views/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,6 @@ class TableContext(Context):
alternate_url_json: str = field(
metadata={"help": "URL for the JSON version of this page"}
)
datasette_allow_facet: str = field(
metadata={
"help": 'The string "true" or "false" reflecting the allow_facet setting'
}
)
is_sortable: bool = field(
metadata={"help": "True if any of the displayed columns can be used to sort"}
)
Expand Down Expand Up @@ -2108,9 +2103,6 @@ async def fetch_next_page():
fix_path=datasette.urls.path,
settings=datasette.settings_dict(),
alternate_url_json=alternate_url_json,
datasette_allow_facet=(
"true" if datasette.setting("allow_facet") else "false"
),
is_sortable=any(c["sortable"] for c in data["display_columns"]),
allow_execute_sql=await datasette.allowed(
action="execute-sql",
Expand Down Expand Up @@ -2619,7 +2611,7 @@ async def table_view_data(
extras.update(extra_extras)

# Faceting
if not datasette.setting("allow_facet") and any(
if not datasette.setting("default_allow_facet") and any(
arg.startswith("_facet") for arg in request.args
):
raise BadRequest("_facet= is not allowed")
Expand Down
2 changes: 1 addition & 1 deletion datasette/views/table_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ async def resolve(self, context, facet_instances):
suggested_facets = []
if (
context.datasette.setting("suggest_facets")
and context.datasette.setting("allow_facet")
and context.datasette.setting("default_allow_facet")
and not context.next_arg
and not context.nofacet
and not context.nosuggest
Expand Down
4 changes: 2 additions & 2 deletions docs/authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ Datasette defaults to allowing any site visitor to execute their own custom SQL

Access to this ability is controlled by the :ref:`actions_execute_sql` permission.

This permission does not apply to structured table-browsing operations where Datasette constructs the SQL, such as sorting, column filters and :ref:`facets`. Faceting is controlled separately by the :ref:`setting_allow_facet` setting.
This permission does not apply to structured table-browsing operations where Datasette constructs the SQL, such as sorting, column filters and :ref:`facets`. Faceting is controlled separately by the :ref:`setting_default_allow_facet` setting.

The easiest way to disable arbitrary SQL queries is using the :ref:`default_allow_sql setting <setting_default_allow_sql>` when you first start Datasette running.

Expand Down Expand Up @@ -1550,7 +1550,7 @@ execute-sql

Actor is allowed to run arbitrary read-only SQL queries against a specific database using the :ref:`custom SQL query page <pages_custom_sql_queries>`, e.g. https://latest.datasette.io/fixtures/-/query?sql=select+100

This action also controls raw SQL supplied using ``?_where=``. It does not control structured table-browsing features such as :ref:`facets`, which use SQL generated by Datasette and are controlled by :ref:`setting_allow_facet`.
This action also controls raw SQL supplied using ``?_where=``. It does not control structured table-browsing features such as :ref:`facets`, which use SQL generated by Datasette and are controlled by :ref:`setting_default_allow_facet`.

``resource`` - ``datasette.resources.DatabaseResource(database)``
``database`` is the name of the database (string)
Expand Down
4 changes: 3 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Unreleased
- Output renderers can now stream every row of a table or view. A ``render`` function that accepts the new ``row_stream`` argument - an async iterator of rows - and returns ``Response.stream()`` will be sent every row when the URL includes ``?_stream=1``. See :ref:`plugin_register_output_renderer_streaming`. (:issue:`1101`)
- CSV and TSV export are now implemented as default output renderers using that mechanism, replacing the previous special case. Plugins can replace either of them by registering a renderer for the ``csv`` or ``tsv`` extension. (:issue:`1062`)
- **Breaking change**: an "include all rows" export that fails part of the way through, or that reaches the :ref:`setting_max_stream_mb` limit, now drops the connection so the download fails. Previously the error message was written as the last line of the file, which otherwise looked complete.
- The ``allow_csv_stream`` and ``max_csv_mb`` settings have been renamed to :ref:`setting_allow_stream` and :ref:`setting_max_stream_mb`, since they now apply to every format that can stream. The previous names continue to work.
- The ``allow_csv_stream`` and ``max_csv_mb`` settings have been renamed to :ref:`setting_default_allow_stream` and :ref:`setting_max_stream_mb`, since they now apply to every format that can stream. The previous names continue to work.
- The ``allow_facet`` and ``allow_download`` settings have been renamed to :ref:`setting_default_allow_facet` and :ref:`setting_default_allow_download`, matching :ref:`setting_default_allow_sql`. The previous names continue to work. (:issue:`1410`)
- **Breaking change**: the ``datasette_allow_facet`` template variable has been removed from the table page. Custom ``table.html`` templates that use it should use ``{{ settings.default_allow_facet|tojson }}`` instead.
- **Breaking change**: the ``view_name`` passed to plugin hooks for SQL query pages, both arbitrary SQL and stored queries, is now ``"query"``. Template hooks such as :ref:`plugin_hook_extra_template_vars` were previously passed ``"database"`` for those pages. Output renderers were passed ``"table"`` by ``render`` and ``"database"`` by ``can_render``. See :ref:`the upgrade guide <upgrade_guide_v1_view_name_query>`.
- **Breaking change**: output renderer ``render`` functions must now return a :ref:`Response <internals_response>` object, or ``None``. Returning a dictionary with ``body``, ``content_type``, ``status_code`` and ``headers`` keys, deprecated since Datasette 0.49, is now an error. The ``"callback"`` key, the pre-0.49 name for ``"render"``, has also been removed. See :ref:`the upgrade guide <upgrade_guide_v1_renderer_response>`. (:issue:`954`)
- Output renderers whose ``render`` function accepts the undocumented ``data`` or ``args`` arguments now trigger a ``DeprecationWarning`` when Datasette starts. Those arguments will be removed before Datasette 1.0. Use the ``page`` argument in place of ``data``, and ``request.args`` in place of ``args``. (:issue:`2770`)
Expand Down
6 changes: 3 additions & 3 deletions docs/cli-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ These can be passed to ``datasette serve`` using ``datasette serve --setting nam
(default=200)
facet_suggest_time_limit_ms Time limit for calculating a suggested facet
(default=50)
allow_facet Allow users to specify columns to facet using
default_allow_facet Allow users to specify columns to facet using
?_facet= parameter (default=True)
allow_download Allow users to download the original SQLite
default_allow_download Allow users to download the original SQLite
database files (default=True)
allow_signed_tokens Allow users to create and use signed API tokens
(default=True)
Expand All @@ -275,7 +275,7 @@ These can be passed to ``datasette serve`` using ``datasette serve --setting nam
max-age= header) (default=5)
cache_size_kb SQLite cache size in KB (0 == use SQLite default)
(default=0)
allow_stream Allow ?_stream=1 to export all rows (ignoring
default_allow_stream Allow ?_stream=1 to export all rows (ignoring
max_returned_rows) (default=True)
max_stream_mb Maximum size allowed for a streamed export in MB
- set 0 to disable this limit (default=100)
Expand Down
2 changes: 1 addition & 1 deletion docs/csv_export.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ missing rows. The same thing happens if an error occurs part of the way through.

You can increase or remove this limit using the :ref:`setting_max_stream_mb` config
setting. You can also disable the *include all rows* option entirely using
:ref:`setting_allow_stream`.
:ref:`setting_default_allow_stream`.

CSV and TSV are implemented as :ref:`output renderers <plugin_register_output_renderer>`
that stream their rows. Plugins can add other formats that work the same way, see
Expand Down
2 changes: 1 addition & 1 deletion docs/facets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Here's `an example <https://latest.datasette.io/fixtures/facetable?_facet=state&

Facets can be specified in two ways: using query string parameters, or in ``metadata.json`` configuration for the table.

Facet queries are generated by Datasette and summarize rows the actor already has permission to view. They do not require the :ref:`actions_execute_sql` permission. Use the :ref:`setting_allow_facet` setting to control whether users can request facets using query string parameters.
Facet queries are generated by Datasette and summarize rows the actor already has permission to view. They do not require the :ref:`actions_execute_sql` permission. Use the :ref:`setting_default_allow_facet` setting to control whether users can request facets using query string parameters.

Facets in query strings
-----------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/internals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ For example:

.. code-block:: python

downloads_are_allowed = datasette.setting("allow_download")
downloads_are_allowed = datasette.setting("default_allow_download")

.. _datasette_resolve_database:

Expand Down
2 changes: 1 addition & 1 deletion docs/plugin_hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ Datasette's own :ref:`CSV and TSV export <csv_export>` is implemented this way.
- ``?_stream=1`` is ignored by formats that do not accept ``row_stream``.
- Only tables and views have more than one page. For a row, or the results of a SQL query, ``row_stream`` yields the same rows as ``rows``.
- ``rows``, ``page`` and the other arguments describe the first page. Everything that could result in an error page - an invalid filter, a permission check - has already happened by the time your function is called.
- :ref:`setting_allow_stream` and :ref:`setting_max_stream_mb` apply to every format, not only CSV. A streamed response that grows larger than ``max_stream_mb`` is cut off by dropping the connection, as described in :ref:`internals_response_stream`.
- :ref:`setting_default_allow_stream` and :ref:`setting_max_stream_mb` apply to every format, not only CSV. A streamed response that grows larger than ``max_stream_mb`` is cut off by dropping the connection, as described in :ref:`internals_response_stream`.

Any format can be downloaded as a file by adding ``?_dl=1`` to the URL, which adds a ``content-disposition: attachment`` header with a filename ending in the format's extension. A response that sets its own ``content-disposition`` header is left alone.

Expand Down
34 changes: 17 additions & 17 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Should users be able to execute arbitrary SQL queries by default?

Setting this to ``off`` causes permission checks for :ref:`actions_execute_sql` to fail by default.

This setting controls the ability to submit arbitrary SQL. It does not disable structured table-browsing features that use SQL generated by Datasette, such as sorting, column filters and :ref:`facets`. Use :ref:`setting_allow_facet` to control whether users can request facets.
This setting controls the ability to submit arbitrary SQL. It does not disable structured table-browsing features that use SQL generated by Datasette, such as sorting, column filters and :ref:`facets`. Use :ref:`setting_default_allow_facet` to control whether users can request facets.

::

Expand Down Expand Up @@ -214,13 +214,13 @@ Maximum number of threads in the thread pool Datasette uses to execute SQLite qu

Setting this to 0 turns off threaded SQL queries entirely - useful for environments that do not support threading such as `Pyodide <https://pyodide.org/>`__.

.. _setting_allow_facet:
.. _setting_default_allow_facet:

allow_facet
~~~~~~~~~~~
default_allow_facet
~~~~~~~~~~~~~~~~~~~

.. [[[cog
setting_default(cog, "allow_facet")
setting_default(cog, "default_allow_facet")
.. ]]]

Default: ``on``
Expand All @@ -233,7 +233,7 @@ If disabled, facets will still be displayed if they have been specifically enabl

Here's how to disable this feature::

datasette mydatabase.db --setting allow_facet off
datasette mydatabase.db --setting default_allow_facet off

.. _setting_default_facet_size:

Expand Down Expand Up @@ -307,22 +307,22 @@ Should Datasette calculate suggested facets? Turn this off like so::

datasette mydatabase.db --setting suggest_facets off

.. _setting_allow_download:
.. _setting_default_allow_download:

allow_download
~~~~~~~~~~~~~~
default_allow_download
~~~~~~~~~~~~~~~~~~~~~~

.. [[[cog
setting_default(cog, "allow_download")
setting_default(cog, "default_allow_download")
.. ]]]

Default: ``on``

.. [[[end]]]

Should users be able to download the original SQLite database using a link on the database index page? Databases can only be downloaded if they are served in immutable mode and not in-memory. If downloading is unavailable for either of these reasons, the download link is hidden even if ``allow_download`` is on. To disable database downloads, use the following::
Should users be able to download the original SQLite database using a link on the database index page? Databases can only be downloaded if they are served in immutable mode and not in-memory. If downloading is unavailable for either of these reasons, the download link is hidden even if ``default_allow_download`` is on. To disable database downloads, use the following::

datasette mydatabase.db --setting allow_download off
datasette mydatabase.db --setting default_allow_download off

.. _setting_allow_signed_tokens:

Expand Down Expand Up @@ -408,13 +408,13 @@ Sets the amount of memory SQLite uses for its `per-connection cache <https://www

datasette mydatabase.db --setting cache_size_kb 5000

.. _setting_allow_stream:
.. _setting_default_allow_stream:

allow_stream
~~~~~~~~~~~~
default_allow_stream
~~~~~~~~~~~~~~~~~~~~

.. [[[cog
setting_default(cog, "allow_stream")
setting_default(cog, "default_allow_stream")
.. ]]]

Default: ``on``
Expand All @@ -429,7 +429,7 @@ You can turn it off like this:

::

datasette mydatabase.db --setting allow_stream off
datasette mydatabase.db --setting default_allow_stream off

.. _setting_max_stream_mb:

Expand Down
3 changes: 0 additions & 3 deletions docs/template_context.rst
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,6 @@ Many of these keys are shared with the :ref:`JSON API <json_api>` for this page.
``database_color`` - ``str``
Color assigned to the database

``datasette_allow_facet`` - ``str``
The string "true" or "false" reflecting the allow_facet setting

``display_columns`` - ``list``
Column metadata used by the HTML table display. Each item includes ``name``, ``sortable``, ``is_pk``, ``type``, ``notnull``, ``description``, ``column_type``, ``column_type_config`` and ``has_fks`` keys. ``has_fks`` is true when at least one cell in the column is displayed as a link to a foreign key row.

Expand Down
6 changes: 3 additions & 3 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,15 +757,15 @@ async def test_settings_json(ds_client):
"max_insert_rows": 100,
"max_post_body_bytes": 10 * 1024 * 1024,
"sql_time_limit_ms": 200,
"allow_download": True,
"default_allow_download": True,
"allow_signed_tokens": True,
"max_signed_tokens_ttl": 0,
"allow_facet": True,
"default_allow_facet": True,
"suggest_facets": True,
"default_cache_ttl": 5,
"num_sql_threads": 1,
"cache_size_kb": 0,
"allow_stream": True,
"default_allow_stream": True,
"max_stream_mb": 100,
"truncate_cells_html": 2048,
"force_https_urls": False,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ def test_database_download_disallowed_for_memory():

def test_allow_download_off():
with make_app_client(
is_immutable=True, settings={"allow_download": False}
is_immutable=True, settings={"default_allow_download": False}
) as client:
response = client.get("/fixtures")
soup = Soup(response.content, "html.parser")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_internals_datasette.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_sign_unsign(datasette, value, namespace):
(
("base_url", "/"),
("max_stream_mb", 100),
("allow_stream", True),
("default_allow_stream", True),
# Previous names for those two settings still work
("max_csv_mb", 100),
("allow_csv_stream", True),
Expand Down
Loading
Loading