Redirect /-/config to /-/settings, closes #1103

pull/1112/head
Simon Willison 2020-11-24 12:19:14 -08:00
rodzic 3159263f05
commit 2a3d5b720b
7 zmienionych plików z 43 dodań i 14 usunięć

Wyświetl plik

@ -66,6 +66,7 @@ from .utils.asgi import (
Forbidden,
NotFound,
Request,
Response,
asgi_static,
asgi_send,
asgi_send_html,
@ -884,8 +885,16 @@ class Datasette:
r"/-/plugins(?P<as_format>(\.json)?)$",
)
add_route(
JsonDataView.as_view(self, "config.json", lambda: self._config),
r"/-/config(?P<as_format>(\.json)?)$",
JsonDataView.as_view(self, "settings.json", lambda: self._config),
r"/-/settings(?P<as_format>(\.json)?)$",
)
add_route(
permanent_redirect("/-/settings.json"),
r"/-/config.json",
)
add_route(
permanent_redirect("/-/settings"),
r"/-/config",
)
add_route(
JsonDataView.as_view(self, "threads.json", self._threads),
@ -1224,6 +1233,13 @@ def wrap_view(view_fn, datasette):
return async_view_fn
def permanent_redirect(path):
return wrap_view(
lambda request, send: Response.redirect(path, status=301),
datasette=None,
)
_curly_re = re.compile(r"(\{.*?\})")

Wyświetl plik

@ -22,8 +22,8 @@ def menu_links(datasette, actor):
"label": "Metadata",
},
{
"href": datasette.urls.path("/-/config"),
"label": "Config",
"href": datasette.urls.path("/-/settings"),
"label": "Settings",
},
{
"href": datasette.urls.path("/-/permissions"),

Wyświetl plik

@ -89,10 +89,10 @@ Add ``?all=1`` to include details of the default plugins baked into Datasette.
.. _JsonDataView_config:
/-/config
---------
/-/settings
-----------
Shows the :ref:`config` options for this instance of Datasette. `Config example <https://fivethirtyeight.datasettes.com/-/config>`_:
Shows the :ref:`config` options for this instance of Datasette. `Settings example <https://fivethirtyeight.datasettes.com/-/settings>`_:
.. code-block:: json
@ -110,7 +110,7 @@ Shows the :ref:`config` options for this instance of Datasette. `Config example
/-/databases
------------
Shows currently attached databases. `Databases example <https://latest.datasette.io/-/config>`_:
Shows currently attached databases. `Databases example <https://latest.datasette.io/-/databases>`_:
.. code-block:: json

Wyświetl plik

@ -1324,8 +1324,8 @@ def test_versions_json(app_client):
assert "compile_options" in response.json["sqlite"]
def test_config_json(app_client):
response = app_client.get("/-/config.json")
def test_settings_json(app_client):
response = app_client.get("/-/settings.json")
assert {
"default_page_size": 50,
"default_facet_size": 30,
@ -1350,6 +1350,19 @@ def test_config_json(app_client):
} == response.json
@pytest.mark.parametrize(
"path,expected_redirect",
(
("/-/config.json", "/-/settings.json"),
("/-/config", "/-/settings"),
),
)
def test_config_redirects_to_settings(app_client, path, expected_redirect):
response = app_client.get(path, allow_redirects=False)
assert response.status == 301
assert response.headers["Location"] == expected_redirect
def test_page_size_matching_max_returned_rows(
app_client_returned_rows_matches_page_size,
):

Wyświetl plik

@ -177,7 +177,7 @@ def test_version():
def test_setting(ensure_eventloop):
runner = CliRunner()
result = runner.invoke(
cli, ["--setting", "default_page_size", "5", "--get", "/-/config.json"]
cli, ["--setting", "default_page_size", "5", "--get", "/-/settings.json"]
)
assert result.exit_code == 0, result.output
assert json.loads(result.output)["default_page_size"] == 5
@ -194,7 +194,7 @@ def test_config_deprecated(ensure_eventloop):
# The --config option should show a deprecation message
runner = CliRunner(mix_stderr=False)
result = runner.invoke(
cli, ["--config", "allow_download:off", "--get", "/-/config.json"]
cli, ["--config", "allow_download:off", "--get", "/-/settings.json"]
)
assert result.exit_code == 0
assert not json.loads(result.output)["allow_download"]

Wyświetl plik

@ -86,7 +86,7 @@ def test_metadata(config_dir_client):
def test_config(config_dir_client):
response = config_dir_client.get("/-/config.json")
response = config_dir_client.get("/-/settings.json")
assert 200 == response.status
assert 60 == response.json["default_cache_ttl"]

Wyświetl plik

@ -378,7 +378,7 @@ def view_instance_client():
"/-/metadata",
"/-/versions",
"/-/plugins",
"/-/config",
"/-/settings",
"/-/threads",
"/-/databases",
"/-/actor",